Skip to content

Commit 1e4850f

Browse files
fix: [GROOT-1314] fix broken pagination for taxonomy requests (#2701)
1 parent 6135540 commit 1e4850f

File tree

5 files changed

+74
-7
lines changed

5 files changed

+74
-7
lines changed

lib/adapters/REST/endpoints/concept-scheme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const getMany: RestEndpoint<'ConceptScheme', 'getMany'> = (
4141
) => {
4242
const url = params.query?.pageUrl ?? basePath(params.organizationId)
4343
return raw.get<CursorPaginatedCollectionProp<ConceptSchemeProps>>(http, url, {
44-
params: params.query?.pageUrl ? {} : params.query,
44+
params: params.query?.pageUrl ? undefined : params.query,
4545
})
4646
}
4747

lib/adapters/REST/endpoints/concept.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ function cursorBasedCollection(
156156
organizationId: string
157157
query?: Record<string, string | number> & { pageUrl?: string }
158158
}
159-
): { url: string; queryParams: Record<string, string | number> } {
159+
): { url: string; queryParams?: Record<string, string | number> } {
160160
return params.query?.pageUrl
161-
? { url: params.query?.pageUrl, queryParams: {} }
161+
? { url: params.query?.pageUrl }
162162
: {
163163
url: `${basePath(params.organizationId)}${path}`,
164-
queryParams: params.query || {},
164+
queryParams: params.query,
165165
}
166166
}

test/integration/taxonomy-integration.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,38 @@ describe('Taxonomy Integration', () => {
254254
expect(items.length).toBe(3)
255255
})
256256

257+
it('gets a list of all paginated concepts', async () => {
258+
await Promise.all(
259+
Array(3)
260+
.fill(null)
261+
.map(async (i) => {
262+
const concept: CreateConceptProps = {
263+
prefLabel: {
264+
'en-US': `Test Concept ${i}`,
265+
},
266+
}
267+
268+
const result = await client.concept.create({}, concept)
269+
conceptsToDelete.push(result)
270+
})
271+
)
272+
273+
const { items, pages } = await client.concept.getMany({
274+
query: {
275+
limit: 2,
276+
},
277+
})
278+
expect(items.length).toBe(2)
279+
280+
const { items: nextItems } = await client.concept.getMany({
281+
query: {
282+
limit: 2,
283+
pageUrl: pages?.next,
284+
},
285+
})
286+
expect(nextItems.length).toBe(1)
287+
})
288+
257289
it('creates a concept with a broader concept', async () => {
258290
const first = await client.concept.create(
259291
{},
@@ -533,6 +565,38 @@ describe('Taxonomy Integration', () => {
533565
const { items } = await client.conceptScheme.getMany({})
534566
expect(items.length).toBe(3)
535567
})
568+
569+
it('gets a list of all paginated concept schemes', async () => {
570+
await Promise.all(
571+
Array(3)
572+
.fill(null)
573+
.map(async (i) => {
574+
const conceptScheme: CreateConceptSchemeProps = {
575+
prefLabel: {
576+
'en-US': `Test ConceptScheme ${i}`,
577+
},
578+
}
579+
580+
const result = await client.conceptScheme.create({}, conceptScheme)
581+
conceptSchemesToDelete.push(result)
582+
})
583+
)
584+
585+
const { items, pages } = await client.conceptScheme.getMany({
586+
query: {
587+
limit: 2,
588+
},
589+
})
590+
expect(items.length).toBe(2)
591+
592+
const { items: nextItems } = await client.conceptScheme.getMany({
593+
query: {
594+
limit: 2,
595+
pageUrl: pages?.next,
596+
},
597+
})
598+
expect(nextItems.length).toBe(1)
599+
})
536600
})
537601

538602
function isConceptProps(concept: any) {

test/unit/adapters/REST/endpoints/concept-scheme.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ describe('ConceptScheme', () => {
199199
params: {
200200
query: { pageUrl: 'page-url', params: {} },
201201
},
202-
expected: { url: 'page-url', params: {} },
202+
// IMPORTANT: if we pass {} instead of undefined for params, axios adds ? which breaks the pre-appended url params
203+
expected: { url: 'page-url', params: undefined },
203204
},
204205
]
205206

test/unit/adapters/REST/endpoints/concept.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ describe('Concept', () => {
3838
{
3939
name: 'without query params',
4040
params: {},
41-
expected: { url: '/organizations/organization-id/taxonomy/concepts', params: {} },
41+
// IMPORTANT: if we pass {} instead of undefined for params, axios adds ? which breaks the pre-appended url params
42+
expected: { url: '/organizations/organization-id/taxonomy/concepts', params: undefined },
4243
},
4344
{
4445
name: 'with pageUrl query params',
4546
params: {
4647
query: { pageUrl: 'page-url' },
4748
},
48-
expected: { url: 'page-url', params: {} },
49+
// IMPORTANT: if we pass {} instead of undefined for params, axios adds ? which breaks the pre-appended url params
50+
expected: { url: 'page-url', params: undefined },
4951
},
5052
{
5153
name: 'with conceptScheme query params',

0 commit comments

Comments
 (0)