diff --git a/openlobby/core/api/schema.py b/openlobby/core/api/schema.py index 035594fadc2693624eac5af060ae39d38be6e1b7..eb66ac698677a86c2ada91d2acb9115190004f03 100644 --- a/openlobby/core/api/schema.py +++ b/openlobby/core/api/schema.py @@ -33,10 +33,13 @@ class Query: ' Default: false') node = relay.Node.Field() - authors = relay.ConnectionField(AuthorsConnection) + authors = relay.ConnectionField( + AuthorsConnection, + description='List of Authors. Returns first 10 nodes if pagination is not specified.', + ) search_reports = relay.ConnectionField( SearchReportsConnection, - description='Fulltext search in Reports.', + description='Fulltext search in Reports. Returns first 10 nodes if pagination is not specified.', query=graphene.String(description='Text to search for.'), highlight=graphene.Boolean(default_value=False, description=highlight_help), ) diff --git a/openlobby/core/tests/snapshots/snap_test_schema.py b/openlobby/core/tests/snapshots/snap_test_schema.py index 81dfb093baf81cb553170feb3f6237291509ea16..151ec07721c7832172c2a9e1dac3fd99c18ee273 100644 --- a/openlobby/core/tests/snapshots/snap_test_schema.py +++ b/openlobby/core/tests/snapshots/snap_test_schema.py @@ -63,7 +63,7 @@ snapshots['TestAuthors.test_all 1'] = { 'firstName': 'Winston', 'id': 'QXV0aG9yOjE=', 'lastName': 'Wolfe', - 'openidUid': 'TheWolf' + 'openidUid': 'first' } }, { @@ -73,7 +73,7 @@ snapshots['TestAuthors.test_all 1'] = { 'firstName': 'Captain', 'id': 'QXV0aG9yOjM=', 'lastName': 'Obvious', - 'openidUid': 'ccc' + 'openidUid': 'second' } }, { @@ -83,11 +83,106 @@ snapshots['TestAuthors.test_all 1'] = { 'firstName': 'Shaun', 'id': 'QXV0aG9yOjQ=', 'lastName': 'Sheep', - 'openidUid': 'ddd' + 'openidUid': 'third' } } ], + 'pageInfo': { + 'endCursor': 'Mw==', + 'hasNextPage': False, + 'hasPreviousPage': False, + 'startCursor': 'MQ==' + }, 'totalCount': 3 } } } + +snapshots['TestAuthors.test_first 1'] = { + 'data': { + 'authors': { + 'edges': [ + { + 'cursor': 'MQ==', + 'node': { + 'openidUid': 'first' + } + }, + { + 'cursor': 'Mg==', + 'node': { + 'openidUid': 'second' + } + } + ], + 'pageInfo': { + 'endCursor': 'Mg==', + 'hasNextPage': True, + 'hasPreviousPage': False, + 'startCursor': 'MQ==' + }, + 'totalCount': 3 + } + } +} + +snapshots['TestAuthors.test_first_after 1'] = { + 'data': { + 'authors': { + 'edges': [ + { + 'cursor': 'Mg==', + 'node': { + 'openidUid': 'second' + } + } + ], + 'pageInfo': { + 'endCursor': 'Mg==', + 'hasNextPage': True, + 'hasPreviousPage': True, + 'startCursor': 'Mg==' + }, + 'totalCount': 3 + } + } +} + +snapshots['TestAuthors.test_last_before 1'] = { + 'data': { + 'authors': { + 'edges': [ + { + 'cursor': 'Mg==', + 'node': { + 'openidUid': 'second' + } + } + ], + 'pageInfo': { + 'endCursor': 'Mg==', + 'hasNextPage': True, + 'hasPreviousPage': True, + 'startCursor': 'Mg==' + }, + 'totalCount': 3 + } + } +} + +snapshots['TestAuthors.test_last 1'] = { + 'data': { + 'authors': None + }, + 'errors': [ + { + 'locations': [ + { + 'column': 13, + 'line': 3 + } + ], + 'message': 'Pagination "last" works only in combination with "before" argument.' + } + ] +} diff --git a/openlobby/core/tests/test_schema.py b/openlobby/core/tests/test_schema.py index a3060b7c0a47a1e0a8a7f1284b80abe5b7b3e8a4..8b0be3e6b00a52ad48c62601535906ab970ad6bb 100644 --- a/openlobby/core/tests/test_schema.py +++ b/openlobby/core/tests/test_schema.py @@ -95,12 +95,12 @@ class TestAuthors: @pytest.fixture(autouse=True) def setup(self): - User.objects.create(id=1, is_author=True, username='a', openid_uid='TheWolf', + User.objects.create(id=1, is_author=True, username='a', openid_uid='first', first_name='Winston', last_name='Wolfe', extra={'x': 1}) User.objects.create(id=2, is_author=False, username='b') - User.objects.create(id=3, is_author=True, username='c', openid_uid='ccc', + User.objects.create(id=3, is_author=True, username='c', openid_uid='second', first_name='Captain', last_name='Obvious') - User.objects.create(id=4, is_author=True, username='d', openid_uid='ddd', + User.objects.create(id=4, is_author=True, username='d', openid_uid='third', first_name='Shaun', last_name='Sheep') yield @@ -119,6 +119,100 @@ class TestAuthors: extra } } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + """}) + snapshot.assert_match(res.json()) + + def test_first(self, client, snapshot): + res = client.post('/graphql', {'query': """ + query { + authors (first: 2) { + totalCount + edges { + cursor + node { + openidUid + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + """}) + snapshot.assert_match(res.json()) + + def test_first_after(self, client, snapshot): + res = client.post('/graphql', {'query': """ + query { + authors (first: 1, after: "MQ==") { + totalCount + edges { + cursor + node { + openidUid + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + """}) + snapshot.assert_match(res.json()) + + def test_last(self, client, snapshot): + res = client.post('/graphql', {'query': """ + query { + authors (last: 2) { + totalCount + edges { + cursor + node { + openidUid + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + """}) + snapshot.assert_match(res.json()) + + def test_last_before(self, client, snapshot): + res = client.post('/graphql', {'query': """ + query { + authors (last: 1, before: "Mw==") { + totalCount + edges { + cursor + node { + openidUid + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } } } """})