From d087f3cedc4d060cd9e014ea35898cf3b9b1e356 Mon Sep 17 00:00:00 2001 From: Tim Leslie Date: Thu, 30 Jul 2020 14:02:15 +1000 Subject: [PATCH] Use authedGraphqlRequest rather than networkedGraphqlRequest where appropriate --- .changeset/silly-bags-jam.md | 5 ++ .../extend-graphql-schema.test.js | 8 +- .../filtering/access-control.test.js | 14 ++-- .../nested-mutations/connect-many.test.js | 64 ++++++--------- .../nested-mutations/connect-singular.test.js | 64 ++++++--------- .../create-and-connect-many.test.js | 52 +++++------- .../nested-mutations/create-many.test.js | 82 ++++++++----------- .../nested-mutations/create-singular.test.js | 66 +++++++-------- .../disconnect-all-many.test.js | 8 +- .../disconnect-all-singular.test.js | 8 +- .../nested-mutations/disconnect-many.test.js | 8 +- .../disconnect-singular.test.js | 8 +- 12 files changed, 172 insertions(+), 215 deletions(-) create mode 100644 .changeset/silly-bags-jam.md diff --git a/.changeset/silly-bags-jam.md b/.changeset/silly-bags-jam.md new file mode 100644 index 00000000000..1c3e79e5dff --- /dev/null +++ b/.changeset/silly-bags-jam.md @@ -0,0 +1,5 @@ +--- +'@keystonejs/api-tests': patch +--- + +Use `authedGraphqlRequest` rather than `networkedGraphqlRequest` where appropriate. diff --git a/api-tests/extend-graphql-schema/extend-graphql-schema.test.js b/api-tests/extend-graphql-schema/extend-graphql-schema.test.js index 606aa7bc550..15102dfd66b 100644 --- a/api-tests/extend-graphql-schema/extend-graphql-schema.test.js +++ b/api-tests/extend-graphql-schema/extend-graphql-schema.test.js @@ -3,7 +3,7 @@ const { multiAdapterRunners, setupServer, graphqlRequest, - networkedGraphqlRequest, + authedGraphqlRequest, } = require('@keystonejs/test-utils'); const falseFn = () => false; @@ -76,9 +76,9 @@ multiAdapterRunners().map(({ runner, adapterName }) => ); it( 'Denies access acording to access control', - runner(setupKeystone, async ({ app }) => { - const { data, errors } = await networkedGraphqlRequest({ - app, + runner(setupKeystone, async ({ keystone }) => { + const { data, errors } = await authedGraphqlRequest({ + keystone, query: ` query { quads(x: 10) diff --git a/api-tests/relationships/filtering/access-control.test.js b/api-tests/relationships/filtering/access-control.test.js index c74fb7a3bd6..5aa721bf719 100644 --- a/api-tests/relationships/filtering/access-control.test.js +++ b/api-tests/relationships/filtering/access-control.test.js @@ -3,7 +3,7 @@ const { Text, Relationship } = require('@keystonejs/fields'); const { multiAdapterRunners, setupServer, - networkedGraphqlRequest, + authedGraphqlRequest, } = require('@keystonejs/test-utils'); const alphanumGenerator = gen.alphaNumString.notEmpty(); @@ -39,7 +39,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => describe('relationship filtering with access control', () => { test( 'implicitly filters to only the IDs in the database by default', - runner(setupKeystone, async ({ app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { // Create all of the posts with the given IDs & random content const posts = await Promise.all( postNames.map(name => { @@ -57,8 +57,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => }); // Create an item that does the linking - const { data, errors } = await networkedGraphqlRequest({ - app, + const { data, errors } = await authedGraphqlRequest({ + keystone, query: ` query { UserToPostLimitedRead(where: { id: "${user.id}" }) { @@ -85,7 +85,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => test( 'explicitly filters when given a `where` clause', - runner(setupKeystone, async ({ app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { // Create all of the posts with the given IDs & random content const posts = await Promise.all( postNames.map(name => { @@ -103,8 +103,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => }); // Create an item that does the linking - const { data, errors } = await networkedGraphqlRequest({ - app, + const { data, errors } = await authedGraphqlRequest({ + keystone, query: ` query { UserToPostLimitedRead(where: { id: "${user.id}" }) { diff --git a/api-tests/relationships/nested-mutations/connect-many.test.js b/api-tests/relationships/nested-mutations/connect-many.test.js index 8d6aa9c28b9..36862d552c7 100644 --- a/api-tests/relationships/nested-mutations/connect-many.test.js +++ b/api-tests/relationships/nested-mutations/connect-many.test.js @@ -4,7 +4,7 @@ const { multiAdapterRunners, setupServer, graphqlRequest, - networkedGraphqlRequest, + authedGraphqlRequest, } = require('@keystonejs/test-utils'); const alphanumGenerator = gen.alphaNumString.notEmpty(); @@ -446,7 +446,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => describe('read: false on related list', () => { test( 'throws when link nested from within create mutation', - runner(setupKeystone, async ({ app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { const noteContent = sampleOne(alphanumGenerator); // Create an item to link against @@ -454,8 +454,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => content: noteContent, }); - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { createUserToNotesNoRead(data: { @@ -468,24 +468,19 @@ multiAdapterRunners().map(({ runner, adapterName }) => `, }); - expect(errors).toMatchObject([ - { - data: { - errors: expect.arrayContaining([ - expect.objectContaining({ - message: - 'Unable to create and/or connect 1 UserToNotesNoRead.notes', - }), - ]), - }, - }, - ]); + expect(errors).toHaveLength(1); + const error = errors[0]; + expect(error.message).toEqual( + 'Unable to create and/or connect 1 UserToNotesNoRead.notes' + ); + expect(error.path).toHaveLength(1); + expect(error.path[0]).toEqual('createUserToNotesNoRead'); }) ); test( 'throws when link nested from within update mutation', - runner(setupKeystone, async ({ app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { const noteContent = sampleOne(alphanumGenerator); // Create an item to link against @@ -497,8 +492,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => }); // Update the item and link the relationship field - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { updateUserToNotesNoRead( @@ -514,18 +509,13 @@ multiAdapterRunners().map(({ runner, adapterName }) => `, }); - expect(errors).toMatchObject([ - { - data: { - errors: expect.arrayContaining([ - expect.objectContaining({ - message: - 'Unable to create and/or connect 1 UserToNotesNoRead.notes', - }), - ]), - }, - }, - ]); + expect(errors).toHaveLength(1); + const error = errors[0]; + expect(error.message).toEqual( + 'Unable to create and/or connect 1 UserToNotesNoRead.notes' + ); + expect(error.path).toHaveLength(1); + expect(error.path[0]).toEqual('updateUserToNotesNoRead'); }) ); }); @@ -533,7 +523,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => describe('create: false on related list', () => { test( 'does not throw when link nested from within create mutation', - runner(setupKeystone, async ({ app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { const noteContent = sampleOne(alphanumGenerator); // Create an item to link against @@ -542,8 +532,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => }); // Create an item that does the linking - const { data, errors } = await networkedGraphqlRequest({ - app, + const { data, errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { createUserToNotesNoCreate(data: { @@ -563,7 +553,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => test( 'does not throw when link nested from within update mutation', - runner(setupKeystone, async ({ app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { const noteContent = sampleOne(alphanumGenerator); // Create an item to link against @@ -575,8 +565,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => }); // Update the item and link the relationship field - const { data, errors } = await networkedGraphqlRequest({ - app, + const { data, errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { updateUserToNotesNoCreate( diff --git a/api-tests/relationships/nested-mutations/connect-singular.test.js b/api-tests/relationships/nested-mutations/connect-singular.test.js index b13bbde036c..560ebca3f5d 100644 --- a/api-tests/relationships/nested-mutations/connect-singular.test.js +++ b/api-tests/relationships/nested-mutations/connect-singular.test.js @@ -4,7 +4,7 @@ const { multiAdapterRunners, setupServer, graphqlRequest, - networkedGraphqlRequest, + authedGraphqlRequest, } = require('@keystonejs/test-utils'); function setupKeystone(adapterName) { @@ -269,7 +269,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => if (group.allowed) { test( 'does not throw error when linking nested within create mutation', - runner(setupKeystone, async ({ app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { const groupName = sampleOne(gen.alphaNumString.notEmpty()); // Create an item to link against @@ -278,8 +278,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => expect(id).toBeTruthy(); // Create an item that does the linking - const { data, errors } = await networkedGraphqlRequest({ - app, + const { data, errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { createEventTo${group.name}(data: { @@ -303,7 +303,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => ); test( 'does not throw error when linking nested within update mutation', - runner(setupKeystone, async ({ app, create, findOne, findById }) => { + runner(setupKeystone, async ({ keystone, create, findOne, findById }) => { const groupName = sampleOne(gen.alphaNumString.notEmpty()); // Create an item to link against @@ -315,8 +315,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => expect(eventModel.id).toBeTruthy(); // Update the item and link the relationship field - const { data, errors } = await networkedGraphqlRequest({ - app, + const { data, errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { updateEventTo${group.name}( @@ -360,7 +360,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => } else { test( 'throws error when linking nested within update mutation', - runner(setupKeystone, async ({ app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { const groupName = sampleOne(gen.alphaNumString.notEmpty()); // Create an item to link against @@ -372,8 +372,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => expect(eventModel.id).toBeTruthy(); // Update the item and link the relationship field - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { updateEventTo${group.name}( @@ -388,24 +388,19 @@ multiAdapterRunners().map(({ runner, adapterName }) => } `, }); - - expect(errors).toMatchObject([ - { - data: { - errors: expect.arrayContaining([ - expect.objectContaining({ - message: `Unable to connect a EventTo${group.name}.group<${group.name}>`, - }), - ]), - }, - }, - ]); + expect(errors).toHaveLength(1); + const error = errors[0]; + expect(error.message).toEqual( + `Unable to connect a EventTo${group.name}.group<${group.name}>` + ); + expect(error.path).toHaveLength(1); + expect(error.path[0]).toEqual(`updateEventTo${group.name}`); }) ); test( 'throws error when linking nested within create mutation', - runner(setupKeystone, async ({ app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { const groupName = sampleOne(gen.alphaNumString.notEmpty()); // Create an item to link against @@ -413,8 +408,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => expect(id).toBeTruthy(); // Create an item that does the linking - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { createEventTo${group.name}(data: { @@ -426,18 +421,13 @@ multiAdapterRunners().map(({ runner, adapterName }) => } `, }); - - expect(errors).toMatchObject([ - { - data: { - errors: expect.arrayContaining([ - expect.objectContaining({ - message: `Unable to connect a EventTo${group.name}.group<${group.name}>`, - }), - ]), - }, - }, - ]); + expect(errors).toHaveLength(1); + const error = errors[0]; + expect(error.message).toEqual( + `Unable to connect a EventTo${group.name}.group<${group.name}>` + ); + expect(error.path).toHaveLength(1); + expect(error.path[0]).toEqual(`createEventTo${group.name}`); }) ); } diff --git a/api-tests/relationships/nested-mutations/create-and-connect-many.test.js b/api-tests/relationships/nested-mutations/create-and-connect-many.test.js index 2c999a56812..4eab82403d1 100644 --- a/api-tests/relationships/nested-mutations/create-and-connect-many.test.js +++ b/api-tests/relationships/nested-mutations/create-and-connect-many.test.js @@ -4,7 +4,7 @@ const { multiAdapterRunners, setupServer, graphqlRequest, - networkedGraphqlRequest, + authedGraphqlRequest, } = require('@keystonejs/test-utils'); const alphanumGenerator = gen.alphaNumString.notEmpty(); @@ -231,7 +231,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => describe('read: false on related list', () => { test( 'throws when link AND create nested from within create mutation', - runner(setupKeystone, async ({ app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { const noteContent = sampleOne(alphanumGenerator); const noteContent2 = sampleOne(alphanumGenerator); @@ -241,8 +241,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => }); // Create an item that does the linking - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { createUserToNotesNoRead(data: { @@ -258,24 +258,19 @@ multiAdapterRunners().map(({ runner, adapterName }) => `, }); - expect(errors).toMatchObject([ - { - data: { - errors: expect.arrayContaining([ - expect.objectContaining({ - message: - 'Unable to create and/or connect 1 UserToNotesNoRead.notes', - }), - ]), - }, - }, - ]); + expect(errors).toHaveLength(1); + const error = errors[0]; + expect(error.message).toEqual( + 'Unable to create and/or connect 1 UserToNotesNoRead.notes' + ); + expect(error.path).toHaveLength(1); + expect(error.path[0]).toEqual('createUserToNotesNoRead'); }) ); test( 'throws when link & create nested from within update mutation', - runner(setupKeystone, async ({ app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { const noteContent = sampleOne(alphanumGenerator); const noteContent2 = sampleOne(alphanumGenerator); @@ -288,8 +283,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => }); // Update the item and link the relationship field - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { updateUserToNotesNoRead( @@ -308,18 +303,13 @@ multiAdapterRunners().map(({ runner, adapterName }) => `, }); - expect(errors).toMatchObject([ - { - data: { - errors: expect.arrayContaining([ - expect.objectContaining({ - message: - 'Unable to create and/or connect 1 UserToNotesNoRead.notes', - }), - ]), - }, - }, - ]); + expect(errors).toHaveLength(1); + const error = errors[0]; + expect(error.message).toEqual( + 'Unable to create and/or connect 1 UserToNotesNoRead.notes' + ); + expect(error.path).toHaveLength(1); + expect(error.path[0]).toEqual('updateUserToNotesNoRead'); }) ); }); diff --git a/api-tests/relationships/nested-mutations/create-many.test.js b/api-tests/relationships/nested-mutations/create-many.test.js index 6209bf37faa..494517402dd 100644 --- a/api-tests/relationships/nested-mutations/create-many.test.js +++ b/api-tests/relationships/nested-mutations/create-many.test.js @@ -4,7 +4,7 @@ const { multiAdapterRunners, setupServer, graphqlRequest, - networkedGraphqlRequest, + authedGraphqlRequest, } = require('@keystonejs/test-utils'); const alphanumGenerator = gen.alphaNumString.notEmpty(); @@ -298,12 +298,12 @@ multiAdapterRunners().map(({ runner, adapterName }) => describe('read: false on related list', () => { test( 'throws when trying to read after nested create', - runner(setupKeystone, async ({ app }) => { + runner(setupKeystone, async ({ keystone }) => { const noteContent = sampleOne(alphanumGenerator); // Create an item that does the nested create - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { createUserToNotesNoRead(data: { @@ -319,22 +319,23 @@ multiAdapterRunners().map(({ runner, adapterName }) => `, }); - expect(errors).toMatchObject([ - { - message: 'You do not have access to this resource', - }, - ]); + expect(errors).toHaveLength(1); + const error = errors[0]; + expect(error.message).toEqual('You do not have access to this resource'); + expect(error.path).toHaveLength(2); + expect(error.path[0]).toEqual('createUserToNotesNoRead'); + expect(error.path[1]).toEqual('notes'); }) ); test( 'does not throw when create nested from within create mutation', - runner(setupKeystone, async ({ app }) => { + runner(setupKeystone, async ({ keystone }) => { const noteContent = sampleOne(alphanumGenerator); // Create an item that does the nested create - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { createUserToNotesNoRead(data: { @@ -353,7 +354,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => test( 'does not throw when create nested from within update mutation', - runner(setupKeystone, async ({ app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { const noteContent = sampleOne(alphanumGenerator); // Create an item to update @@ -362,8 +363,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => }); // Update an item that does the nested create - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { updateUserToNotesNoRead( @@ -387,13 +388,13 @@ multiAdapterRunners().map(({ runner, adapterName }) => describe('create: false on related list', () => { test( 'throws error when creating nested within create mutation', - runner(setupKeystone, async ({ keystone, app }) => { + runner(setupKeystone, async ({ keystone }) => { const userName = sampleOne(alphanumGenerator); const noteContent = sampleOne(alphanumGenerator); // Create an item that does the nested create - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { createUserToNotesNoCreate(data: { @@ -407,19 +408,13 @@ multiAdapterRunners().map(({ runner, adapterName }) => }); // Assert it throws an access denied error - - expect(errors).toMatchObject([ - { - data: { - errors: expect.arrayContaining([ - expect.objectContaining({ - message: - 'Unable to create and/or connect 1 UserToNotesNoCreate.notes', - }), - ]), - }, - }, - ]); + expect(errors).toHaveLength(1); + const error = errors[0]; + expect(error.message).toEqual( + 'Unable to create and/or connect 1 UserToNotesNoCreate.notes' + ); + expect(error.path).toHaveLength(1); + expect(error.path[0]).toEqual('createUserToNotesNoCreate'); // Confirm it didn't insert either of the records anyway const { @@ -448,7 +443,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => test( 'throws error when creating nested within update mutation', - runner(setupKeystone, async ({ keystone, app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { const noteContent = sampleOne(alphanumGenerator); // Create an item to update @@ -457,8 +452,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => }); // Update an item that does the nested create - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { updateUserToNotesNoCreate( @@ -475,18 +470,13 @@ multiAdapterRunners().map(({ runner, adapterName }) => }); // Assert it throws an access denied error - expect(errors).toMatchObject([ - { - data: { - errors: expect.arrayContaining([ - expect.objectContaining({ - message: - 'Unable to create and/or connect 1 UserToNotesNoCreate.notes', - }), - ]), - }, - }, - ]); + expect(errors).toHaveLength(1); + const error = errors[0]; + expect(error.message).toEqual( + 'Unable to create and/or connect 1 UserToNotesNoCreate.notes' + ); + expect(error.path).toHaveLength(1); + expect(error.path[0]).toEqual('updateUserToNotesNoCreate'); // Confirm it didn't insert the record anyway const { diff --git a/api-tests/relationships/nested-mutations/create-singular.test.js b/api-tests/relationships/nested-mutations/create-singular.test.js index b24bdfe265f..5a55d135189 100644 --- a/api-tests/relationships/nested-mutations/create-singular.test.js +++ b/api-tests/relationships/nested-mutations/create-singular.test.js @@ -4,7 +4,7 @@ const { multiAdapterRunners, setupServer, graphqlRequest, - networkedGraphqlRequest, + authedGraphqlRequest, } = require('@keystonejs/test-utils'); function setupKeystone(adapterName) { @@ -243,12 +243,12 @@ multiAdapterRunners().map(({ runner, adapterName }) => if (group.allowed) { test( 'does not throw error when creating nested within create mutation', - runner(setupKeystone, async ({ app, findOne, findById }) => { + runner(setupKeystone, async ({ keystone, findOne, findById }) => { const groupName = sampleOne(gen.alphaNumString.notEmpty()); // Create an item that does the nested create - const { data, errors } = await networkedGraphqlRequest({ - app, + const { data, errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { createEventTo${group.name}(data: { @@ -279,15 +279,15 @@ multiAdapterRunners().map(({ runner, adapterName }) => test( 'does not throw error when creating nested within update mutation', - runner(setupKeystone, async ({ app, create, findOne, findById }) => { + runner(setupKeystone, async ({ keystone, create, findOne, findById }) => { const groupName = sampleOne(gen.alphaNumString.notEmpty()); // Create an item to update const eventModel = await create(`EventTo${group.name}`, { title: 'A thing' }); // Update an item that does the nested create - const { data, errors } = await networkedGraphqlRequest({ - app, + const { data, errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { updateEventTo${group.name}( @@ -321,14 +321,14 @@ multiAdapterRunners().map(({ runner, adapterName }) => } else { test( 'throws error when creating nested within create mutation', - runner(setupKeystone, async ({ keystone, app }) => { + runner(setupKeystone, async ({ keystone }) => { const alphaNumGenerator = gen.alphaNumString.notEmpty(); const eventName = sampleOne(alphaNumGenerator); const groupName = sampleOne(alphaNumGenerator); // Create an item that does the nested create - const { data, errors } = await networkedGraphqlRequest({ - app, + const { data, errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { createEventTo${group.name}(data: { @@ -344,21 +344,17 @@ multiAdapterRunners().map(({ runner, adapterName }) => if (group.name === 'GroupNoCreateHard') { // For { create: false } the mutation won't even exist, so we expect a different behaviour - expect(data).toBe(undefined); + expect(data[`createEventTo${group.name}`]).toBe(null); } else { // Assert it throws an access denied error expect(data[`createEventTo${group.name}`]).toBe(null); - expect(errors).toMatchObject([ - { - data: { - errors: expect.arrayContaining([ - expect.objectContaining({ - message: `Unable to create a EventTo${group.name}.group<${group.name}>`, - }), - ]), - }, - }, - ]); + expect(errors).toHaveLength(1); + const error = errors[0]; + expect(error.message).toEqual( + `Unable to create a EventTo${group.name}.group<${group.name}>` + ); + expect(error.path).toHaveLength(1); + expect(error.path[0]).toEqual(`createEventTo${group.name}`); } // Confirm it didn't insert either of the records anyway const result = await graphqlRequest({ @@ -394,15 +390,15 @@ multiAdapterRunners().map(({ runner, adapterName }) => test( 'throws error when creating nested within update mutation', - runner(setupKeystone, async ({ keystone, app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { const groupName = sampleOne(gen.alphaNumString.notEmpty()); // Create an item to update const eventModel = await create(`EventTo${group.name}`, { title: 'A thing' }); // Update an item that does the nested create - const { data, errors } = await networkedGraphqlRequest({ - app, + const { data, errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { updateEventTo${group.name}( @@ -422,20 +418,16 @@ multiAdapterRunners().map(({ runner, adapterName }) => // Assert it throws an access denied error if (group.name === 'GroupNoCreateHard') { // For { create: false } the mutation won't even exist, so we expect a different behaviour - expect(data).toBe(undefined); + expect(data[`updateEventTo${group.name}`]).toBe(null); } else { expect(data[`updateEventTo${group.name}`]).toBe(null); - expect(errors).toMatchObject([ - { - data: { - errors: expect.arrayContaining([ - expect.objectContaining({ - message: `Unable to create a EventTo${group.name}.group<${group.name}>`, - }), - ]), - }, - }, - ]); + expect(errors).toHaveLength(1); + const error = errors[0]; + expect(error.message).toEqual( + `Unable to create a EventTo${group.name}.group<${group.name}>` + ); + expect(error.path).toHaveLength(1); + expect(error.path[0]).toEqual(`updateEventTo${group.name}`); } // Confirm it didn't insert the record anyway diff --git a/api-tests/relationships/nested-mutations/disconnect-all-many.test.js b/api-tests/relationships/nested-mutations/disconnect-all-many.test.js index ff7acf2e1b2..e542d6cda2b 100644 --- a/api-tests/relationships/nested-mutations/disconnect-all-many.test.js +++ b/api-tests/relationships/nested-mutations/disconnect-all-many.test.js @@ -4,7 +4,7 @@ const { setupServer, graphqlRequest, multiAdapterRunners, - networkedGraphqlRequest, + authedGraphqlRequest, } = require('@keystonejs/test-utils'); const alphanumGenerator = gen.alphaNumString.notEmpty(); @@ -147,7 +147,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => describe('read: false on related list', () => { test( 'has no effect when specifying disconnectAll', - runner(setupKeystone, async ({ keystone, app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { const noteContent = sampleOne(alphanumGenerator); // Create an item to link against @@ -160,8 +160,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => }); // Update the item and link the relationship field - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { updateUserToNotesNoRead( diff --git a/api-tests/relationships/nested-mutations/disconnect-all-singular.test.js b/api-tests/relationships/nested-mutations/disconnect-all-singular.test.js index b56a102b45c..fb1c452aeca 100644 --- a/api-tests/relationships/nested-mutations/disconnect-all-singular.test.js +++ b/api-tests/relationships/nested-mutations/disconnect-all-singular.test.js @@ -4,7 +4,7 @@ const { multiAdapterRunners, setupServer, graphqlRequest, - networkedGraphqlRequest, + authedGraphqlRequest, } = require('@keystonejs/test-utils'); const alphanumGenerator = gen.alphaNumString.notEmpty(); @@ -170,7 +170,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => describe('read: false on related list', () => { test( 'has no effect when using disconnectAll', - runner(setupKeystone, async ({ app, create, findById }) => { + runner(setupKeystone, async ({ keystone, create, findById }) => { const groupName = sampleOne(alphanumGenerator); // Create an item to link against @@ -186,8 +186,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => expect(createEvent.group.toString()).toBe(createGroup.id); // Update the item and link the relationship field - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { updateEventToGroupNoRead( diff --git a/api-tests/relationships/nested-mutations/disconnect-many.test.js b/api-tests/relationships/nested-mutations/disconnect-many.test.js index 61fcf2249ff..0e8f96f1b34 100644 --- a/api-tests/relationships/nested-mutations/disconnect-many.test.js +++ b/api-tests/relationships/nested-mutations/disconnect-many.test.js @@ -4,7 +4,7 @@ const { multiAdapterRunners, setupServer, graphqlRequest, - networkedGraphqlRequest, + authedGraphqlRequest, } = require('@keystonejs/test-utils'); const alphanumGenerator = gen.alphaNumString.notEmpty(); @@ -247,7 +247,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => describe('read: false on related list', () => { test( 'has no impact when disconnecting directly with an id', - runner(setupKeystone, async ({ keystone, app, create }) => { + runner(setupKeystone, async ({ keystone, create }) => { const noteContent = sampleOne(alphanumGenerator); // Create an item to link against @@ -260,8 +260,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => }); // Update the item and link the relationship field - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { updateUserToNotesNoRead( diff --git a/api-tests/relationships/nested-mutations/disconnect-singular.test.js b/api-tests/relationships/nested-mutations/disconnect-singular.test.js index 6ca3ad9951a..127bdaa8dd0 100644 --- a/api-tests/relationships/nested-mutations/disconnect-singular.test.js +++ b/api-tests/relationships/nested-mutations/disconnect-singular.test.js @@ -4,7 +4,7 @@ const { multiAdapterRunners, setupServer, graphqlRequest, - networkedGraphqlRequest, + authedGraphqlRequest, } = require('@keystonejs/test-utils'); const alphanumGenerator = gen.alphaNumString.notEmpty(); @@ -215,7 +215,7 @@ multiAdapterRunners().map(({ runner, adapterName }) => describe('read: false on related list', () => { test( 'has no effect when disconnecting a specific id', - runner(setupKeystone, async ({ app, create, findById }) => { + runner(setupKeystone, async ({ keystone, create, findById }) => { const groupName = sampleOne(alphanumGenerator); // Create an item to link against @@ -231,8 +231,8 @@ multiAdapterRunners().map(({ runner, adapterName }) => expect(createEvent.group.toString()).toBe(createGroup.id); // Update the item and link the relationship field - const { errors } = await networkedGraphqlRequest({ - app, + const { errors } = await authedGraphqlRequest({ + keystone, query: ` mutation { updateEventToGroupNoRead(