Skip to content

Commit

Permalink
Use authedGraphqlRequest rather than networkedGraphqlRequest where ap…
Browse files Browse the repository at this point in the history
…propriate (#3310)
  • Loading branch information
timleslie authored Jul 30, 2020
1 parent 22b4a5c commit cefbca4
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 215 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-bags-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystonejs/api-tests': patch
---

Use `authedGraphqlRequest` rather than `networkedGraphqlRequest` where appropriate.
8 changes: 4 additions & 4 deletions api-tests/extend-graphql-schema/extend-graphql-schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {
multiAdapterRunners,
setupServer,
graphqlRequest,
networkedGraphqlRequest,
authedGraphqlRequest,
} = require('@keystonejs/test-utils');

const falseFn = () => false;
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions api-tests/relationships/filtering/access-control.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { Text, Relationship } = require('@keystonejs/fields');
const {
multiAdapterRunners,
setupServer,
networkedGraphqlRequest,
authedGraphqlRequest,
} = require('@keystonejs/test-utils');

const alphanumGenerator = gen.alphaNumString.notEmpty();
Expand Down Expand Up @@ -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 => {
Expand All @@ -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}" }) {
Expand All @@ -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 => {
Expand All @@ -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}" }) {
Expand Down
64 changes: 27 additions & 37 deletions api-tests/relationships/nested-mutations/connect-many.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
multiAdapterRunners,
setupServer,
graphqlRequest,
networkedGraphqlRequest,
authedGraphqlRequest,
} = require('@keystonejs/test-utils');

const alphanumGenerator = gen.alphaNumString.notEmpty();
Expand Down Expand Up @@ -446,16 +446,16 @@ 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
const createNoteNoRead = await create('NoteNoRead', {
content: noteContent,
});

const { errors } = await networkedGraphqlRequest({
app,
const { errors } = await authedGraphqlRequest({
keystone,
query: `
mutation {
createUserToNotesNoRead(data: {
Expand All @@ -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<NoteNoRead>',
}),
]),
},
},
]);
expect(errors).toHaveLength(1);
const error = errors[0];
expect(error.message).toEqual(
'Unable to create and/or connect 1 UserToNotesNoRead.notes<NoteNoRead>'
);
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
Expand All @@ -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(
Expand All @@ -514,26 +509,21 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
`,
});

expect(errors).toMatchObject([
{
data: {
errors: expect.arrayContaining([
expect.objectContaining({
message:
'Unable to create and/or connect 1 UserToNotesNoRead.notes<NoteNoRead>',
}),
]),
},
},
]);
expect(errors).toHaveLength(1);
const error = errors[0];
expect(error.message).toEqual(
'Unable to create and/or connect 1 UserToNotesNoRead.notes<NoteNoRead>'
);
expect(error.path).toHaveLength(1);
expect(error.path[0]).toEqual('updateUserToNotesNoRead');
})
);
});

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
Expand All @@ -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: {
Expand All @@ -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
Expand All @@ -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(
Expand Down
64 changes: 27 additions & 37 deletions api-tests/relationships/nested-mutations/connect-singular.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
multiAdapterRunners,
setupServer,
graphqlRequest,
networkedGraphqlRequest,
authedGraphqlRequest,
} = require('@keystonejs/test-utils');

function setupKeystone(adapterName) {
Expand Down Expand Up @@ -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
Expand All @@ -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: {
Expand All @@ -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
Expand All @@ -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}(
Expand Down Expand Up @@ -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
Expand All @@ -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}(
Expand All @@ -388,33 +388,28 @@ 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
const { id } = await create(group.name, { name: groupName });
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: {
Expand All @@ -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}`);
})
);
}
Expand Down
Loading

0 comments on commit cefbca4

Please sign in to comment.