From a6b3215c9e1a2185d74a9c57102c894045d6ea54 Mon Sep 17 00:00:00 2001 From: gestchild Date: Tue, 23 Dec 2025 11:54:14 +0000 Subject: [PATCH 1/2] remove filterOutExhibitions param --- api/src/controllers/events.ts | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/api/src/controllers/events.ts b/api/src/controllers/events.ts index 70361690..0b35123f 100644 --- a/api/src/controllers/events.ts +++ b/api/src/controllers/events.ts @@ -44,7 +44,6 @@ type QueryParams = { location?: string; isAvailableOnline?: string; timespan?: string; - filterOutExhibitions?: string; linkedWork?: string | string[]; } & PaginationQueryParameters; @@ -87,12 +86,6 @@ const isAvailableOnlineValidator = queryValidator({ singleValue: true, }); -const filterOutExhibitionsValidator = queryValidator({ - name: 'filterOutExhibitions', - allowed: ['true'], - singleValue: true, -}); - const timespanValidator = queryValidator({ name: 'timespan', allowed: timespans, @@ -122,7 +115,7 @@ const formatAliasMap: Record = { }; const paramsValidator = (params: QueryParams): QueryParams => { - const { isAvailableOnline, filterOutExhibitions, format, ...rest } = params; + const { isAvailableOnline, format, ...rest } = params; if (params.location) locationsValidator({ @@ -191,14 +184,7 @@ const paramsValidator = (params: QueryParams): QueryParams => { isAvailableOnline, }); - const hasFilterOutExhibitions = - filterOutExhibitions && - filterOutExhibitionsValidator({ - filterOutExhibitions, - }); - - // For isAvailableOnline and filterOutExhibitions, - // we are ignoring all values passed in but "true". + // For isAvailableOnline, we are ignoring all values passed in but "true". // Anything else should remove the param from the query return { ...rest, @@ -207,7 +193,6 @@ const paramsValidator = (params: QueryParams): QueryParams => { ? { excludeFormat: excludeFormats.join(',') } : {}), ...(hasIsAvailableOnline ? { isAvailableOnline } : {}), - ...(hasFilterOutExhibitions ? { filterOutExhibitions } : {}), }; }; @@ -345,15 +330,6 @@ const eventsController = (clients: Clients, config: Config): EventsHandler => { isChildScheduledEvent: true, }, }, - ...(validParams.filterOutExhibitions - ? [ - { - term: { - 'filter.format': EVENT_EXHIBITION_FORMAT_ID, - }, - }, - ] - : []), ...(validParams.excludeFormat ? [ { From a1db45f3f1e33d34b328e4b913ae0b6d59ad7b6d Mon Sep 17 00:00:00 2001 From: gestchild Date: Tue, 23 Dec 2025 16:30:16 +0000 Subject: [PATCH 2/2] fix tests --- api/test/__snapshots__/query.test.ts.snap | 49 +++++++++++++++++++++++ api/test/addressables.test.ts | 16 ++++---- api/test/article.test.ts | 8 ++-- api/test/articles.test.ts | 22 +++++----- api/test/event.test.ts | 8 ++-- api/test/venues.test.ts | 4 +- 6 files changed, 79 insertions(+), 28 deletions(-) diff --git a/api/test/__snapshots__/query.test.ts.snap b/api/test/__snapshots__/query.test.ts.snap index fd20fb8e..b7d67f53 100644 --- a/api/test/__snapshots__/query.test.ts.snap +++ b/api/test/__snapshots__/query.test.ts.snap @@ -46,6 +46,55 @@ exports[`addressables query makes the expected query to ES for a given set of qu } `; +exports[`addressables query makes the expected query to ES for multiple linkedWork parameters 1`] = ` +{ + "_source": [ + "display", + ], + "from": 0, + "index": "test-addressables", + "query": { + "bool": { + "must": [ + { + "multi_match": { + "fields": [ + "id", + "uid", + "query.title.*^100", + "query.contributors.*^10", + "query.contributors.keyword^100", + "query.body.*", + "query.description.*", + ], + "minimum_should_match": "-25%", + "operator": "or", + "query": "sculpture", + "type": "cross_fields", + }, + }, + { + "terms": { + "query.linkedWorks": [ + "work123", + "work456", + ], + }, + }, + ], + "must_not": [ + { + "term": { + "query.tags": "delist", + }, + }, + ], + }, + }, + "size": 20, +} +`; + exports[`articles query makes the expected query to ES for a given set of query parameters 1`] = ` { "_source": [ diff --git a/api/test/addressables.test.ts b/api/test/addressables.test.ts index 3b89e457..05f2f4f9 100644 --- a/api/test/addressables.test.ts +++ b/api/test/addressables.test.ts @@ -8,9 +8,9 @@ describe('GET /all', () => { title: `test doc ${i}`, }, })); - const api = mockedApi(docs); + const { agent } = mockedApi(docs); - const response = await api.get(`/all`); + const response = await agent.get(`/all`); expect(response.statusCode).toBe(200); expect(response.body.results).toStrictEqual(docs.map(d => d.display)); }); @@ -22,17 +22,17 @@ describe('GET /all', () => { display: { title: 'Document with works' }, }, ]; - const api = mockedApi(docs); + const { agent } = mockedApi(docs); - const response = await api.get(`/all?linkedWork=work123`); + const response = await agent.get(`/all?linkedWork=work123`); expect(response.statusCode).toBe(200); expect(response.body.results).toBeDefined(); }); it('returns 400 for invalid linkedWork format', async () => { - const api = mockedApi([]); + const { agent } = mockedApi([]); - const response = await api.get(`/all?linkedWork=invalid-work-id!`); + const response = await agent.get(`/all?linkedWork=invalid-work-id!`); expect(response.statusCode).toBe(400); expect(response.body.description).toContain('Invalid work ID format'); }); @@ -44,9 +44,9 @@ describe('GET /all', () => { display: { title: 'Health article' }, }, ]; - const api = mockedApi(docs); + const { agent } = mockedApi(docs); - const response = await api.get(`/all?query=health&linkedWork=work123`); + const response = await agent.get(`/all?query=health&linkedWork=work123`); expect(response.statusCode).toBe(200); expect(response.body.results).toBeDefined(); }); diff --git a/api/test/article.test.ts b/api/test/article.test.ts index a9415314..11a78fa7 100644 --- a/api/test/article.test.ts +++ b/api/test/article.test.ts @@ -4,17 +4,17 @@ describe('GET /articles/:id', () => { it('returns a document for the given ID', async () => { const testId = '123'; const testDoc = { title: 'test-article' }; - const api = mockedApi([{ id: testId, display: testDoc }]); + const { agent } = mockedApi([{ id: testId, display: testDoc }]); - const response = await api.get(`/articles/${testId}`); + const response = await agent.get(`/articles/${testId}`); expect(response.statusCode).toBe(200); expect(response.body).toStrictEqual(testDoc); }); it('returns a 404 if no document for the given ID exists', async () => { - const api = mockedApi([]); + const { agent } = mockedApi([]); - const response = await api.get(`/articles/123`); + const response = await agent.get(`/articles/123`); expect(response.statusCode).toBe(404); }); }); diff --git a/api/test/articles.test.ts b/api/test/articles.test.ts index b9fb4222..25c10bef 100644 --- a/api/test/articles.test.ts +++ b/api/test/articles.test.ts @@ -8,9 +8,9 @@ describe('GET /articles', () => { title: `test doc ${i}`, }, })); - const api = mockedApi(docs); + const { agent } = mockedApi(docs); - const response = await api.get(`/articles`); + const response = await agent.get(`/articles`); expect(response.statusCode).toBe(200); expect(response.body.results).toStrictEqual(docs.map(d => d.display)); }); @@ -22,17 +22,17 @@ describe('GET /articles', () => { display: { title: 'Article with works' }, }, ]; - const api = mockedApi(docs); + const { agent } = mockedApi(docs); - const response = await api.get(`/articles?linkedWork=work123`); + const response = await agent.get(`/articles?linkedWork=work123`); expect(response.statusCode).toBe(200); expect(response.body.results).toBeDefined(); }); it('returns 400 for invalid linkedWork format', async () => { - const api = mockedApi([]); + const { agent } = mockedApi([]); - const response = await api.get(`/articles?linkedWork=invalid-work-id!`); + const response = await agent.get(`/articles?linkedWork=invalid-work-id!`); expect(response.statusCode).toBe(400); expect(response.body.description).toContain('Invalid work ID format'); }); @@ -44,9 +44,11 @@ describe('GET /articles', () => { display: { title: 'Health article' }, }, ]; - const api = mockedApi(docs); + const { agent } = mockedApi(docs); - const response = await api.get(`/articles?query=health&linkedWork=work123`); + const response = await agent.get( + `/articles?query=health&linkedWork=work123` + ); expect(response.statusCode).toBe(200); expect(response.body.results).toBeDefined(); }); @@ -58,9 +60,9 @@ describe('GET /articles', () => { display: { title: 'Article with multiple works' }, }, ]; - const api = mockedApi(docs); + const { agent } = mockedApi(docs); - const response = await api.get(`/articles?linkedWork=work123,work456`); + const response = await agent.get(`/articles?linkedWork=work123,work456`); expect(response.statusCode).toBe(200); expect(response.body.results).toBeDefined(); }); diff --git a/api/test/event.test.ts b/api/test/event.test.ts index dfd9bfce..05ac3528 100644 --- a/api/test/event.test.ts +++ b/api/test/event.test.ts @@ -4,17 +4,17 @@ describe('GET /events/:id', () => { it('returns a document for the given ID', async () => { const testId = 'abc'; const testDoc = { title: 'test-event' }; - const api = mockedApi([{ id: testId, display: testDoc }]); + const { agent } = mockedApi([{ id: testId, display: testDoc }]); - const response = await api.get(`/events/${testId}`); + const response = await agent.get(`/events/${testId}`); expect(response.statusCode).toBe(200); expect(response.body).toStrictEqual(testDoc); }); it('returns a 404 if no document for the given ID exists', async () => { - const api = mockedApi([]); + const { agent } = mockedApi([]); - const response = await api.get(`/events/abc`); + const response = await agent.get(`/events/abc`); expect(response.statusCode).toBe(404); }); }); diff --git a/api/test/venues.test.ts b/api/test/venues.test.ts index 20210937..1a00659c 100644 --- a/api/test/venues.test.ts +++ b/api/test/venues.test.ts @@ -249,11 +249,11 @@ describe('GET /venues', () => { jest.useFakeTimers().setSystemTime(new Date('2024-04-02T08:00:00.000Z')); const testId = '123'; - const api = mockedApi([ + const { agent } = mockedApi([ { id: testId, display: venueDisplay, data: venueData }, ]); - const response = await api.get(`/venues`); + const response = await agent.get(`/venues`); expect(response.statusCode).toBe(200); expect(response.body.results[0]).toEqual({ ...venueDisplay,