Skip to content

fix: [GROOT-1314] fix broken pagination for taxonomy requests #2701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 1 addition & 1 deletion lib/adapters/REST/endpoints/concept-scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const getMany: RestEndpoint<'ConceptScheme', 'getMany'> = (
) => {
const url = params.query?.pageUrl ?? basePath(params.organizationId)
return raw.get<CursorPaginatedCollectionProp<ConceptSchemeProps>>(http, url, {
params: params.query?.pageUrl ? {} : params.query,
params: params.query?.pageUrl ? undefined : params.query,
})
}

Expand Down
6 changes: 3 additions & 3 deletions lib/adapters/REST/endpoints/concept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ function cursorBasedCollection(
organizationId: string
query?: Record<string, string | number> & { pageUrl?: string }
}
): { url: string; queryParams: Record<string, string | number> } {
): { url: string; queryParams?: Record<string, string | number> } {
return params.query?.pageUrl
? { url: params.query?.pageUrl, queryParams: {} }
? { url: params.query?.pageUrl }
: {
url: `${basePath(params.organizationId)}${path}`,
queryParams: params.query || {},
queryParams: params.query,
}
}
64 changes: 64 additions & 0 deletions test/integration/taxonomy-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,38 @@ describe('Taxonomy Integration', () => {
expect(items.length).toBe(3)
})

it('gets a list of all paginated concepts', async () => {
await Promise.all(
Array(3)
.fill(null)
.map(async (i) => {
const concept: CreateConceptProps = {
prefLabel: {
'en-US': `Test Concept ${i}`,
},
}

const result = await client.concept.create({}, concept)
conceptsToDelete.push(result)
})
)

const { items, pages } = await client.concept.getMany({
query: {
limit: 2,
},
})
expect(items.length).toBe(2)

const { items: nextItems } = await client.concept.getMany({
query: {
limit: 2,
pageUrl: pages?.next,
},
})
expect(nextItems.length).toBe(1)
})

it('creates a concept with a broader concept', async () => {
const first = await client.concept.create(
{},
Expand Down Expand Up @@ -533,6 +565,38 @@ describe('Taxonomy Integration', () => {
const { items } = await client.conceptScheme.getMany({})
expect(items.length).toBe(3)
})

it('gets a list of all paginated concept schemes', async () => {
await Promise.all(
Array(3)
.fill(null)
.map(async (i) => {
const conceptScheme: CreateConceptSchemeProps = {
prefLabel: {
'en-US': `Test ConceptScheme ${i}`,
},
}

const result = await client.conceptScheme.create({}, conceptScheme)
conceptSchemesToDelete.push(result)
})
)

const { items, pages } = await client.conceptScheme.getMany({
query: {
limit: 2,
},
})
expect(items.length).toBe(2)

const { items: nextItems } = await client.conceptScheme.getMany({
query: {
limit: 2,
pageUrl: pages?.next,
},
})
expect(nextItems.length).toBe(1)
})
})

function isConceptProps(concept: any) {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/adapters/REST/endpoints/concept-scheme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ describe('ConceptScheme', () => {
params: {
query: { pageUrl: 'page-url', params: {} },
},
expected: { url: 'page-url', params: {} },
// IMPORTANT: if we pass {} instead of undefined for params, axios adds ? which breaks the pre-appended url params
expected: { url: 'page-url', params: undefined },
},
]

Expand Down
6 changes: 4 additions & 2 deletions test/unit/adapters/REST/endpoints/concept.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ describe('Concept', () => {
{
name: 'without query params',
params: {},
expected: { url: '/organizations/organization-id/taxonomy/concepts', params: {} },
// IMPORTANT: if we pass {} instead of undefined for params, axios adds ? which breaks the pre-appended url params
expected: { url: '/organizations/organization-id/taxonomy/concepts', params: undefined },
},
{
name: 'with pageUrl query params',
params: {
query: { pageUrl: 'page-url' },
},
expected: { url: 'page-url', params: {} },
// IMPORTANT: if we pass {} instead of undefined for params, axios adds ? which breaks the pre-appended url params
expected: { url: 'page-url', params: undefined },
},
{
name: 'with conceptScheme query params',
Expand Down