Skip to content

Commit

Permalink
Merge pull request #51 from koopjs/b/7627-sort-query-fix
Browse files Browse the repository at this point in the history
Fix 0 batch when sort field is applied
  • Loading branch information
sansth1010 authored Aug 22, 2023
2 parents dce1bff + 7f1bbd4 commit b0a5617
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,81 @@ describe('HubApiModel', () => {
}
});

it('can handle 0 batches when sort fields are applied', async () => {
// Setup
const terms = faker.random.words();
const id = faker.datatype.uuid();
const model = new HubApiModel();

const searchRequestBody: IContentSearchRequest = {
filter: {
terms,
id
},
options: {
portal: 'https://qaext.arcgis.com',
sortField: 'Date Created|created|modified',
sortOrder: SortDirection.asc
}
};
const req = {
app: { locals: { arcgisPortal: 'https://devext.arcgis.com' } },
res: {
locals: {
searchRequestBody
}
},
query: {}
} as unknown as Request;

// Mock
const batches = 0;
const pagesPerBatch = 0;
const resultsPerPage = 0;

mockGetBatchStreams.mockImplementationOnce(() => {
return Promise.resolve([]);
});
mockHubApiRequest.mockResolvedValue(['id']);

try {
const actualResponses = [];
const stream = await model.getStream(req);
const pass = new PassThrough({ objectMode: true });
pass.on('data', data => {
actualResponses.push(data);
});

const pipe = promisify(pipeline);

await pipe(stream, pass);
expect(mockGetBatchStreams).toHaveBeenCalledTimes(1);
expect(mockGetBatchStreams).toHaveBeenNthCalledWith(1, {
request: {
filter: {
terms,
id
},
options: {
fields: 'id,type,slug,access,size,licenseInfo,structuredLicense,boundary',
portal: 'https://qaext.arcgis.com',
sortField: 'Date Created|created|modified',
sortOrder: SortDirection.asc
}
},
siteUrl: undefined,
orgBaseUrl: "https://qa-pre-a-hub.mapsdev.arcgis.com",
orgTitle: "QA Premium Alpha Hub",
portalUrl: "https://devext.arcgis.com",
limit: undefined
});
expect(actualResponses).toHaveLength(batches * pagesPerBatch * resultsPerPage);
} catch (err) {
console.error(err);
fail(err);
}
});

it('should generate orgBaseUrl if dev portal url is supplied', async () => {
// Setup
const terms = faker.random.words();
Expand Down
5 changes: 5 additions & 0 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ export class HubApiModel {
}

private async _combineStreamsInSequence(sources: PagingStream[], destination: PassThrough): Promise<void> {
if (!sources.length) {
destination.end(() => { });
return;
}

for (const stream of sources) {
await new Promise((resolve, reject) => {
stream.pipe(destination, { end: false });
Expand Down

0 comments on commit b0a5617

Please sign in to comment.