Skip to content

Commit

Permalink
Update tests, fix minor bugs (#5714)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored May 14, 2021
1 parent 65c241f commit 5c00d7c
Show file tree
Hide file tree
Showing 22 changed files with 237 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ const createItems = async ({
returnFields?: string;
context: KeystoneContext;
}) => {
const { createManyMutationName, createManyInputName } = context.gqlNames(listKey);
const { createManyMutationName, createInputName } = context.gqlNames(listKey);

const query = `mutation ($items: [${createManyInputName}!]!){
const query = `mutation ($items: [${createInputName}!]!){
${createManyMutationName}(data: $items) { ${returnFields} }
}`;

Expand Down
4 changes: 2 additions & 2 deletions packages-next/keystone/src/lib/core/types-for-lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,15 @@ export function initialiseLists(
};

const relateToOneForCreate = types.inputObject({
name: `${listKey}RelateToManyForCreateInput`,
name: `${listKey}RelateToOneForCreateInput`,
fields: relateToOneForCreateFields,
});

// this is a seperate type because:
// - in the future, this should contain delete
// - setting relateToOneForCreate to null is not allowed, setting relateToOneForUpdate disconnects
const relateToOneForUpdate = types.inputObject({
name: `${listKey}RelateToManyForUpdateInput`,
name: `${listKey}RelateToOneForUpdateInput`,
fields: relateToOneForCreateFields,
});

Expand Down
6 changes: 1 addition & 5 deletions packages-next/types/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ export type KeystoneListsAPI<KeystoneListsTypeInfo extends Record<string, BaseGe
args: { readonly data: KeystoneListsTypeInfo[Key]['inputs']['create'] } & ResolveFields
): Promise<Record<string, any>>;
createMany(
args: {
readonly data: readonly {
readonly data: KeystoneListsTypeInfo[Key]['inputs']['update'];
}[];
} & ResolveFields
args: { readonly data: KeystoneListsTypeInfo[Key]['inputs']['create'][] } & ResolveFields
): Promise<Record<string, any>[]>;
deleteOne(args: { readonly id: string } & ResolveFields): Promise<Record<string, any> | null>;
deleteMany(
Expand Down
2 changes: 1 addition & 1 deletion tests/api-tests/access-control/authed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ multiAdapterRunners().map(({ before, after, provider }) =>
items = {};
for (const [listKey, _items] of Object.entries(initialData)) {
items[listKey] = (await context.lists[listKey].createMany({
data: _items.map(x => ({ data: x })),
data: _items,
query: 'id name',
})) as { id: IdType; name: string }[];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/api-tests/access-control/not-authed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ multiAdapterRunners().map(({ before, after, provider }) =>
items = {};
for (const [listKey, _items] of Object.entries(initialData)) {
items[listKey] = (await context.lists[listKey].createMany({
data: _items.map(x => ({ data: x })),
data: _items,
query: 'id, name',
})) as { id: IdType; name: string }[];
}
Expand Down
8 changes: 4 additions & 4 deletions tests/api-tests/access-control/updateMany.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ multiAdapterRunners().map(({ runner, provider }) =>
// Create some items, half of which have `isUpdatable: true`
const users = (await context.lists.User.createMany({
data: [
{ data: { name: 'Jess', isUpdatable: true } },
{ data: { name: 'Johanna', isUpdatable: false } },
{ data: { name: 'Sam', isUpdatable: true } },
{ data: { name: 'Theo', isUpdatable: false } },
{ name: 'Jess', isUpdatable: true },
{ name: 'Johanna', isUpdatable: false },
{ name: 'Sam', isUpdatable: true },
{ name: 'Theo', isUpdatable: false },
],
})) as { id: any }[];
// Attempt to update all four items
Expand Down
16 changes: 2 additions & 14 deletions tests/api-tests/auth-header.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,8 @@ import type { KeystoneContext, KeystoneConfig } from '@keystone-next/types';

const initialData = {
User: [
{
data: {
name: 'Boris Bozic',
email: 'boris@keystone.com',
password: 'correctbattery',
},
},
{
data: {
name: 'Jed Watson',
email: 'jed@keystone.com',
password: 'horsestaple',
},
},
{ name: 'Boris Bozic', email: 'boris@keystone.com', password: 'correctbattery' },
{ name: 'Jed Watson', email: 'jed@keystone.com', password: 'horsestaple' },
],
};

Expand Down
21 changes: 7 additions & 14 deletions tests/api-tests/queries/cache-hints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,19 @@ function setupKeystone(provider: ProviderName) {
const addFixtures = async (context: KeystoneContext) => {
const users = await context.lists.User.createMany({
data: [
{ data: { name: 'Jess', favNumber: 1 } },
{ data: { name: 'Johanna', favNumber: 8 } },
{ data: { name: 'Sam', favNumber: 5 } },
{ name: 'Jess', favNumber: 1 },
{ name: 'Johanna', favNumber: 8 },
{ name: 'Sam', favNumber: 5 },
],
});

const posts = await context.lists.Post.createMany({
data: [
{ data: { author: { connect: [{ id: users[0].id }] }, title: 'One author' } },
{ author: { connect: [{ id: users[0].id }] }, title: 'One author' },
{ author: { connect: [{ id: users[0].id }, { id: users[1].id }] }, title: 'Two authors' },
{
data: {
author: { connect: [{ id: users[0].id }, { id: users[1].id }] },
title: 'Two authors',
},
},
{
data: {
author: { connect: [{ id: users[0].id }, { id: users[1].id }, { id: users[2].id }] },
title: 'Three authors',
},
author: { connect: [{ id: users[0].id }, { id: users[1].id }, { id: users[2].id }] },
title: 'Three authors',
},
],
});
Expand Down
30 changes: 13 additions & 17 deletions tests/api-tests/queries/limits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ multiAdapterRunners().map(({ runner, provider }) =>
runner(setupKeystone, async ({ context }) => {
const users = await context.lists.User.createMany({
data: [
{ data: { name: 'Jess', favNumber: 1 } },
{ data: { name: 'Johanna', favNumber: 8 } },
{ data: { name: 'Sam', favNumber: 5 } },
{ data: { name: 'Theo', favNumber: 2 } },
{ name: 'Jess', favNumber: 1 },
{ name: 'Johanna', favNumber: 8 },
{ name: 'Sam', favNumber: 5 },
{ name: 'Theo', favNumber: 2 },
],
});

Expand Down Expand Up @@ -159,27 +159,23 @@ multiAdapterRunners().map(({ runner, provider }) =>
runner(setupKeystone, async ({ context }) => {
const users = await context.lists.User.createMany({
data: [
{ data: { name: 'Jess', favNumber: 1 } },
{ data: { name: 'Johanna', favNumber: 8 } },
{ data: { name: 'Sam', favNumber: 5 } },
{ name: 'Jess', favNumber: 1 },
{ name: 'Johanna', favNumber: 8 },
{ name: 'Sam', favNumber: 5 },
],
});
await context.lists.Post.createMany({
data: [
{ data: { author: { connect: [{ id: users[0].id }] }, title: 'One author' } },
{ author: { connect: [{ id: users[0].id }] }, title: 'One author' },
{
data: {
author: { connect: [{ id: users[0].id }, { id: users[1].id }] },
title: 'Two authors',
},
author: { connect: [{ id: users[0].id }, { id: users[1].id }] },
title: 'Two authors',
},
{
data: {
author: {
connect: [{ id: users[0].id }, { id: users[1].id }, { id: users[2].id }],
},
title: 'Three authors',
author: {
connect: [{ id: users[0].id }, { id: users[1].id }, { id: users[2].id }],
},
title: 'Three authors',
},
],
});
Expand Down
43 changes: 7 additions & 36 deletions tests/api-tests/queries/relationships.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,14 @@ multiAdapterRunners().map(({ runner, provider }) =>
runner(setupKeystone, async ({ context }) => {
// Create an item to link against
const users = await context.lists.User.createMany({
data: [
{ data: { name: 'Jess' } },
{ data: { name: 'Johanna' } },
{ data: { name: 'Sam' } },
],
data: [{ name: 'Jess' }, { name: 'Johanna' }, { name: 'Sam' }],
});
const posts = await context.lists.Post.createMany({
data: [
{
data: {
author: { connect: { id: users[0].id } },
title: sampleOne(alphanumGenerator),
},
},
{
data: {
author: { connect: { id: users[1].id } },
title: sampleOne(alphanumGenerator),
},
},
{
data: {
author: { connect: { id: users[2].id } },
title: sampleOne(alphanumGenerator),
},
},
{
data: {
author: { connect: { id: users[0].id } },
title: sampleOne(alphanumGenerator),
},
},
{ author: { connect: { id: users[0].id } }, title: sampleOne(alphanumGenerator) },
{ author: { connect: { id: users[1].id } }, title: sampleOne(alphanumGenerator) },
{ author: { connect: { id: users[2].id } }, title: sampleOne(alphanumGenerator) },
{ author: { connect: { id: users[0].id } }, title: sampleOne(alphanumGenerator) },
],
query: 'id title',
});
Expand All @@ -99,13 +75,8 @@ multiAdapterRunners().map(({ runner, provider }) =>
const user = await context.lists.User.createOne({ data: { name: 'Jess' } });
const posts = await context.lists.Post.createMany({
data: [
{
data: {
author: { connect: { id: user.id } },
title: sampleOne(alphanumGenerator),
},
},
{ data: { title: sampleOne(alphanumGenerator) } },
{ author: { connect: { id: user.id } }, title: sampleOne(alphanumGenerator) },
{ title: sampleOne(alphanumGenerator) },
],
query: 'id title',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ const alphanumGenerator = gen.alphaNumString.notEmpty();
const createInitialData = async (context: KeystoneContext) => {
const companies = await context.lists.Company.createMany({
data: [
{ data: { name: sampleOne(alphanumGenerator) } },
{ data: { name: sampleOne(alphanumGenerator) } },
{ data: { name: sampleOne(alphanumGenerator) } },
{ name: sampleOne(alphanumGenerator) },
{ name: sampleOne(alphanumGenerator) },
{ name: sampleOne(alphanumGenerator) },
],
});
const locations = await context.lists.Location.createMany({
data: [
{ data: { name: sampleOne(alphanumGenerator) } },
{ data: { name: sampleOne(alphanumGenerator) } },
{ data: { name: sampleOne(alphanumGenerator) } },
{ name: sampleOne(alphanumGenerator) },
{ name: sampleOne(alphanumGenerator) },
{ name: sampleOne(alphanumGenerator) },
],
});
return { locations, companies };
Expand Down Expand Up @@ -64,7 +64,7 @@ const getCompanyAndLocation = async (

const createReadData = async (context: KeystoneContext) => {
// create locations [A, A, B, B, C, C];
const data = ['A', 'A', 'B', 'B', 'C', 'C'].map(name => ({ data: { name } }));
const data = ['A', 'A', 'B', 'B', 'C', 'C'].map(name => ({ name }));
const locations = await context.lists.Location.createMany({ data, query: 'id name' });
await Promise.all(
[
Expand Down Expand Up @@ -432,7 +432,7 @@ multiAdapterRunners().map(({ runner, provider }) =>

// Run the query to disconnect the location from company
const data = await context.graphql.run({
query: `mutation { deleteCompany(id: "${company.id}") { id } } `,
query: `mutation { deleteCompany(where: { id: "${company.id}" }) { id } } `,
});
expect(data.deleteCompany.id).toBe(company.id);

Expand Down
18 changes: 9 additions & 9 deletions tests/api-tests/relationships/crud/many-to-many.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ const alphanumGenerator = gen.alphaNumString.notEmpty();
const createInitialData = async (context: KeystoneContext) => {
const companies = await context.lists.Company.createMany({
data: [
{ data: { name: sampleOne(alphanumGenerator) } },
{ data: { name: sampleOne(alphanumGenerator) } },
{ data: { name: sampleOne(alphanumGenerator) } },
{ name: sampleOne(alphanumGenerator) },
{ name: sampleOne(alphanumGenerator) },
{ name: sampleOne(alphanumGenerator) },
],
});
const locations = await context.lists.Location.createMany({
data: [
{ data: { name: sampleOne(alphanumGenerator) } },
{ data: { name: sampleOne(alphanumGenerator) } },
{ data: { name: sampleOne(alphanumGenerator) } },
{ name: sampleOne(alphanumGenerator) },
{ name: sampleOne(alphanumGenerator) },
{ name: sampleOne(alphanumGenerator) },
],
});
return { locations, companies };
Expand Down Expand Up @@ -76,9 +76,9 @@ const getCompanyAndLocation = async (
const createReadData = async (context: KeystoneContext) => {
// create locations [A, A, B, B, C, C];
const data = await context.graphql.run({
query: `mutation create($locations: [LocationsCreateInput!]!) { createLocations(data: $locations) { id name } }`,
query: `mutation create($locations: [LocationCreateInput!]!) { createLocations(data: $locations) { id name } }`,
variables: {
locations: ['A', 'A', 'B', 'B', 'C', 'C'].map(name => ({ data: { name } })),
locations: ['A', 'A', 'B', 'B', 'C', 'C'].map(name => ({ name })),
},
});
const { createLocations } = data;
Expand Down Expand Up @@ -598,7 +598,7 @@ multiAdapterRunners().map(({ runner, provider }) =>

// Run the query to disconnect the location from company
const data = await context.graphql.run({
query: `mutation { deleteCompany(id: "${company.id}") { id } } `,
query: `mutation { deleteCompany(where: { id: "${company.id}" }) { id } } `,
});
expect(data.deleteCompany.id).toBe(company.id);

Expand Down
20 changes: 10 additions & 10 deletions tests/api-tests/relationships/crud/one-to-many-one-sided.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ const alphanumGenerator = gen.alphaNumString.notEmpty();
const createInitialData = async (context: KeystoneContext) => {
const companies = await context.lists.Company.createMany({
data: [
{ data: { name: sampleOne(alphanumGenerator) } },
{ data: { name: sampleOne(alphanumGenerator) } },
{ data: { name: sampleOne(alphanumGenerator) } },
{ name: sampleOne(alphanumGenerator) },
{ name: sampleOne(alphanumGenerator) },
{ name: sampleOne(alphanumGenerator) },
],
});
const locations = await context.lists.Location.createMany({
data: [
{ data: { name: sampleOne(alphanumGenerator) } },
{ data: { name: sampleOne(alphanumGenerator) } },
{ data: { name: sampleOne(alphanumGenerator) } },
{ name: sampleOne(alphanumGenerator) },
{ name: sampleOne(alphanumGenerator) },
{ name: sampleOne(alphanumGenerator) },
],
});
return { locations, companies };
Expand Down Expand Up @@ -57,10 +57,10 @@ const createComplexData = async (context: KeystoneContext) => {
query: `
mutation {
createCompanies(data: [
{ data: { name: "A" location: { create: { name: "A" } } } }
{ data: { name: "B" location: { create: { name: "D" } } } }
{ data: { name: "C" location: { create: { name: "B" } } } }
{ data: { name: "E" } }
{ name: "A" location: { create: { name: "A" } } }
{ name: "B" location: { create: { name: "D" } } }
{ name: "C" location: { create: { name: "B" } } }
{ name: "E" }
]) { id name location { id name }}
}`,
})) as T1;
Expand Down
Loading

0 comments on commit 5c00d7c

Please sign in to comment.