From 3ed28b49c795b642a17b8fa246d6fd46bce25227 Mon Sep 17 00:00:00 2001 From: Joshua Berry Date: Fri, 5 Dec 2025 15:44:57 +0000 Subject: [PATCH] feat: add referencingEntryId query parameter to Resource API [ARC-727] --- lib/entities/resource.ts | 2 + test/unit/plain/resource.test.ts | 79 ++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/lib/entities/resource.ts b/lib/entities/resource.ts index b57e610d8..58f0b0951 100644 --- a/lib/entities/resource.ts +++ b/lib/entities/resource.ts @@ -12,11 +12,13 @@ export type ResourceQueryOptions = LookupQueryOptions | SearchQueryOptions type LookupQueryOptions = { 'sys.urn[in]': string locale?: string + referencingEntryId?: string } & BasicCursorPaginationOptions type SearchQueryOptions = { query: string locale?: string + referencingEntryId?: string } & BasicCursorPaginationOptions export type ResourceProps = { diff --git a/test/unit/plain/resource.test.ts b/test/unit/plain/resource.test.ts index 9881ef419..acfb2d0a4 100644 --- a/test/unit/plain/resource.test.ts +++ b/test/unit/plain/resource.test.ts @@ -30,4 +30,83 @@ describe('Resource', () => { `/spaces/spaceId/environments/envId/resource_types/${resourceTypeId}/resources`, ) }) + + test('getMany with referencingEntryId parameter', async () => { + const { httpMock, adapterMock } = setupRestAdapter( + Promise.resolve({ data: { items: [resourceMock] } }), + ) + const plainClient = createClient({ apiAdapter: adapterMock }, { type: 'plain' }) + const response = await plainClient.resource.getMany({ + spaceId, + environmentId, + resourceTypeId, + query: { + query: 'test', + referencingEntryId: 'entry-123', + }, + }) + + expect(response).toBeInstanceOf(Object) + expect(httpMock.get.mock.calls[0][0]).toBe( + `/spaces/spaceId/environments/envId/resource_types/${resourceTypeId}/resources`, + ) + expect(httpMock.get.mock.calls[0][1]).toMatchObject({ + params: { + query: 'test', + referencingEntryId: 'entry-123', + }, + }) + }) + + test('getMany with locale parameter', async () => { + const { httpMock, adapterMock } = setupRestAdapter( + Promise.resolve({ data: { items: [resourceMock] } }), + ) + const plainClient = createClient({ apiAdapter: adapterMock }, { type: 'plain' }) + const response = await plainClient.resource.getMany({ + spaceId, + environmentId, + resourceTypeId, + query: { + 'sys.urn[in]': '123,456', + locale: 'en-US', + }, + }) + + expect(response).toBeInstanceOf(Object) + expect(httpMock.get.mock.calls[0][1]).toMatchObject({ + params: { + 'sys.urn[in]': '123,456', + locale: 'en-US', + }, + }) + }) + + test('getMany with multiple optional parameters', async () => { + const { httpMock, adapterMock } = setupRestAdapter( + Promise.resolve({ data: { items: [resourceMock] } }), + ) + const plainClient = createClient({ apiAdapter: adapterMock }, { type: 'plain' }) + const response = await plainClient.resource.getMany({ + spaceId, + environmentId, + resourceTypeId, + query: { + query: 'search term', + locale: 'de-DE', + referencingEntryId: 'entry-456', + limit: 10, + }, + }) + + expect(response).toBeInstanceOf(Object) + expect(httpMock.get.mock.calls[0][1]).toMatchObject({ + params: { + query: 'search term', + locale: 'de-DE', + referencingEntryId: 'entry-456', + limit: 10, + }, + }) + }) })