From ef28f5aaad27955fc08fa7a967d7b385b76e2060 Mon Sep 17 00:00:00 2001 From: Raphaelle Cantin Date: Tue, 17 Dec 2024 13:04:05 +0000 Subject: [PATCH] Update exhibitions tests to sort by end date --- .../prismic/fetch/exhibitions.test.ts | 76 ++++++++++++++++--- 1 file changed, 65 insertions(+), 11 deletions(-) diff --git a/content/webapp/services/prismic/fetch/exhibitions.test.ts b/content/webapp/services/prismic/fetch/exhibitions.test.ts index 1cfbf5f3d8..caafce8bdb 100644 --- a/content/webapp/services/prismic/fetch/exhibitions.test.ts +++ b/content/webapp/services/prismic/fetch/exhibitions.test.ts @@ -38,19 +38,52 @@ describe('fetchExhibitions', () => { .map(e => ({ id: e.id, title: asText(e.data.title), + end: e.data.end, })) - .sort((a, b) => (a.id > b.id ? 1 : -1)) + .sort((a, b) => { + // Makes TS happy but this condition should never not work + // we always have an end date, even for permanent exhibitions + // e.g. Being Human ends in 2090 + if (a.end && b.end) { + return a.end > b.end ? 1 : -1; + } + return 1; + }) .slice(0, 6); // Slicing so we don't have to keep adding new exhibitions. // Of these exhibitions, three closed on 23 April 2023: // Objects in Stereo, The Archive of an Unseen, and the Healing Pavilion expect(closingDayExhibitions).toStrictEqual([ - { id: 'XNFfsxAAANwqbNWD', title: 'Being Human' }, - { id: 'Y0QhIxEAAA__0sMb', title: 'Objects in Stereo' }, - { id: 'Y3zI8hAAAGXXcMua', title: 'The Archive of an Unseen' }, - { id: 'Y8VNbhEAAPJM-oki', title: 'Milk' }, - { id: 'Yzv9ChEAABfUrkVp', title: 'The Healing Pavilion' }, - { id: 'ZAW0PxQAACcG-pX8', title: 'Genetic Automata' }, + { + id: 'Yzv9ChEAABfUrkVp', + title: 'The Healing Pavilion', + end: '2023-04-22T23:00:00+0000', + }, + { + id: 'Y0QhIxEAAA__0sMb', + title: 'Objects in Stereo', + end: '2023-04-22T23:00:00+0000', + }, + { + id: 'Y3zI8hAAAGXXcMua', + title: 'The Archive of an Unseen', + end: '2023-04-22T23:00:00+0000', + }, + { + id: 'Y8VNbhEAAPJM-oki', + title: 'Milk', + end: '2023-09-09T23:00:00+0000', + }, + { + id: 'ZAW0PxQAACcG-pX8', + title: 'Genetic Automata', + end: '2024-02-11T00:00:00+0000', + }, + { + id: 'ZJ1zCxAAACMAczPA', + title: 'The Cult of Beauty', + end: '2024-04-27T23:00:00+0000', + }, ]); mockToday({ as: new Date('2023-04-24T12:00:00Z') }); @@ -63,14 +96,35 @@ describe('fetchExhibitions', () => { .map(e => ({ id: e.id, title: asText(e.data.title), + end: e.data.end, })) - .sort((a, b) => (a.id > b.id ? 1 : -1)) + .sort((a, b) => { + // Makes TS happy but this condition should never not work + // we always have an end date, even for permanent exhibitions + // e.g. Being Human ends in 2090 + if (a.end && b.end) { + return a.end > b.end ? 1 : -1; + } + return 1; + }) .slice(0, 3); // Slicing so we don't have to keep adding new exhibitions. expect(nextDayExhibitions).toStrictEqual([ - { id: 'XNFfsxAAANwqbNWD', title: 'Being Human' }, - { id: 'Y8VNbhEAAPJM-oki', title: 'Milk' }, - { id: 'ZAW0PxQAACcG-pX8', title: 'Genetic Automata' }, + { + id: 'Y8VNbhEAAPJM-oki', + title: 'Milk', + end: '2023-09-09T23:00:00+0000', + }, + { + id: 'ZAW0PxQAACcG-pX8', + title: 'Genetic Automata', + end: '2024-02-11T00:00:00+0000', + }, + { + id: 'ZJ1zCxAAACMAczPA', + title: 'The Cult of Beauty', + end: '2024-04-27T23:00:00+0000', + }, ]); }, timeout