Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-order tests #3033

Merged
merged 1 commit into from
May 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,11 @@ We also build commonjs builds to run in node (for testing with jest or etc.) and
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->

<!-- prettier-ignore-start -->

<!-- markdownlint-disable -->

<table>
<tr>
<td align="center"><a href="http://www.thinkmill.com.au"><img src="https://avatars3.githubusercontent.com/u/872310?v=4" width="80px;" alt=""/><br /><sub><b>Jed Watson</b></sub></a><br /><a href="https://github.com/keystonejs/keystone/commits?author=JedWatson" title="Code">💻</a></td>
Expand Down Expand Up @@ -339,7 +342,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
</table>

<!-- markdownlint-enable -->

<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ We'd like to start by thanking all our wonderful contributors:
([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->

<!-- prettier-ignore-start -->

<!-- markdownlint-disable -->

<table>
<tr>
<td align="center"><a href="http://www.thinkmill.com.au"><img src="https://avatars3.githubusercontent.com/u/872310?v=4" width="80px;" alt=""/><br /><sub><b>Jed Watson</b></sub></a><br /><a href="https://github.com/keystonejs/keystone/commits?author=JedWatson" title="Code">💻</a></td>
Expand Down Expand Up @@ -141,7 +144,9 @@ We'd like to start by thanking all our wonderful contributors:
</table>

<!-- markdownlint-enable -->

<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

### Demo Projects
Expand Down
258 changes: 127 additions & 131 deletions api-tests/relationships/nested-mutations/connect-singular.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,62 +210,58 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
});

