Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/entities/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
79 changes: 79 additions & 0 deletions test/unit/plain/resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
})
})
})
Loading