From 18715f8a2de4074d0152cf4acf511b3dbca41b22 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com>
Date: Sun, 18 Feb 2018 17:50:11 +0100
Subject: [PATCH] Reduce Author API fields and extend User and Viewer API
 fields.

---
 openlobby/core/api/types.py                   |  6 +++--
 tests/dummy.py                                |  3 ---
 tests/schema/snapshots/snap_test_authors.py   | 25 +++++++++++--------
 tests/schema/snapshots/snap_test_node.py      |  5 ++--
 .../snapshots/snap_test_search_reports.py     |  8 +++---
 tests/schema/snapshots/snap_test_viewer.py    |  2 ++
 tests/schema/test_authors.py                  | 17 +++++++++----
 tests/schema/test_node.py                     | 15 +++++++----
 tests/schema/test_viewer.py                   |  5 +++-
 9 files changed, 54 insertions(+), 32 deletions(-)

diff --git a/openlobby/core/api/types.py b/openlobby/core/api/types.py
index f17f8d3..78640df 100644
--- a/openlobby/core/api/types.py
+++ b/openlobby/core/api/types.py
@@ -87,6 +87,8 @@ class User(graphene.ObjectType):
     first_name = graphene.String()
     last_name = graphene.String()
     email = graphene.String()
+    is_author = graphene.Boolean()
+    extra = JSONString()
 
     class Meta:
         interfaces = (relay.Node, )
@@ -99,6 +101,8 @@ class User(graphene.ObjectType):
             first_name=user.first_name,
             last_name=user.last_name,
             email=user.email,
+            is_author=user.is_author,
+            extra=user.extra,
         )
 
     @classmethod
@@ -113,7 +117,6 @@ class User(graphene.ObjectType):
 class Author(graphene.ObjectType):
     first_name = graphene.String()
     last_name = graphene.String()
-    openid_uid = graphene.String()
     extra = JSONString()
     reports = relay.ConnectionField(ReportConnection)
 
@@ -126,7 +129,6 @@ class Author(graphene.ObjectType):
             id=user.id,
             first_name=user.first_name,
             last_name=user.last_name,
-            openid_uid=user.openid_uid,
             extra=user.extra,
         )
 
