it('can be retrieved', done => { request({ url: 'http://localhost:8378/1/config', json: true, headers, }).then(response => { const body = response.data; try { expect(response.status).toEqual(200); expect(body.params.companies).toEqual(['US', 'DK']); } catch (e) { jfail(e); } done(); }); });
describe('Delete', () => { test( 'delete', runner(setupKeystone, async ({ keystone }) => { // Manually setup a connected Company <-> Location const { location, company } = await createCompanyAndLocation(keystone); // Run the query to disconnect the location from company const { data, errors } = await keystone.executeGraphQL({ query: `mutation { deleteCompany(id: "${company.id}") { id } } `, }); expect(errors).toBe(undefined); expect(data.deleteCompany.id).toBe(company.id); // Check the link has been broken const result = await getCompanyAndLocation(keystone, company.id, location.id); expect(result.Company).toBe(null); expect(result.Location.companies).toEqual([]); }) ); });
const createCompanyAndLocation = async keystone => { const { data: { createCompany }, errors, } = await keystone.executeGraphQL({ query: ` mutation { createCompany(data: { locations: { create: [{ name: "${sampleOne(alphanumGenerator)}" }] } }) { id locations { id } } }`, }); expect(errors).toBe(undefined); const { Company, Location } = await getCompanyAndLocation( keystone, createCompany.id, createCompany.locations[0].id ); // Sanity check the links are setup correctly expect(Company.locations[0].id.toString()).toBe(Location.id.toString()); expect(Location.companies[0].id.toString()).toBe(Company.id.toString()); return { company: createCompany, location: createCompany.locations[0] }; }
test( 'With disconnectAll', runner(setupKeystone, async ({ keystone }) => { // Manually setup a connected Company <-> Location const { location, company } = await createCompanyAndLocation(keystone); // Run the query to disconnect the location from company const { data, errors } = await keystone.executeGraphQL({ query: ` mutation { updateCompany( id: "${company.id}", data: { locations: { disconnectAll: true } } ) { id locations { id name } } } `, }); expect(errors).toBe(undefined); expect(data.updateCompany.id).toEqual(company.id); expect(data.updateCompany.locations).toEqual([]); // Check the link has been broken const result = await getCompanyAndLocation(keystone, company.id, location.id); expect(result.Company.locations).toEqual([]); expect(result.Location.companies).toEqual([]); }) );
expect(result1.companies.edges.length).toEqual(2); expect( result1.companies.edges.some(o => o.node.objectId === company1.id) ).toBeTruthy(); expect( result1.companies.edges.some(o => o.node.objectId === company2.id) ).toBeTruthy(); }); expect(result2.objectId).toEqual(country.id); expect(result2.companies.edges.length).toEqual(1); expect(result2.companies.edges[0].node.objectId).toEqual(company1.id); });
expect(result.companies.edges.length).toEqual(3); expect( result.companies.edges.some(o => o.node.objectId === company.id) ).toBeTruthy(); expect( result.companies.edges.some(o => o.node.name === 'imACompany2') ).toBeTruthy(); expect( result.companies.edges.some(o => o.node.name === 'imACompany3') ).toBeTruthy();
test( 'With create', runner(setupKeystone, async ({ keystone }) => { const locationName = sampleOne(alphanumGenerator); const { data, errors } = await keystone.executeGraphQL({ query: ` mutation { createCompany(data: { locations: { create: [{ name: "${locationName}" }] } }) { id locations { id } } } `, }); expect(errors).toBe(undefined); const { Company, Location } = await getCompanyAndLocation( keystone, data.createCompany.id, data.createCompany.locations[0].id ); // Everything should now be connected expect(Company.locations.map(({ id }) => id.toString())).toEqual([ Location.id.toString(), ]); expect(Location.companies.map(({ id }) => id.toString())).toEqual([ Company.id.toString(), ]); }) );
try { expect(response.status).toEqual(200); expect(body.params.companies).toBeUndefined(); expect(body.params.foo).toBe('bar'); expect(Object.keys(body.params).length).toBe(1);
expect(result.companies.edges.length).toEqual(2); expect( result.companies.edges.some(o => o.node.objectId === company2.id) ).toBeTruthy(); expect( result.companies.edges.some(o => o.node.name === 'imACompany3') ).toBeTruthy(); expect( result.companies.edges.some(o => o.node.objectId === company1.id) ).toBeFalsy();
Location.id.toString(), ]); expect(Location.companies.map(({ id }) => id.toString())).toEqual([ Company.id.toString(), ]);
test( 'With disconnect', runner(setupKeystone, async ({ keystone }) => { // Manually setup a connected Company <-> Location const { location, company } = await createCompanyAndLocation(keystone); // Run the query to disconnect the location from company const { data, errors } = await keystone.executeGraphQL({ query: ` mutation { updateCompany( id: "${company.id}", data: { locations: { disconnect: [{ id: "${location.id}" }] } } ) { id locations { id name } } } `, }); expect(errors).toBe(undefined); expect(data.updateCompany.id).toEqual(company.id); expect(data.updateCompany.locations).toEqual([]); // Check the link has been broken const result = await getCompanyAndLocation(keystone, company.id, location.id); expect(result.Company.locations).toEqual([]); expect(result.Location.companies).toEqual([]); }) );
Location.id.toString(), ]); expect(Location.companies.map(({ id }) => id.toString())).toEqual([ Company.id.toString(), ]);