From a2454426e58622a391cda5bf85287a4b4f789813 Mon Sep 17 00:00:00 2001 From: Chris Kalmar Date: Thu, 28 Jan 2021 00:50:26 +0100 Subject: [PATCH] extend cursor tests with graphql tests --- test/__snapshots__/cursor.spec.ts.snap | 1121 +++++++++++++++++++++++- test/cursor.spec.ts | 793 +++++++++++++---- 2 files changed, 1714 insertions(+), 200 deletions(-) diff --git a/test/__snapshots__/cursor.spec.ts.snap b/test/__snapshots__/cursor.spec.ts.snap index ddb0099f..e2cb8dc9 100644 --- a/test/__snapshots__/cursor.spec.ts.snap +++ b/test/__snapshots__/cursor.spec.ts.snap @@ -1,6 +1,1101 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`cursor after + before + filter + offset 1`] = ` +exports[`cursor via GrahpQL after + before + filter + offset: first 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVsemE1MTAiXSxbImlkIiwiOTgiXV19", + "node": Object { + "firstname": "Elza", + "id": "98", + "lastname": "Gorczany", + "username": "elza510", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVsbGEzNzciXSxbImlkIiwiMTAzIl1dfQ==", + "node": Object { + "firstname": "Ella", + "id": "103", + "lastname": "Roberts", + "username": "ella377", + }, + }, + ], + "resultCount": 2, + "totalCount": 9, + }, + }, +} +`; + +exports[`cursor via GrahpQL after + before + filter + offset: found after 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVzdGVsbDY4NCJdLFsiaWQiLCI3MCJdXX0=", + "node": Object { + "firstname": "Estell", + "id": "70", + "lastname": "Waters", + "username": "estell684", + }, + }, + ], + "resultCount": 1, + "totalCount": 1, + }, + }, +} +`; + +exports[`cursor via GrahpQL after + before + filter + offset: found before 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVkd2FyZDk2OSJdLFsiaWQiLCI4Il1dfQ==", + "node": Object { + "firstname": "Edward", + "id": "8", + "lastname": "Dach", + "username": "edward969", + }, + }, + ], + "resultCount": 1, + "totalCount": 1, + }, + }, +} +`; + +exports[`cursor via GrahpQL after + before + filter + offset: last 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVtaWxpYTE4OSJdLFsiaWQiLCI5MCJdXX0=", + "node": Object { + "firstname": "Emilia", + "id": "90", + "lastname": "Marks", + "username": "emilia189", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVtZWxpZTU3OCJdLFsiaWQiLCI1MyJdXX0=", + "node": Object { + "firstname": "Emelie", + "id": "53", + "lastname": "Schamberger", + "username": "emelie578", + }, + }, + ], + "resultCount": 2, + "totalCount": 9, + }, + }, +} +`; + +exports[`cursor via GrahpQL after + filter: found 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVsbGEzNzciXSxbImlkIiwiMTAzIl1dfQ==", + "node": Object { + "firstname": "Ella", + "id": "103", + "lastname": "Roberts", + "username": "ella377", + }, + }, + ], + "resultCount": 1, + "totalCount": 1, + }, + }, +} +`; + +exports[`cursor via GrahpQL after + filter: result 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVsemE1MTAiXSxbImlkIiwiOTgiXV19", + "node": Object { + "firstname": "Elza", + "id": "98", + "lastname": "Gorczany", + "username": "elza510", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVtZWxpZTU3OCJdLFsiaWQiLCI1MyJdXX0=", + "node": Object { + "firstname": "Emelie", + "id": "53", + "lastname": "Schamberger", + "username": "emelie578", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVtaWxpYTE4OSJdLFsiaWQiLCI5MCJdXX0=", + "node": Object { + "firstname": "Emilia", + "id": "90", + "lastname": "Marks", + "username": "emilia189", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVtbWV0NzQxIl0sWyJpZCIsIjEyIl1dfQ==", + "node": Object { + "firstname": "Emmet", + "id": "12", + "lastname": "Boyle", + "username": "emmet741", + }, + }, + ], + "resultCount": 4, + "totalCount": 9, + }, + }, +} +`; + +exports[`cursor via GrahpQL after: found 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFtYWxpYTk0MyJdLFsiaWQiLCI2NSJdXX0=", + "node": Object { + "firstname": "Amalia", + "id": "65", + "lastname": "Stamm", + "username": "amalia943", + }, + }, + ], + "resultCount": 1, + "totalCount": 1, + }, + }, +} +`; + +exports[`cursor via GrahpQL after: result 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFuZ2VsaW5lNDQ3Il0sWyJpZCIsIjM5Il1dfQ==", + "node": Object { + "firstname": "Angeline", + "id": "39", + "lastname": "Tremblay", + "username": "angeline447", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFubmFiZWw3MTEiXSxbImlkIiwiMSJdXX0=", + "node": Object { + "firstname": "Annabel", + "id": "1", + "lastname": "Bergstrom", + "username": "annabel711", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFubmU3NTAiXSxbImlkIiwiODQiXV19", + "node": Object { + "firstname": "Anne", + "id": "84", + "lastname": "Wyman", + "username": "anne750", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFudG9uZTM0NyJdLFsiaWQiLCI2OSJdXX0=", + "node": Object { + "firstname": "Antone", + "id": "69", + "lastname": "Schmitt", + "username": "antone347", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFudG9uaWE5MTkiXSxbImlkIiwiNDYiXV19", + "node": Object { + "firstname": "Antonia", + "id": "46", + "lastname": "Gutkowski", + "username": "antonia919", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFudG9uaW5hNDQ4Il0sWyJpZCIsIjk5Il1dfQ==", + "node": Object { + "firstname": "Antonina", + "id": "99", + "lastname": "Lesch", + "username": "antonina448", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFueWE1NDMiXSxbImlkIiwiMiJdXX0=", + "node": Object { + "firstname": "Anya", + "id": "2", + "lastname": "Conn", + "username": "anya543", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFyYWNlbGk3OTQiXSxbImlkIiwiMjYiXV19", + "node": Object { + "firstname": "Araceli", + "id": "26", + "lastname": "Lind", + "username": "araceli794", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFybGllMTI4Il0sWyJpZCIsIjM0Il1dfQ==", + "node": Object { + "firstname": "Arlie", + "id": "34", + "lastname": "Kemmer", + "username": "arlie128", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImF0aGVuYTU1NyJdLFsiaWQiLCIxNSJdXX0=", + "node": Object { + "firstname": "Athena", + "id": "15", + "lastname": "Stamm", + "username": "athena557", + }, + }, + ], + "resultCount": 10, + "totalCount": 110, + }, + }, +} +`; + +exports[`cursor via GrahpQL before + filter: found 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVtaWxpYTE4OSJdLFsiaWQiLCI5MCJdXX0=", + "node": Object { + "firstname": "Emilia", + "id": "90", + "lastname": "Marks", + "username": "emilia189", + }, + }, + ], + "resultCount": 1, + "totalCount": 1, + }, + }, +} +`; + +exports[`cursor via GrahpQL before + filter: result 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVkd2FyZDk2OSJdLFsiaWQiLCI4Il1dfQ==", + "node": Object { + "firstname": "Edward", + "id": "8", + "lastname": "Dach", + "username": "edward969", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVsYWRpbzgzMiJdLFsiaWQiLCI1OCJdXX0=", + "node": Object { + "firstname": "Eladio", + "id": "58", + "lastname": "Botsford", + "username": "eladio832", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVsbGEzNzciXSxbImlkIiwiMTAzIl1dfQ==", + "node": Object { + "firstname": "Ella", + "id": "103", + "lastname": "Roberts", + "username": "ella377", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImVsemE1MTAiXSxbImlkIiwiOTgiXV19", + "node": Object { + "firstname": "Elza", + "id": "98", + "lastname": "Gorczany", + "username": "elza510", + }, + }, + ], + "resultCount": 4, + "totalCount": 9, + }, + }, +} +`; + +exports[`cursor via GrahpQL before: found 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFtYWxpYTk0MyJdLFsiaWQiLCI2NSJdXX0=", + "node": Object { + "firstname": "Amalia", + "id": "65", + "lastname": "Stamm", + "username": "amalia943", + }, + }, + ], + "resultCount": 1, + "totalCount": 1, + }, + }, +} +`; + +exports[`cursor via GrahpQL before: result 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFpZGEyODUiXSxbImlkIiwiMjQiXV19", + "node": Object { + "firstname": "Aida", + "id": "24", + "lastname": "Lakin", + "username": "aida285", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFsaWNlMTU3Il0sWyJpZCIsIjMxIl1dfQ==", + "node": Object { + "firstname": "Alice", + "id": "31", + "lastname": "Howell", + "username": "alice157", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFsdmEyODAiXSxbImlkIiwiNDIiXV19", + "node": Object { + "firstname": "Alva", + "id": "42", + "lastname": "Jacobson", + "username": "alva280", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJ1c2VybmFtZSIsImFsdmVyYTcwNyJdLFsiaWQiLCI3MiJdXX0=", + "node": Object { + "firstname": "Alvera", + "id": "72", + "lastname": "Miller", + "username": "alvera707", + }, + }, + ], + "resultCount": 4, + "totalCount": 110, + }, + }, +} +`; + +exports[`cursor via GrahpQL mutli-key after + before: found after 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJmaXJzdG5hbWUiLCJKb2UiXSxbImxhc3RuYW1lIiwiUmF0a2UiXSxbImlkIiwiMTA0Il1dfQ==", + "node": Object { + "firstname": "Joe", + "id": "104", + "lastname": "Ratke", + "username": "joe154", + }, + }, + ], + "resultCount": 1, + "totalCount": 1, + }, + }, +} +`; + +exports[`cursor via GrahpQL mutli-key after + before: found before 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJmaXJzdG5hbWUiLCJKb3NlIl0sWyJsYXN0bmFtZSIsIkxlZmZsZXIiXSxbImlkIiwiNzEiXV19", + "node": Object { + "firstname": "Jose", + "id": "71", + "lastname": "Leffler", + "username": "jose821", + }, + }, + ], + "resultCount": 1, + "totalCount": 1, + }, + }, +} +`; + +exports[`cursor via GrahpQL mutli-key after + before: result 1`] = ` +Object { + "data": Object { + "allProfiles": Object { + "edges": Array [ + Object { + "cursor": "eyJQcm9maWxlIjpbWyJmaXJzdG5hbWUiLCJKb2VsIl0sWyJsYXN0bmFtZSIsIkxha2luIl0sWyJpZCIsIjk1Il1dfQ==", + "node": Object { + "firstname": "Joel", + "id": "95", + "lastname": "Lakin", + "username": "joel356", + }, + }, + Object { + "cursor": "eyJQcm9maWxlIjpbWyJmaXJzdG5hbWUiLCJKb25hdGhvbiJdLFsibGFzdG5hbWUiLCJHdXNpa293c2tpIl0sWyJpZCIsIjY3Il1dfQ==", + "node": Object { + "firstname": "Jonathon", + "id": "67", + "lastname": "Gusikowski", + "username": "jonathon586", + }, + }, + ], + "resultCount": 2, + "totalCount": 7, + }, + }, +} +`; + +exports[`cursor via GrahpQL time-based after + first: found 1 1`] = ` +Object { + "data": Object { + "allMessages": Object { + "edges": Array [ + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU3OFoiXSxbImlkIiwiNyJdXX0=", + "node": Object { + "author": "7", + "board": "26", + "content": "velit magnam nobis aspernatur corporis voluptas sed 😀", + "id": "7", + "writtenAt": 2018-03-26T20:47:46.578Z, + }, + }, + ], + "resultCount": 1, + "totalCount": 1, + }, + }, +} +`; + +exports[`cursor via GrahpQL time-based after + first: found 2 1`] = ` +Object { + "data": Object { + "allMessages": Object { + "edges": Array [ + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU3OFoiXSxbImlkIiwiNDAiXV19", + "node": Object { + "author": "78", + "board": "30", + "content": "expedita eveniet dicta deleniti aut distinctio molestiae 😆", + "id": "40", + "writtenAt": 2018-03-26T20:47:46.578Z, + }, + }, + ], + "resultCount": 1, + "totalCount": 1, + }, + }, +} +`; + +exports[`cursor via GrahpQL time-based after + first: found 3 1`] = ` +Object { + "data": Object { + "allMessages": Object { + "edges": Array [ + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU3OFoiXSxbImlkIiwiMjAiXV19", + "node": Object { + "author": "54", + "board": "43", + "content": "fugiat quis a a debitis et culpa", + "id": "20", + "writtenAt": 2018-03-26T20:47:46.578Z, + }, + }, + ], + "resultCount": 1, + "totalCount": 1, + }, + }, +} +`; + +exports[`cursor via GrahpQL time-based after + first: result 1 1`] = ` +Object { + "data": Object { + "allMessages": Object { + "edges": Array [ + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU3OFoiXSxbImlkIiwiMjAiXV19", + "node": Object { + "author": "54", + "board": "43", + "content": "fugiat quis a a debitis et culpa", + "id": "20", + "writtenAt": 2018-03-26T20:47:46.578Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU3OFoiXSxbImlkIiwiNDAiXV19", + "node": Object { + "author": "78", + "board": "30", + "content": "expedita eveniet dicta deleniti aut distinctio molestiae 😆", + "id": "40", + "writtenAt": 2018-03-26T20:47:46.578Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU1NloiXSxbImlkIiwiMzgiXV19", + "node": Object { + "author": "88", + "board": "26", + "content": "enim vel et rem labore amet recusandae 🙌", + "id": "38", + "writtenAt": 2018-03-26T20:47:46.556Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjUxOVoiXSxbImlkIiwiNDgiXV19", + "node": Object { + "author": "25", + "board": "48", + "content": "deserunt voluptates eum aut libero nam sit 🚀", + "id": "48", + "writtenAt": 2018-03-26T20:47:46.519Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjQ4MFoiXSxbImlkIiwiNDciXV19", + "node": Object { + "author": "28", + "board": "13", + "content": "et ut qui eum et consequatur numquam 😆", + "id": "47", + "writtenAt": 2018-03-26T20:47:46.480Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjQyMloiXSxbImlkIiwiMjkiXV19", + "node": Object { + "author": "59", + "board": "12", + "content": "ut distinctio sint dolores ut est corrupti", + "id": "29", + "writtenAt": 2018-03-26T20:47:46.422Z, + }, + }, + ], + "resultCount": 6, + "totalCount": 50, + }, + }, +} +`; + +exports[`cursor via GrahpQL time-based after + first: result 2 1`] = ` +Object { + "data": Object { + "allMessages": Object { + "edges": Array [ + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU1NloiXSxbImlkIiwiMzgiXV19", + "node": Object { + "author": "88", + "board": "26", + "content": "enim vel et rem labore amet recusandae 🙌", + "id": "38", + "writtenAt": 2018-03-26T20:47:46.556Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjUxOVoiXSxbImlkIiwiNDgiXV19", + "node": Object { + "author": "25", + "board": "48", + "content": "deserunt voluptates eum aut libero nam sit 🚀", + "id": "48", + "writtenAt": 2018-03-26T20:47:46.519Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjQ4MFoiXSxbImlkIiwiNDciXV19", + "node": Object { + "author": "28", + "board": "13", + "content": "et ut qui eum et consequatur numquam 😆", + "id": "47", + "writtenAt": 2018-03-26T20:47:46.480Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjQyMloiXSxbImlkIiwiMjkiXV19", + "node": Object { + "author": "59", + "board": "12", + "content": "ut distinctio sint dolores ut est corrupti", + "id": "29", + "writtenAt": 2018-03-26T20:47:46.422Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjA4NFoiXSxbImlkIiwiMTEiXV19", + "node": Object { + "author": "65", + "board": "37", + "content": "voluptatem vero optio mollitia et qui nihil", + "id": "11", + "writtenAt": 2018-03-26T20:47:46.084Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ1Ljg1NFoiXSxbImlkIiwiMTIiXV19", + "node": Object { + "author": "88", + "board": "47", + "content": "voluptatum eius deleniti et consequatur qui architecto 😀", + "id": "12", + "writtenAt": 2018-03-26T20:47:45.854Z, + }, + }, + ], + "resultCount": 6, + "totalCount": 50, + }, + }, +} +`; + +exports[`cursor via GrahpQL time-based after + first: result 3 1`] = ` +Object { + "data": Object { + "allMessages": Object { + "edges": Array [ + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU3OFoiXSxbImlkIiwiNDAiXV19", + "node": Object { + "author": "78", + "board": "30", + "content": "expedita eveniet dicta deleniti aut distinctio molestiae 😆", + "id": "40", + "writtenAt": 2018-03-26T20:47:46.578Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU1NloiXSxbImlkIiwiMzgiXV19", + "node": Object { + "author": "88", + "board": "26", + "content": "enim vel et rem labore amet recusandae 🙌", + "id": "38", + "writtenAt": 2018-03-26T20:47:46.556Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjUxOVoiXSxbImlkIiwiNDgiXV19", + "node": Object { + "author": "25", + "board": "48", + "content": "deserunt voluptates eum aut libero nam sit 🚀", + "id": "48", + "writtenAt": 2018-03-26T20:47:46.519Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjQ4MFoiXSxbImlkIiwiNDciXV19", + "node": Object { + "author": "28", + "board": "13", + "content": "et ut qui eum et consequatur numquam 😆", + "id": "47", + "writtenAt": 2018-03-26T20:47:46.480Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjQyMloiXSxbImlkIiwiMjkiXV19", + "node": Object { + "author": "59", + "board": "12", + "content": "ut distinctio sint dolores ut est corrupti", + "id": "29", + "writtenAt": 2018-03-26T20:47:46.422Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjA4NFoiXSxbImlkIiwiMTEiXV19", + "node": Object { + "author": "65", + "board": "37", + "content": "voluptatem vero optio mollitia et qui nihil", + "id": "11", + "writtenAt": 2018-03-26T20:47:46.084Z, + }, + }, + ], + "resultCount": 6, + "totalCount": 50, + }, + }, +} +`; + +exports[`cursor via GrahpQL time-based before + last: found 1 1`] = ` +Object { + "data": Object { + "allMessages": Object { + "edges": Array [ + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU3OFoiXSxbImlkIiwiNyJdXX0=", + "node": Object { + "author": "7", + "board": "26", + "content": "velit magnam nobis aspernatur corporis voluptas sed 😀", + "id": "7", + "writtenAt": 2018-03-26T20:47:46.578Z, + }, + }, + ], + "resultCount": 1, + "totalCount": 1, + }, + }, +} +`; + +exports[`cursor via GrahpQL time-based before + last: found 2 1`] = ` +Object { + "data": Object { + "allMessages": Object { + "edges": Array [ + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU3OFoiXSxbImlkIiwiNDAiXV19", + "node": Object { + "author": "78", + "board": "30", + "content": "expedita eveniet dicta deleniti aut distinctio molestiae 😆", + "id": "40", + "writtenAt": 2018-03-26T20:47:46.578Z, + }, + }, + ], + "resultCount": 1, + "totalCount": 1, + }, + }, +} +`; + +exports[`cursor via GrahpQL time-based before + last: found 3 1`] = ` +Object { + "data": Object { + "allMessages": Object { + "edges": Array [ + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU3OFoiXSxbImlkIiwiMjAiXV19", + "node": Object { + "author": "54", + "board": "43", + "content": "fugiat quis a a debitis et culpa", + "id": "20", + "writtenAt": 2018-03-26T20:47:46.578Z, + }, + }, + ], + "resultCount": 1, + "totalCount": 1, + }, + }, +} +`; + +exports[`cursor via GrahpQL time-based before + last: result 1 1`] = ` +Object { + "data": Object { + "allMessages": Object { + "edges": Array [ + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ1Ljg1NFoiXSxbImlkIiwiMTIiXV19", + "node": Object { + "author": "88", + "board": "47", + "content": "voluptatum eius deleniti et consequatur qui architecto 😀", + "id": "12", + "writtenAt": 2018-03-26T20:47:45.854Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjA4NFoiXSxbImlkIiwiMTEiXV19", + "node": Object { + "author": "65", + "board": "37", + "content": "voluptatem vero optio mollitia et qui nihil", + "id": "11", + "writtenAt": 2018-03-26T20:47:46.084Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjQyMloiXSxbImlkIiwiMjkiXV19", + "node": Object { + "author": "59", + "board": "12", + "content": "ut distinctio sint dolores ut est corrupti", + "id": "29", + "writtenAt": 2018-03-26T20:47:46.422Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjQ4MFoiXSxbImlkIiwiNDciXV19", + "node": Object { + "author": "28", + "board": "13", + "content": "et ut qui eum et consequatur numquam 😆", + "id": "47", + "writtenAt": 2018-03-26T20:47:46.480Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjUxOVoiXSxbImlkIiwiNDgiXV19", + "node": Object { + "author": "25", + "board": "48", + "content": "deserunt voluptates eum aut libero nam sit 🚀", + "id": "48", + "writtenAt": 2018-03-26T20:47:46.519Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU1NloiXSxbImlkIiwiMzgiXV19", + "node": Object { + "author": "88", + "board": "26", + "content": "enim vel et rem labore amet recusandae 🙌", + "id": "38", + "writtenAt": 2018-03-26T20:47:46.556Z, + }, + }, + ], + "resultCount": 6, + "totalCount": 50, + }, + }, +} +`; + +exports[`cursor via GrahpQL time-based before + last: result 2 1`] = ` +Object { + "data": Object { + "allMessages": Object { + "edges": Array [ + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjQyMloiXSxbImlkIiwiMjkiXV19", + "node": Object { + "author": "59", + "board": "12", + "content": "ut distinctio sint dolores ut est corrupti", + "id": "29", + "writtenAt": 2018-03-26T20:47:46.422Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjQ4MFoiXSxbImlkIiwiNDciXV19", + "node": Object { + "author": "28", + "board": "13", + "content": "et ut qui eum et consequatur numquam 😆", + "id": "47", + "writtenAt": 2018-03-26T20:47:46.480Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjUxOVoiXSxbImlkIiwiNDgiXV19", + "node": Object { + "author": "25", + "board": "48", + "content": "deserunt voluptates eum aut libero nam sit 🚀", + "id": "48", + "writtenAt": 2018-03-26T20:47:46.519Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU1NloiXSxbImlkIiwiMzgiXV19", + "node": Object { + "author": "88", + "board": "26", + "content": "enim vel et rem labore amet recusandae 🙌", + "id": "38", + "writtenAt": 2018-03-26T20:47:46.556Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU3OFoiXSxbImlkIiwiNyJdXX0=", + "node": Object { + "author": "7", + "board": "26", + "content": "velit magnam nobis aspernatur corporis voluptas sed 😀", + "id": "7", + "writtenAt": 2018-03-26T20:47:46.578Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU3OFoiXSxbImlkIiwiMjAiXV19", + "node": Object { + "author": "54", + "board": "43", + "content": "fugiat quis a a debitis et culpa", + "id": "20", + "writtenAt": 2018-03-26T20:47:46.578Z, + }, + }, + ], + "resultCount": 6, + "totalCount": 50, + }, + }, +} +`; + +exports[`cursor via GrahpQL time-based before + last: result 3 1`] = ` +Object { + "data": Object { + "allMessages": Object { + "edges": Array [ + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjA4NFoiXSxbImlkIiwiMTEiXV19", + "node": Object { + "author": "65", + "board": "37", + "content": "voluptatem vero optio mollitia et qui nihil", + "id": "11", + "writtenAt": 2018-03-26T20:47:46.084Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjQyMloiXSxbImlkIiwiMjkiXV19", + "node": Object { + "author": "59", + "board": "12", + "content": "ut distinctio sint dolores ut est corrupti", + "id": "29", + "writtenAt": 2018-03-26T20:47:46.422Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjQ4MFoiXSxbImlkIiwiNDciXV19", + "node": Object { + "author": "28", + "board": "13", + "content": "et ut qui eum et consequatur numquam 😆", + "id": "47", + "writtenAt": 2018-03-26T20:47:46.480Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjUxOVoiXSxbImlkIiwiNDgiXV19", + "node": Object { + "author": "25", + "board": "48", + "content": "deserunt voluptates eum aut libero nam sit 🚀", + "id": "48", + "writtenAt": 2018-03-26T20:47:46.519Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU1NloiXSxbImlkIiwiMzgiXV19", + "node": Object { + "author": "88", + "board": "26", + "content": "enim vel et rem labore amet recusandae 🙌", + "id": "38", + "writtenAt": 2018-03-26T20:47:46.556Z, + }, + }, + Object { + "cursor": "eyJNZXNzYWdlIjpbWyJ3cml0dGVuQXQiLCIyMDE4LTAzLTI2VDIwOjQ3OjQ2LjU3OFoiXSxbImlkIiwiNyJdXX0=", + "node": Object { + "author": "7", + "board": "26", + "content": "velit magnam nobis aspernatur corporis voluptas sed 😀", + "id": "7", + "writtenAt": 2018-03-26T20:47:46.578Z, + }, + }, + ], + "resultCount": 6, + "totalCount": 50, + }, + }, +} +`; + +exports[`cursor via connector after + before + filter + offset 1`] = ` Object { "data": Array [ Object { @@ -27,7 +1122,7 @@ Object { } `; -exports[`cursor after + before + filter + offset 2`] = ` +exports[`cursor via connector after + before + filter + offset 2`] = ` Object { "data": Array [ Object { @@ -54,7 +1149,7 @@ Object { } `; -exports[`cursor after + filter 1`] = ` +exports[`cursor via connector after + filter 1`] = ` Object { "data": Array [ Object { @@ -97,7 +1192,7 @@ Object { } `; -exports[`cursor after 1`] = ` +exports[`cursor via connector after 1`] = ` Object { "data": Array [ Object { @@ -188,7 +1283,7 @@ Object { } `; -exports[`cursor before + filter 1`] = ` +exports[`cursor via connector before + filter 1`] = ` Object { "data": Array [ Object { @@ -231,7 +1326,7 @@ Object { } `; -exports[`cursor before 1`] = ` +exports[`cursor via connector before 1`] = ` Object { "data": Array [ Object { @@ -274,7 +1369,7 @@ Object { } `; -exports[`cursor mutli-key after + before 1`] = ` +exports[`cursor via connector mutli-key after + before 1`] = ` Object { "data": Array [ Object { @@ -301,7 +1396,7 @@ Object { } `; -exports[`cursor time-based after + first: id: 7 1`] = ` +exports[`cursor via connector time-based after + first: id: 7 1`] = ` Object { "data": Array [ Object { @@ -354,7 +1449,7 @@ Object { } `; -exports[`cursor time-based after + first: id: 20 1`] = ` +exports[`cursor via connector time-based after + first: id: 20 1`] = ` Object { "data": Array [ Object { @@ -407,7 +1502,7 @@ Object { } `; -exports[`cursor time-based after + first: id: 40 1`] = ` +exports[`cursor via connector time-based after + first: id: 40 1`] = ` Object { "data": Array [ Object { @@ -460,7 +1555,7 @@ Object { } `; -exports[`cursor time-based before + last: id: 7 1`] = ` +exports[`cursor via connector time-based before + last: id: 7 1`] = ` Object { "data": Array [ Object { @@ -513,7 +1608,7 @@ Object { } `; -exports[`cursor time-based before + last: id: 20 1`] = ` +exports[`cursor via connector time-based before + last: id: 20 1`] = ` Object { "data": Array [ Object { @@ -566,7 +1661,7 @@ Object { } `; -exports[`cursor time-based before + last: id: 40 1`] = ` +exports[`cursor via connector time-based before + last: id: 40 1`] = ` Object { "data": Array [ Object { diff --git a/test/cursor.spec.ts b/test/cursor.spec.ts index 19e61d26..9c3338f5 100644 --- a/test/cursor.spec.ts +++ b/test/cursor.spec.ts @@ -1,10 +1,11 @@ import './setupAndTearDown'; -import { find } from './db'; +import { find, testGraphql } from './db'; import { asAdmin, removeListDynamicData } from './testUtils'; import { Profile } from './models/Profile'; import { Message } from './models/Message'; +import { gql } from '../src/graphqlProtocol/util'; const orderByUsernameAsc = { orderBy: [ @@ -43,207 +44,625 @@ const orderByWrittenAtDesc = { }; describe('cursor', () => { - it('after', async () => { - const cursor = { - after: { - Profile: [ [ 'username', 'amalia943' ], [ 'id', 65 ] ], - }, - }; - - const result = await find( - Profile, - { ...orderByUsernameAsc, ...cursor }, - asAdmin(), - ); - result.data = removeListDynamicData(Profile, result.data); - - expect(result).toMatchSnapshot(); - }); + describe('via connector', () => { + it('after', async () => { + const cursor = { + after: { + Profile: [ + ['username', 'amalia943'], + ['id', 65], + ], + }, + }; + + const result = await find( + Profile, + { ...orderByUsernameAsc, ...cursor }, + asAdmin(), + ); + result.data = removeListDynamicData(Profile, result.data); + + expect(result).toMatchSnapshot(); + }); + + it('before', async () => { + const cursor = { + before: { + Profile: [ + ['username', 'amalia943'], + ['id', 65], + ], + }, + }; + + const result = await find( + Profile, + { ...orderByUsernameAsc, ...cursor }, + asAdmin(), + ); + result.data = removeListDynamicData(Profile, result.data); + + expect(result).toMatchSnapshot(); + }); + + it('after + filter', async () => { + const cursor = { + after: { + Profile: [ + ['username', 'ella377'], + ['id', 103], + ], + }, + }; - it('before', async () => { - const cursor = { - before: { - Profile: [ [ 'username', 'amalia943' ], [ 'id', 65 ] ], - }, - }; - - const result = await find( - Profile, - { ...orderByUsernameAsc, ...cursor }, - asAdmin(), - ); - result.data = removeListDynamicData(Profile, result.data); - - expect(result).toMatchSnapshot(); - }); + const filter = { + username: { + $starts_with: 'e', + $not_ends_with: '3', + }, + }; + + const result = await find( + Profile, + { ...orderByUsernameAsc, ...cursor, filter, first: 4 }, + asAdmin(), + ); + result.data = removeListDynamicData(Profile, result.data); + + expect(result).toMatchSnapshot(); + }); + + it('before + filter', async () => { + const cursor = { + before: { + Profile: [ + ['username', 'emilia189'], + ['id', 90], + ], + }, + }; - it('after + filter', async () => { - const cursor = { - after: { - Profile: [ [ 'username', 'ella377' ], [ 'id', 103 ] ], - }, - }; - - const filter = { - username: { - $starts_with: 'e', - $not_ends_with: '3', - }, - }; - - const result = await find( - Profile, - { ...orderByUsernameAsc, ...cursor, filter, first: 4 }, - asAdmin(), - ); - result.data = removeListDynamicData(Profile, result.data); - - expect(result).toMatchSnapshot(); - }); + const filter = { + username: { + $starts_with: 'e', + $not_ends_with: '3', + }, + }; + + const result = await find( + Profile, + { ...orderByUsernameAsc, ...cursor, filter, first: 4 }, + asAdmin(), + ); + result.data = removeListDynamicData(Profile, result.data); + + expect(result).toMatchSnapshot(); + }); + + it('after + before + filter + offset', async () => { + const cursor = { + after: { + Profile: [ + ['username', 'estell684'], + ['id', 70], + ], + }, + before: { + Profile: [ + ['username', 'edward969'], + ['id', 8], + ], + }, + }; - it('before + filter', async () => { - const cursor = { - before: { - Profile: [ [ 'username', 'emilia189' ], [ 'id', 90 ] ], - }, - }; - - const filter = { - username: { - $starts_with: 'e', - $not_ends_with: '3', - }, - }; - - const result = await find( - Profile, - { ...orderByUsernameAsc, ...cursor, filter, first: 4 }, - asAdmin(), - ); - result.data = removeListDynamicData(Profile, result.data); - - expect(result).toMatchSnapshot(); - }); + const filter = { + username: { + $starts_with: 'e', + $not_ends_with: '3', + }, + }; + + let result; + + result = await find( + Profile, + { ...orderByUsernameDesc, ...cursor, filter, offset: 3, first: 2 }, + asAdmin(), + ); + result.data = removeListDynamicData(Profile, result.data); + expect(result).toMatchSnapshot(); + + result = await find( + Profile, + { ...orderByUsernameDesc, ...cursor, filter, offset: 3, last: 2 }, + asAdmin(), + ); + result.data = removeListDynamicData(Profile, result.data); + expect(result).toMatchSnapshot(); + }); + + it('mutli-key after + before', async () => { + const orderByNames = { + orderBy: [ + { + attribute: 'firstname', + direction: 'ASC', + }, + { + attribute: 'lastname', + direction: 'DESC', + }, + { + attribute: 'id', + direction: 'ASC', + }, + ], + }; + + const cursor = { + after: { + Profile: [ + ['firstname', 'Joe'], + ['lastname', 'Ratke'], + ['id', 104], + ], + }, + before: { + Profile: [ + ['firstname', 'Jose'], + ['lastname', 'Leffler'], + ['id', 71], + ], + }, + }; - it('after + before + filter + offset', async () => { - const cursor = { - after: { - Profile: [ [ 'username', 'estell684' ], [ 'id', 70 ] ], - }, - before: { - Profile: [ [ 'username', 'edward969' ], [ 'id', 8 ] ], - }, - }; - - const filter = { - username: { - $starts_with: 'e', - $not_ends_with: '3', - }, - }; - - let result; - - result = await find( - Profile, - { ...orderByUsernameDesc, ...cursor, filter, offset: 3, first: 2 }, - asAdmin(), - ); - result.data = removeListDynamicData(Profile, result.data); - expect(result).toMatchSnapshot(); - - result = await find( - Profile, - { ...orderByUsernameDesc, ...cursor, filter, offset: 3, last: 2 }, - asAdmin(), - ); - result.data = removeListDynamicData(Profile, result.data); - expect(result).toMatchSnapshot(); + const filter = { + username: { + $starts_with: 'jo', + }, + }; + + const result = await find( + Profile, + { ...orderByNames, ...cursor, filter }, + asAdmin(), + ); + result.data = removeListDynamicData(Profile, result.data); + expect(result).toMatchSnapshot(); + }); + + it('time-based after + first', async () => { + const differentiatorId = [7, 40, 20]; + + await Promise.all( + differentiatorId.map(async (id) => { + const cursor = { + after: { + Message: [ + ['writtenAt', '2018-03-26 20:47:46.578Z'], + ['id', id], + ], + }, + }; + + const result = await find( + Message, + { ...orderByWrittenAtDesc, ...cursor, first: 6 }, + asAdmin(), + ); + result.data = removeListDynamicData(Message, result.data); + expect(result).toMatchSnapshot(`id: ${id}`); + }), + ); + }); + + it('time-based before + last', async () => { + const differentiatorId = [7, 40, 20]; + + await Promise.all( + differentiatorId.map(async (id) => { + const cursor = { + before: { + Message: [ + ['writtenAt', '2018-03-26 20:47:46.578Z'], + ['id', id], + ], + }, + }; + + const result = await find( + Message, + { ...orderByWrittenAtAsc, ...cursor, last: 6 }, + asAdmin(), + ); + result.data = removeListDynamicData(Message, result.data); + expect(result).toMatchSnapshot(`id: ${id}`); + }), + ); + }); }); - it('mutli-key after + before', async () => { - const orderByNames = { - orderBy: [ - { - attribute: 'firstname', - direction: 'ASC', + describe('via GrahpQL', () => { + const findProfilesQuery = gql` + query allProfiles( + $profileFilter: ProfileFilter + $after: Cursor + $before: Cursor + $first: Int + $last: Int + $offset: Int + $orderBy: [ProfileOrderBy] + ) { + allProfiles( + filter: $profileFilter + after: $after + before: $before + first: $first + last: $last + offset: $offset + orderBy: $orderBy + ) { + totalCount + resultCount + edges { + cursor + node { + id + username + firstname + lastname + } + } + } + } + `; + + it('after', async () => { + const foundProfile = await testGraphql(findProfilesQuery, asAdmin(), { + orderBy: ['USERNAME_ASC'], + profileFilter: { + username: 'amalia943', + }, + }); + + expect(foundProfile).toMatchSnapshot('found'); + + const cursor = foundProfile.data.allProfiles.edges[0].cursor; + + const result = await testGraphql(findProfilesQuery, asAdmin(), { + orderBy: ['USERNAME_ASC'], + after: cursor, + }); + + expect(result).toMatchSnapshot('result'); + }); + + it('before', async () => { + const foundProfile = await testGraphql(findProfilesQuery, asAdmin(), { + orderBy: ['USERNAME_ASC'], + profileFilter: { + username: 'amalia943', }, + }); + + expect(foundProfile).toMatchSnapshot('found'); + + const cursor = foundProfile.data.allProfiles.edges[0].cursor; + + const result = await testGraphql(findProfilesQuery, asAdmin(), { + orderBy: ['USERNAME_ASC'], + before: cursor, + }); + + expect(result).toMatchSnapshot('result'); + }); + + it('after + filter', async () => { + const foundProfile = await testGraphql(findProfilesQuery, asAdmin(), { + orderBy: ['USERNAME_ASC'], + profileFilter: { + username: 'ella377', + }, + }); + + expect(foundProfile).toMatchSnapshot('found'); + + const cursor = foundProfile.data.allProfiles.edges[0].cursor; + + const result = await testGraphql(findProfilesQuery, asAdmin(), { + orderBy: ['USERNAME_ASC'], + after: cursor, + first: 4, + profileFilter: { + username__starts_with: 'e', + username__not_ends_with: '3', + }, + }); + + expect(result).toMatchSnapshot('result'); + }); + + it('before + filter', async () => { + const foundProfile = await testGraphql(findProfilesQuery, asAdmin(), { + orderBy: ['USERNAME_ASC'], + profileFilter: { + username: 'emilia189', + }, + }); + + expect(foundProfile).toMatchSnapshot('found'); + + const cursor = foundProfile.data.allProfiles.edges[0].cursor; + + const result = await testGraphql(findProfilesQuery, asAdmin(), { + orderBy: ['USERNAME_ASC'], + before: cursor, + first: 4, + profileFilter: { + username__starts_with: 'e', + username__not_ends_with: '3', + }, + }); + + expect(result).toMatchSnapshot('result'); + }); + + it('after + before + filter + offset', async () => { + const foundProfileAfter = await testGraphql( + findProfilesQuery, + asAdmin(), { - attribute: 'lastname', - direction: 'DESC', + orderBy: ['USERNAME_DESC'], + profileFilter: { + username: 'estell684', + }, }, + ); + + expect(foundProfileAfter).toMatchSnapshot('found after'); + + const cursorAfter = foundProfileAfter.data.allProfiles.edges[0].cursor; + + const foundProfileBefore = await testGraphql( + findProfilesQuery, + asAdmin(), { - attribute: 'id', - direction: 'ASC', - }, - ], - }; - - const cursor = { - after: { - Profile: [ [ 'firstname', 'Joe' ], [ 'lastname', 'Ratke' ], [ 'id', 104 ] ], - }, - before: { - Profile: [ [ 'firstname', 'Jose' ], [ 'lastname', 'Leffler' ], [ 'id', 71 ] ], - }, - }; - - const filter = { - username: { - $starts_with: 'jo', - }, - }; - - const result = await find( - Profile, - { ...orderByNames, ...cursor, filter }, - asAdmin(), - ); - result.data = removeListDynamicData(Profile, result.data); - expect(result).toMatchSnapshot(); - }); + orderBy: ['USERNAME_DESC'], + profileFilter: { + username: 'edward969', + }, + }, + ); + + expect(foundProfileBefore).toMatchSnapshot('found before'); - it('time-based after + first', async () => { - const differentiatorId = [ 7, 40, 20 ]; + const cursorBefore = foundProfileBefore.data.allProfiles.edges[0].cursor; - await Promise.all( - differentiatorId.map(async id => { - const cursor = { - after: { - Message: [ [ 'writtenAt', '2018-03-26 20:47:46.578Z' ], [ 'id', id ] ], + const result1 = await testGraphql(findProfilesQuery, asAdmin(), { + orderBy: ['USERNAME_DESC'], + after: cursorAfter, + before: cursorBefore, + first: 2, + offset: 3, + profileFilter: { + username__starts_with: 'e', + username__not_ends_with: '3', + }, + }); + + expect(result1).toMatchSnapshot('first'); + + const result2 = await testGraphql(findProfilesQuery, asAdmin(), { + orderBy: ['USERNAME_DESC'], + after: cursorAfter, + before: cursorBefore, + last: 2, + offset: 3, + profileFilter: { + username__starts_with: 'e', + username__not_ends_with: '3', + }, + }); + + expect(result2).toMatchSnapshot('last'); + }); + + it('mutli-key after + before', async () => { + const foundProfileAfter = await testGraphql( + findProfilesQuery, + asAdmin(), + { + orderBy: ['FIRSTNAME_ASC', 'LASTNAME_DESC', 'ID_ASC'], + profileFilter: { + firstname: 'Joe', + lastname: 'Ratke', }, - }; - - const result = await find( - Message, - { ...orderByWrittenAtDesc, ...cursor, first: 6 }, - asAdmin(), - ); - result.data = removeListDynamicData(Message, result.data); - expect(result).toMatchSnapshot(`id: ${id}`); - }), - ); - }); + }, + ); + + expect(foundProfileAfter).toMatchSnapshot('found after'); - it('time-based before + last', async () => { - const differentiatorId = [ 7, 40, 20 ]; + const cursorAfter = foundProfileAfter.data.allProfiles.edges[0].cursor; - await Promise.all( - differentiatorId.map(async id => { - const cursor = { - before: { - Message: [ [ 'writtenAt', '2018-03-26 20:47:46.578Z' ], [ 'id', id ] ], + const foundProfileBefore = await testGraphql( + findProfilesQuery, + asAdmin(), + { + orderBy: ['FIRSTNAME_ASC', 'LASTNAME_DESC', 'ID_ASC'], + profileFilter: { + firstname: 'Jose', + lastname: 'Leffler', }, - }; - - const result = await find( - Message, - { ...orderByWrittenAtAsc, ...cursor, last: 6 }, - asAdmin(), - ); - result.data = removeListDynamicData(Message, result.data); - expect(result).toMatchSnapshot(`id: ${id}`); - }), - ); + }, + ); + + expect(foundProfileBefore).toMatchSnapshot('found before'); + + const cursorBefore = foundProfileBefore.data.allProfiles.edges[0].cursor; + + const result = await testGraphql(findProfilesQuery, asAdmin(), { + orderBy: ['FIRSTNAME_ASC', 'LASTNAME_DESC', 'ID_ASC'], + after: cursorAfter, + before: cursorBefore, + profileFilter: { + username__starts_with: 'jo', + }, + }); + + expect(result).toMatchSnapshot('result'); + }); + + const findMessagesQuery = gql` + query allMessages( + $messageFilter: MessageFilter + $after: Cursor + $before: Cursor + $first: Int + $last: Int + $offset: Int + $orderBy: [MessageOrderBy] + ) { + allMessages( + filter: $messageFilter + after: $after + before: $before + first: $first + last: $last + offset: $offset + orderBy: $orderBy + ) { + totalCount + resultCount + edges { + cursor + node { + id + author + board + content + writtenAt + } + } + } + } + `; + + it('time-based after + first', async () => { + const foundMessage1 = await testGraphql(findMessagesQuery, asAdmin(), { + orderBy: ['WRITTEN_AT_DESC'], + messageFilter: { + id: 7, + }, + }); + + expect(foundMessage1).toMatchSnapshot('found 1'); + + const cursor1 = foundMessage1.data.allMessages.edges[0].cursor; + + const result1 = await testGraphql(findMessagesQuery, asAdmin(), { + orderBy: ['WRITTEN_AT_DESC'], + after: cursor1, + first: 6, + }); + + expect(result1).toMatchSnapshot('result 1'); + + const foundMessage2 = await testGraphql(findMessagesQuery, asAdmin(), { + orderBy: ['WRITTEN_AT_DESC'], + messageFilter: { + id: 40, + }, + }); + + expect(foundMessage2).toMatchSnapshot('found 2'); + + const cursor2 = foundMessage2.data.allMessages.edges[0].cursor; + + const result2 = await testGraphql(findMessagesQuery, asAdmin(), { + orderBy: ['WRITTEN_AT_DESC'], + after: cursor2, + first: 6, + }); + + expect(result2).toMatchSnapshot('result 2'); + + const foundMessage3 = await testGraphql(findMessagesQuery, asAdmin(), { + orderBy: ['WRITTEN_AT_DESC'], + messageFilter: { + id: 20, + }, + }); + + expect(foundMessage3).toMatchSnapshot('found 3'); + + const cursor3 = foundMessage3.data.allMessages.edges[0].cursor; + + const result3 = await testGraphql(findMessagesQuery, asAdmin(), { + orderBy: ['WRITTEN_AT_DESC'], + after: cursor3, + first: 6, + }); + + expect(result3).toMatchSnapshot('result 3'); + }); + + it('time-based before + last', async () => { + const foundMessage1 = await testGraphql(findMessagesQuery, asAdmin(), { + orderBy: ['WRITTEN_AT_ASC'], + messageFilter: { + id: 7, + }, + }); + + expect(foundMessage1).toMatchSnapshot('found 1'); + + const cursor1 = foundMessage1.data.allMessages.edges[0].cursor; + + const result1 = await testGraphql(findMessagesQuery, asAdmin(), { + orderBy: ['WRITTEN_AT_ASC'], + before: cursor1, + last: 6, + }); + + expect(result1).toMatchSnapshot('result 1'); + + const foundMessage2 = await testGraphql(findMessagesQuery, asAdmin(), { + orderBy: ['WRITTEN_AT_ASC'], + messageFilter: { + id: 40, + }, + }); + + expect(foundMessage2).toMatchSnapshot('found 2'); + + const cursor2 = foundMessage2.data.allMessages.edges[0].cursor; + + const result2 = await testGraphql(findMessagesQuery, asAdmin(), { + orderBy: ['WRITTEN_AT_ASC'], + before: cursor2, + last: 6, + }); + + expect(result2).toMatchSnapshot('result 2'); + + const foundMessage3 = await testGraphql(findMessagesQuery, asAdmin(), { + orderBy: ['WRITTEN_AT_ASC'], + messageFilter: { + id: 20, + }, + }); + + expect(foundMessage3).toMatchSnapshot('found 3'); + + const cursor3 = foundMessage3.data.allMessages.edges[0].cursor; + + const result3 = await testGraphql(findMessagesQuery, asAdmin(), { + orderBy: ['WRITTEN_AT_ASC'], + before: cursor3, + last: 6, + }); + + expect(result3).toMatchSnapshot('result 3'); + }); }); });