describe('with access control', () => {
[{ name: 'GroupNoRead', func: 'read: () => false' }].forEach(group => {
[{ name: 'GroupNoRead', allowed: false, func: 'read: () => false' }].forEach(group => {
describe(`${group.func} on related list`, () => {
test(
'throws error when linking nested within create mutation',
runner(setupKeystone, async ({ app, create }) => {
const groupName = sampleOne(gen.alphaNumString.notEmpty());

// Create an item to link against
const { id } = await create(group.name, { name: groupName });

// Create an item that does the linking
const { errors } = await networkedGraphqlRequest({
app,
query: `
if (group.allowed) {
test(
'does not throw error when linking nested within create mutation',
runner(setupKeystone, async ({ app, create }) => {
const groupName = sampleOne(gen.alphaNumString.notEmpty());

// Create an item to link against
// We can't use the graphQL query here (it's `create: () => false`)
const { id } = await create(group.name, { name: groupName });

// Create an item that does the linking
const { data, errors } = await networkedGraphqlRequest({
app,
query: `
mutation {
createEventTo${group.name}(data: {
title: "A thing",
group: { connect: { id: "${id}" } }
}) {
id
group {
id
}
}
}
`,
});

expect(errors).toMatchObject([
{
data: {
errors: expect.arrayContaining([
expect.objectContaining({
message: `Unable to connect a EventTo${group.name}.group<${group.name}>`,
}),
]),
},
},
]);
})
);

test(
'does not throw error when linking nested within update mutation',
runner(setupKeystone, async ({ app, create }) => {
const groupName = sampleOne(gen.alphaNumString.notEmpty());

// Create an item to link against
const groupModel = await create(group.name, { name: groupName });
expect(groupModel.id).toBeTruthy();

// Create an item to update
const eventModel = await create(`EventTo${group.name}`, { title: 'A thing' });
expect(eventModel.id).toBeTruthy();

// Update the item and link the relationship field
const { errors } = await networkedGraphqlRequest({
app,
query: `
});

expect(data).toMatchObject({
[`createEventTo${group.name}`]: { id: expect.any(String), group: { id } },
});
expect(errors).toBe(undefined);
})
);
test(
'does not throw error when linking nested within update mutation',
runner(setupKeystone, async ({ app, create, findOne, findById }) => {
const groupName = sampleOne(gen.alphaNumString.notEmpty());

// Create an item to link against
const groupModel = await create(group.name, { name: groupName });

// Create an item to update
const eventModel = await create(`EventTo${group.name}`, { title: 'A Thing' });
expect(eventModel.id).toBeTruthy();

// Update the item and link the relationship field
const { data, errors } = await networkedGraphqlRequest({
app,
query: `
mutation {
updateEventTo${group.name}(
id: "${eventModel.id}"
Expand All @@ -275,79 +271,90 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
}
) {
id
group {
id
name
}
}
}
`,
});

expect(errors).toMatchObject([
{
data: {
errors: expect.arrayContaining([
expect.objectContaining({
message: `Unable to connect a EventTo${group.name}.group<${group.name}>`,
}),
]),
},
},
]);
})
);
});
});
});

[{ name: 'GroupNoCreate', func: 'create: () => false' }].forEach(group => {
describe(`${group.func} on related list`, () => {
test(
'does not throw error when linking nested within create mutation',
runner(setupKeystone, async ({ app, create }) => {
const groupName = sampleOne(gen.alphaNumString.notEmpty());

// Create an item to link against
// We can't use the graphQL query here (it's `create: () => false`)
const { id } = await create(group.name, { name: groupName });

// Create an item that does the linking
const { data, errors } = await networkedGraphqlRequest({
app,
query: `
expect(data).toMatchObject({
[`updateEventTo${group.name}`]: {
id: expect.any(String),
group: {
id: expect.any(String),
name: groupName,
},
},
});
expect(errors).toBe(undefined);

// See that it actually stored the group ID on the Event record
const event = await findOne(`EventTo${group.name}`, { title: 'A thing' });
expect(event).toBeTruthy();
expect(event.group).toBeTruthy();

const _group = await findById(group.name, event.group);
expect(_group).toBeTruthy();
expect(_group.name).toBe(groupName);
})
);
} else {
test(
'throws error when linking nested within create mutation',
runner(setupKeystone, async ({ app, create }) => {
const groupName = sampleOne(gen.alphaNumString.notEmpty());

// Create an item to link against
const { id } = await create(group.name, { name: groupName });

// Create an item that does the linking
const { errors } = await networkedGraphqlRequest({
app,
query: `
mutation {
createEventTo${group.name}(data: {
title: "A thing",
group: { connect: { id: "${id}" } }
}) {
id
group {
id
}
}
}
`,
});

expect(data).toMatchObject({
[`createEventTo${group.name}`]: { id: expect.any(String), group: { id } },
});
expect(errors).toBe(undefined);
})
);

test(
'does not throw error when linking nested within update mutation',
runner(setupKeystone, async ({ app, create, findOne, findById }) => {
const groupName = sampleOne(gen.alphaNumString.notEmpty());

// Create an item to link against
// We can't use the graphQL query here (it's `create: () => false`)
const groupModel = await create(group.name, { name: groupName });

// Create an item to update
const eventModel = await create(`EventTo${group.name}`, { title: 'A Thing' });

// Update the item and link the relationship field
const { data, errors } = await networkedGraphqlRequest({
app,
query: `
});

expect(errors).toMatchObject([
{
data: {
errors: expect.arrayContaining([
expect.objectContaining({
message: `Unable to connect a EventTo${group.name}.group<${group.name}>`,
}),
]),
},
},
]);
})
);
test(
'throws error when linking nested within update mutation',
runner(setupKeystone, async ({ app, create }) => {
const groupName = sampleOne(gen.alphaNumString.notEmpty());

// Create an item to link against
const groupModel = await create(group.name, { name: groupName });
expect(groupModel.id).toBeTruthy();

// Create an item to update
const eventModel = await create(`EventTo${group.name}`, { title: 'A thing' });
expect(eventModel.id).toBeTruthy();

// Update the item and link the relationship field
const { errors } = await networkedGraphqlRequest({
app,
query: `
mutation {
updateEventTo${group.name}(
id: "${eventModel.id}"
Expand All @@ -357,36 +364,25 @@ multiAdapterRunners().map(({ runner, adapterName }) =>
}
) {
id
group {
id
name
}
}
}
`,
});
});

expect(data).toMatchObject({
[`updateEventTo${group.name}`]: {
id: expect.any(String),
group: {
id: expect.any(String),
name: groupName,
expect(errors).toMatchObject([
{
data: {
errors: expect.arrayContaining([
expect.objectContaining({
message: `Unable to connect a EventTo${group.name}.group<${group.name}>`,
}),
]),
},
},
},
});
expect(errors).toBe(undefined);

// See that it actually stored the group ID on the Event record
const event = await findOne(`EventTo${group.name}`, { title: 'A thing' });
expect(event).toBeTruthy();
expect(event.group).toBeTruthy();

const _group = await findById(group.name, event.group);
expect(_group).toBeTruthy();
expect(_group.name).toBe(groupName);
})
);
]);
})
);
}
});
});
});
Expand Down
Loading