From 5c54032516e21e4a0b56154165b6663fe44ff19d Mon Sep 17 00:00:00 2001 From: Tim Leslie Date: Thu, 23 Jul 2020 14:08:28 +1000 Subject: [PATCH] Remove dependency on return order of many-relationships in api-tests --- .changeset/popular-maps-juggle.md | 5 +++++ .../relationships/crud/many-to-many.test.js | 14 +++++------- .../relationships/filtering/filtering.test.js | 22 +++++-------------- .../relationships/filtering/nested.test.js | 19 ++++++---------- 4 files changed, 24 insertions(+), 36 deletions(-) create mode 100644 .changeset/popular-maps-juggle.md diff --git a/.changeset/popular-maps-juggle.md b/.changeset/popular-maps-juggle.md new file mode 100644 index 00000000000..3aaf7019519 --- /dev/null +++ b/.changeset/popular-maps-juggle.md @@ -0,0 +1,5 @@ +--- +'@keystonejs/api-tests': patch +--- + +Updated tests to not depend on resolver order. diff --git a/api-tests/relationships/crud/many-to-many.test.js b/api-tests/relationships/crud/many-to-many.test.js index 6eadcde0a7d..88bb38f9550 100644 --- a/api-tests/relationships/crud/many-to-many.test.js +++ b/api-tests/relationships/crud/many-to-many.test.js @@ -322,10 +322,9 @@ multiAdapterRunners().map(({ runner, adapterName }) => linkedCompanies.forEach(({ locations }) => { expect(locations.map(({ id }) => id)).toEqual([Location.id.toString()]); }); - expect(linkedCompanies[0].locations[0].companies).toEqual([ - { id: linkedCompanies[0].id }, - { id: linkedCompanies[1].id }, - ]); + expect(linkedCompanies[0].locations[0].companies.map(({ id }) => id).sort()).toEqual( + [linkedCompanies[0].id, linkedCompanies[1].id].sort() + ); }) ); @@ -371,10 +370,9 @@ multiAdapterRunners().map(({ runner, adapterName }) => allCompanies.forEach(({ locations }) => { expect(locations.map(({ id }) => id)).toEqual([Location.id.toString()]); }); - expect(allCompanies[0].locations[0].companies).toEqual([ - { id: allCompanies[0].id }, - { id: allCompanies[1].id }, - ]); + expect(allCompanies[0].locations[0].companies.map(({ id }) => id).sort()).toEqual( + [allCompanies[0].id, allCompanies[1].id].sort() + ); }) ); }); diff --git a/api-tests/relationships/filtering/filtering.test.js b/api-tests/relationships/filtering/filtering.test.js index c11a148b7f9..d074c64f636 100644 --- a/api-tests/relationships/filtering/filtering.test.js +++ b/api-tests/relationships/filtering/filtering.test.js @@ -155,15 +155,10 @@ multiAdapterRunners().map(({ runner, adapterName }) => expect(errors).toBe(undefined); expect(data).toHaveProperty('allUsers.0.posts'); + expect(data.allUsers).toHaveLength(1); + expect(data.allUsers[0].id).toEqual(user.id); expect(data.allUsers[0].posts).toHaveLength(3); - expect(data).toMatchObject({ - allUsers: [ - { - id: user.id, - posts: [{ id: ids[0] }, { id: ids[1] }, { id: ids[2] }], - }, - ], - }); + expect(data.allUsers[0].posts.map(({ id }) => id).sort()).toEqual(ids.sort()); }) ); @@ -203,15 +198,10 @@ multiAdapterRunners().map(({ runner, adapterName }) => expect(errors).toBe(undefined); expect(data).toHaveProperty('allUsers.0.posts'); + expect(data.allUsers).toHaveLength(1); + expect(data.allUsers[0].id).toEqual(user.id); expect(data.allUsers[0].posts).toHaveLength(3); - expect(data).toMatchObject({ - allUsers: [ - { - id: user.id, - posts: [{ id: ids[0] }, { id: ids[1] }, { id: ids[2] }], - }, - ], - }); + expect(data.allUsers[0].posts.map(({ id }) => id).sort()).toEqual(ids.sort()); }) ); diff --git a/api-tests/relationships/filtering/nested.test.js b/api-tests/relationships/filtering/nested.test.js index f66da58600b..719e1655742 100644 --- a/api-tests/relationships/filtering/nested.test.js +++ b/api-tests/relationships/filtering/nested.test.js @@ -62,19 +62,14 @@ multiAdapterRunners().map(({ runner, adapterName }) => expect(errors).toBe(undefined); expect(data).toHaveProperty('allUsers.0.posts'); + expect(data.allUsers).toHaveLength(2); + expect(data.allUsers[0].id).toEqual(user.id); expect(data.allUsers[0].posts).toHaveLength(2); - expect(data).toMatchObject({ - allUsers: [ - { - id: user.id, - posts: [{ id: ids[1] }, { id: ids[2] }], - }, - { - id: user2.id, - posts: [], - }, - ], - }); + expect(data.allUsers[0].posts.map(({ id }) => id).sort()).toEqual( + [ids[1], ids[2]].sort() + ); + expect(data.allUsers[1].id).toEqual(user2.id); + expect(data.allUsers[1].posts).toHaveLength(0); }) );