Skip to content

Commit

Permalink
added unit test for get CollectionItemUrl method
Browse files Browse the repository at this point in the history
  • Loading branch information
ronitjadhav committed Apr 5, 2024
1 parent 6ff1fff commit 863a979
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
13 changes: 13 additions & 0 deletions src/ogc-api/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,19 @@ describe('OgcApiEndpoint', () => {
});
});
});
describe('#getCollectionItemsUrl', () => {
it('returns the correct URL for the collection items', () => {
expect(
endpoint.getCollectionItemsUrl('airports', {
maxFeatures: 101,
query: 'name=Sumburgh Airport',
outputFormat: 'json',
})
).resolves.toEqual(
'https://my.server.org/sample-data/collections/airports/items?f=json&name=Sumburgh+Airport&limit=101'
);
});
});
});
describe('a failure happens while parsing the endpoint capabilities', () => {
beforeEach(() => {
Expand Down
24 changes: 16 additions & 8 deletions src/ogc-api/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,22 @@ export default class OgcApiEndpoint {
url.searchParams.set('f', format);

// Inline conditional statements for other options
if (options.query !== undefined) url.search += (url.search ? '&' : '') + options.query;
if (options.maxFeatures !== undefined) url.searchParams.set('limit', options.maxFeatures.toString());
if (options.offset !== undefined) url.searchParams.set('offset', options.offset.toString());
if (options.skipGeometry !== undefined) url.searchParams.set('skipGeometry', options.skipGeometry.toString());
if (options.outputCrs !== undefined) url.searchParams.set('outputCrs', options.outputCrs);
if (options.extent !== undefined && options.extent.length === 4) url.searchParams.set('bbox', options.extent.join(','));
if (options.extentCrs !== undefined) url.searchParams.set('bbox-crs', options.extentCrs);
if (options.properties !== undefined && options.properties.length > 0) url.searchParams.set('properties', options.properties.join(','));
if (options.query !== undefined)
url.search += (url.search ? '&' : '') + options.query;
if (options.maxFeatures !== undefined)
url.searchParams.set('limit', options.maxFeatures.toString());
if (options.offset !== undefined)
url.searchParams.set('offset', options.offset.toString());
if (options.skipGeometry !== undefined)
url.searchParams.set('skipGeometry', options.skipGeometry.toString());
if (options.outputCrs !== undefined)
url.searchParams.set('outputCrs', options.outputCrs);
if (options.extent !== undefined && options.extent.length === 4)
url.searchParams.set('bbox', options.extent.join(','));
if (options.extentCrs !== undefined)
url.searchParams.set('bbox-crs', options.extentCrs);
if (options.properties !== undefined && options.properties.length > 0)
url.searchParams.set('properties', options.properties.join(','));

return url.toString();
})
Expand Down

0 comments on commit 863a979

Please sign in to comment.