diff --git a/tests/dummy.py b/tests/dummy.py
index f37ab08..dbdb7dc 100644
--- a/tests/dummy.py
+++ b/tests/dummy.py
@@ -7,7 +7,6 @@ authors = [
     {
         'id': 1,
         'username': 'Wolf',
-        'openid_uid': 'Wolf',
         'first_name': 'Winston',
         'last_name': 'Wolfe',
         'is_author': True,
@@ -16,7 +15,6 @@ authors = [
     {
         'id': 2,
         'username': 'sponge',
-        'openid_uid': 'sponge',
         'first_name': 'Spongebob',
         'last_name': 'Squarepants',
         'is_author': True,
@@ -24,7 +22,6 @@ authors = [
     {
         'id': 3,
         'username': 'shaun',
-        'openid_uid': 'shaun',
         'first_name': 'Shaun',
         'last_name': 'Sheep',
         'is_author': True,
diff --git a/tests/schema/snapshots/snap_test_authors.py b/tests/schema/snapshots/snap_test_authors.py
index 6a8de11..88acda2 100644
--- a/tests/schema/snapshots/snap_test_authors.py
+++ b/tests/schema/snapshots/snap_test_authors.py
@@ -17,8 +17,7 @@ snapshots['test_all 1'] = {
                         'extra': '{"movies": 1}',
                         'firstName': 'Winston',
                         'id': 'QXV0aG9yOjE=',
-                        'lastName': 'Wolfe',
-                        'openidUid': 'Wolf'
+                        'lastName': 'Wolfe'
                     }
                 },
                 {
@@ -27,8 +26,7 @@ snapshots['test_all 1'] = {
                         'extra': None,
                         'firstName': 'Spongebob',
                         'id': 'QXV0aG9yOjI=',
-                        'lastName': 'Squarepants',
-                        'openidUid': 'sponge'
+                        'lastName': 'Squarepants'
                     }
                 },
                 {
@@ -37,8 +35,7 @@ snapshots['test_all 1'] = {
                         'extra': None,
                         'firstName': 'Shaun',
                         'id': 'QXV0aG9yOjM=',
-                        'lastName': 'Sheep',
-                        'openidUid': 'shaun'
+                        'lastName': 'Sheep'
                     }
                 }
             ],
@@ -60,13 +57,17 @@ snapshots['test_first 1'] = {
                 {
                     'cursor': 'MQ==',
                     'node': {
-                        'openidUid': 'Wolf'
+                        'firstName': 'Winston',
+                        'id': 'QXV0aG9yOjE=',
+                        'lastName': 'Wolfe'
                     }
                 },
                 {
                     'cursor': 'Mg==',
                     'node': {
-                        'openidUid': 'sponge'
+                        'firstName': 'Spongebob',
+                        'id': 'QXV0aG9yOjI=',
+                        'lastName': 'Squarepants'
                     }
                 }
             ],
@@ -88,7 +89,9 @@ snapshots['test_first_after 1'] = {
                 {
                     'cursor': 'Mg==',
                     'node': {
-                        'openidUid': 'sponge'
+                        'firstName': 'Spongebob',
+                        'id': 'QXV0aG9yOjI=',
+                        'lastName': 'Squarepants'
                     }
                 }
             ],
@@ -127,7 +130,9 @@ snapshots['test_last_before 1'] = {
                 {
                     'cursor': 'Mg==',
                     'node': {
-                        'openidUid': 'sponge'
+                        'firstName': 'Spongebob',
+                        'id': 'QXV0aG9yOjI=',
+                        'lastName': 'Squarepants'
                     }
                 }
             ],
diff --git a/tests/schema/snapshots/snap_test_node.py b/tests/schema/snapshots/snap_test_node.py
index 706962a..d2b7936 100644
--- a/tests/schema/snapshots/snap_test_node.py
+++ b/tests/schema/snapshots/snap_test_node.py
@@ -22,8 +22,7 @@ snapshots['test_author 1'] = {
             'extra': '{"x": 1}',
             'firstName': 'Winston',
             'id': 'QXV0aG9yOjU=',
-            'lastName': 'Wolfe',
-            'openidUid': 'TheWolf'
+            'lastName': 'Wolfe'
         }
     }
 }
@@ -72,8 +71,10 @@ snapshots['test_user__not_a_viewer 1'] = {
 snapshots['test_user 1'] = {
     'data': {
         'node': {
+            'extra': '{"e": "mc2"}',
             'firstName': 'Albert',
             'id': 'VXNlcjo4',
+            'isAuthor': False,
             'lastName': 'Einstein',
             'openidUid': 'albert@einstein.id'
         }
diff --git a/tests/schema/snapshots/snap_test_search_reports.py b/tests/schema/snapshots/snap_test_search_reports.py
index e8b353b..70f33ad 100644
--- a/tests/schema/snapshots/snap_test_search_reports.py
+++ b/tests/schema/snapshots/snap_test_search_reports.py
@@ -36,7 +36,7 @@ snapshots['test_all 1'] = {
                     'cursor': 'Mg==',
                     'node': {
                         'author': {
-                            'extra': None,
+                            'extra': '{"movies": 1}',
                             'firstName': 'Winston',
                             'id': 'QXV0aG9yOjE=',
                             'lastName': 'Wolfe'
@@ -57,7 +57,7 @@ snapshots['test_all 1'] = {
                     'cursor': 'Mw==',
                     'node': {
                         'author': {
-                            'extra': None,
+                            'extra': '{"movies": 1}',
                             'firstName': 'Winston',
                             'id': 'QXV0aG9yOjE=',
                             'lastName': 'Wolfe'
@@ -125,7 +125,7 @@ snapshots['test_highlight 1'] = {
                     'cursor': 'MQ==',
                     'node': {
                         'author': {
-                            'extra': None,
+                            'extra': '{"movies": 1}',
                             'firstName': 'Winston',
                             'id': 'QXV0aG9yOjE=',
                             'lastName': 'Wolfe'
@@ -146,7 +146,7 @@ snapshots['test_highlight 1'] = {
                     'cursor': 'Mg==',
                     'node': {
                         'author': {
-                            'extra': None,
+                            'extra': '{"movies": 1}',
                             'firstName': 'Winston',
                             'id': 'QXV0aG9yOjE=',
                             'lastName': 'Wolfe'
diff --git a/tests/schema/snapshots/snap_test_viewer.py b/tests/schema/snapshots/snap_test_viewer.py
index 5ba5fc7..947e074 100644
--- a/tests/schema/snapshots/snap_test_viewer.py
+++ b/tests/schema/snapshots/snap_test_viewer.py
@@ -17,8 +17,10 @@ snapshots['test_authenticated 1'] = {
     'data': {
         'viewer': {
             'email': 'winston@wolfe.com',
+            'extra': '{"caliber": 45}',
             'firstName': 'Winston',
             'id': 'VXNlcjox',
+            'isAuthor': True,
             'lastName': 'Wolfe',
             'openidUid': 'TheWolf'
         }
diff --git a/tests/schema/test_authors.py b/tests/schema/test_authors.py
index 614f82d..e81d03e 100644
--- a/tests/schema/test_authors.py
+++ b/tests/schema/test_authors.py
@@ -21,7 +21,6 @@ def test_all(client, snapshot):
                     id
                     firstName
                     lastName
-                    openidUid
                     extra
                 }
             }
@@ -46,7 +45,9 @@ def test_first(client, snapshot):
             edges {
                 cursor
                 node {
-                    openidUid
+                    id
+                    firstName
+                    lastName
                 }
             }
             pageInfo {
@@ -70,7 +71,9 @@ def test_first_after(client, snapshot):
             edges {
                 cursor
                 node {
-                    openidUid
+                    id
+                    firstName
+                    lastName
                 }
             }
             pageInfo {
@@ -94,7 +97,9 @@ def test_last(client, snapshot):
             edges {
                 cursor
                 node {
-                    openidUid
+                    id
+                    firstName
+                    lastName
                 }
             }
             pageInfo {
@@ -118,7 +123,9 @@ def test_last_before(client, snapshot):
             edges {
                 cursor
                 node {
-                    openidUid
+                    id
+                    firstName
+                    lastName
                 }
             }
             pageInfo {
diff --git a/tests/schema/test_node.py b/tests/schema/test_node.py
index d2bfe8c..9b2adb7 100644
--- a/tests/schema/test_node.py
+++ b/tests/schema/test_node.py
@@ -41,7 +41,6 @@ def test_author(client, snapshot):
                 id
                 firstName
                 lastName
-                openidUid
                 extra
             }}
         }}
@@ -95,7 +94,7 @@ def test_report(client, snapshot):
 
 def test_user__unauthorized(client, snapshot):
     User.objects.create(id=8, username='albert', openid_uid='albert@einstein.id',
-        first_name='Albert', last_name='Einstein')
+        first_name='Albert', last_name='Einstein', extra={'e': 'mc2'})
     res = client.post('/graphql', {'query': """
     query {{
         node (id:"{id}") {{
@@ -104,6 +103,8 @@ def test_user__unauthorized(client, snapshot):
                 firstName
                 lastName
                 openidUid
+                isAuthor
+                extra
             }}
         }}
     }}
@@ -113,9 +114,9 @@ def test_user__unauthorized(client, snapshot):
 
 def test_user__not_a_viewer(client, snapshot):
     User.objects.create(id=8, username='albert', openid_uid='albert@einstein.id',
-        first_name='Albert', last_name='Einstein')
+        first_name='Albert', last_name='Einstein', extra={'e': 'mc2'})
     User.objects.create(id=2, username='isaac', openid_uid='isaac@newton.id',
-        first_name='Isaac', last_name='Newton')
+        first_name='Isaac', last_name='Newton', extra={'apple': 'hit'})
     auth_header = 'Bearer {}'.format(create_access_token('isaac'))
     res = client.post('/graphql', {'query': """
     query {{
@@ -125,6 +126,8 @@ def test_user__not_a_viewer(client, snapshot):
                 firstName
                 lastName
                 openidUid
+                isAuthor
+                extra
             }}
         }}
     }}
@@ -134,7 +137,7 @@ def test_user__not_a_viewer(client, snapshot):
 
 def test_user(client, snapshot):
     User.objects.create(id=8, username='albert', openid_uid='albert@einstein.id',
-        first_name='Albert', last_name='Einstein')
+            first_name='Albert', last_name='Einstein', extra={'e': 'mc2'})
     auth_header = 'Bearer {}'.format(create_access_token('albert'))
     res = client.post('/graphql', {'query': """
     query {{
@@ -144,6 +147,8 @@ def test_user(client, snapshot):
                 firstName
                 lastName
                 openidUid
+                isAuthor
+                extra
             }}
         }}
     }}
diff --git a/tests/schema/test_viewer.py b/tests/schema/test_viewer.py
index a501580..4ab66d2 100644
--- a/tests/schema/test_viewer.py
+++ b/tests/schema/test_viewer.py
@@ -10,7 +10,8 @@ pytestmark = pytest.mark.django_db
 @pytest.fixture(autouse=True)
 def setup():
     User.objects.create(id=1, is_author=True, username='wolfe', openid_uid='TheWolf',
-        first_name='Winston', last_name='Wolfe', email='winston@wolfe.com')
+        first_name='Winston', last_name='Wolfe', email='winston@wolfe.com',
+        extra={'caliber': 45})
 
 
 def test_unauthenticated(client, snapshot):
@@ -35,6 +36,8 @@ def test_authenticated(client, snapshot):
             lastName
             email
             openidUid
+            isAuthor
+            extra
         }
     }
     """}, HTTP_AUTHORIZATION=auth_header)
-- 
GitLab