Skip to content

Commit 725af23

Browse files
committed
feat: add referencingEntryId query parameter to Resource API [ARC-727]
1 parent 3a1e5b1 commit 725af23

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

lib/entities/resource.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ export type ResourceQueryOptions = LookupQueryOptions | SearchQueryOptions
1212
type LookupQueryOptions = {
1313
'sys.urn[in]': string
1414
locale?: string
15+
referencingEntryId?: string
1516
} & BasicCursorPaginationOptions
1617

1718
type SearchQueryOptions = {
1819
query: string
1920
locale?: string
21+
referencingEntryId?: string
2022
} & BasicCursorPaginationOptions
2123

2224
export type ResourceProps = {

test/unit/plain/resource.test.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,83 @@ describe('Resource', () => {
3030
`/spaces/spaceId/environments/envId/resource_types/${resourceTypeId}/resources`,
3131
)
3232
})
33+
34+
test('getMany with referencingEntryId parameter', async () => {
35+
const { httpMock, adapterMock } = setupRestAdapter(
36+
Promise.resolve({ data: { items: [resourceMock] } }),
37+
)
38+
const plainClient = createClient({ apiAdapter: adapterMock }, { type: 'plain' })
39+
const response = await plainClient.resource.getMany({
40+
spaceId,
41+
environmentId,
42+
resourceTypeId,
43+
query: {
44+
query: 'test',
45+
referencingEntryId: 'entry-123',
46+
},
47+
})
48+
49+
expect(response).toBeInstanceOf(Object)
50+
expect(httpMock.get.mock.calls[0][0]).toBe(
51+
`/spaces/spaceId/environments/envId/resource_types/${resourceTypeId}/resources`,
52+
)
53+
expect(httpMock.get.mock.calls[0][1]).toMatchObject({
54+
params: {
55+
query: 'test',
56+
referencingEntryId: 'entry-123',
57+
},
58+
})
59+
})
60+
61+
test('getMany with locale parameter', async () => {
62+
const { httpMock, adapterMock } = setupRestAdapter(
63+
Promise.resolve({ data: { items: [resourceMock] } }),
64+
)
65+
const plainClient = createClient({ apiAdapter: adapterMock }, { type: 'plain' })
66+
const response = await plainClient.resource.getMany({
67+
spaceId,
68+
environmentId,
69+
resourceTypeId,
70+
query: {
71+
'sys.urn[in]': '123,456',
72+
locale: 'en-US',
73+
},
74+
})
75+
76+
expect(response).toBeInstanceOf(Object)
77+
expect(httpMock.get.mock.calls[0][1]).toMatchObject({
78+
params: {
79+
'sys.urn[in]': '123,456',
80+
locale: 'en-US',
81+
},
82+
})
83+
})
84+
85+
test('getMany with multiple optional parameters', async () => {
86+
const { httpMock, adapterMock } = setupRestAdapter(
87+
Promise.resolve({ data: { items: [resourceMock] } }),
88+
)
89+
const plainClient = createClient({ apiAdapter: adapterMock }, { type: 'plain' })
90+
const response = await plainClient.resource.getMany({
91+
spaceId,
92+
environmentId,
93+
resourceTypeId,
94+
query: {
95+
query: 'search term',
96+
locale: 'de-DE',
97+
referencingEntryId: 'entry-456',
98+
limit: 10,
99+
},
100+
})
101+
102+
expect(response).toBeInstanceOf(Object)
103+
expect(httpMock.get.mock.calls[0][1]).toMatchObject({
104+
params: {
105+
query: 'search term',
106+
locale: 'de-DE',
107+
referencingEntryId: 'entry-456',
108+
limit: 10,
109+
},
110+
})
111+
})
33112
})

0 commit comments

Comments
 (0)