Skip to content

Commit

Permalink
feat: Adding assets to catalog queries
Browse files Browse the repository at this point in the history
Co-authored-by: William Mai <[email protected]>
  • Loading branch information
wmai and wmai authored Mar 27, 2024
1 parent d8439e8 commit 110d5c8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/api-client/src/odsql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ function root(source: string) {
itself: () => new Query(`${source}/`),
facets: () => new Query(`${source}/facets/`),
datasets: () => new Query(`${source}/datasets/`),
/**
* FIXME: Update this URL or remove this comment when the endpoint is out of beta.
* The assets endpoint is still in development and not yet documented.
* Therefore, this URL may change in the future.
*/
assets: () => new Query(`${source}/assets/`),
export: (format: ExportCatalogFormat) => new Query(`${source}/exports/${format}/`),
dataset: (datasetId: string) => ({
itself: () => new Query(`${source}/datasets/${datasetId}/`),
Expand Down
45 changes: 45 additions & 0 deletions packages/api-client/test/odsql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ describe('ODSQL query builder', () => {
test('with no parameters', () => {
expect(fromCatalog().datasets().toString()).toEqual('catalog/datasets/');

expect(fromCatalog().assets().toString()).toEqual('catalog/assets/');

expect(fromMonitoring().itself().toString()).toEqual('monitoring/');

expect(fromDataNetwork().dataset('sirene@data').facets().lang('fr').toString()).toEqual(
Expand Down Expand Up @@ -69,6 +71,13 @@ describe('ODSQL query builder', () => {
.where(searchTerm && `search(${string(searchTerm)})`)
.toString()
).toEqual('catalog/datasets/');

expect(
fromCatalog()
.assets()
.where(searchTerm && `search(${string(searchTerm)})`)
.toString()
).toEqual('catalog/assets/');
});

test('conditional condition', () => {
Expand All @@ -79,6 +88,13 @@ describe('ODSQL query builder', () => {
.where((prev) => all(prev, searchTerm && `search(${string(searchTerm)})`))
.toString()
).toEqual('catalog/datasets/?where=%28search%28%22my+search+term%22%29%29');

expect(
fromCatalog()
.assets()
.where((prev) => all(prev, searchTerm && `search(${string(searchTerm)})`))
.toString()
).toEqual('catalog/assets/?where=%28search%28%22my+search+term%22%29%29');
});

test('list helper', () => {
Expand All @@ -89,6 +105,14 @@ describe('ODSQL query builder', () => {
.select((prev) => list(prev, 'd'))
.toString()
).toEqual(`catalog/datasets/?select=${encodeURIComponent('a,b,c,d')}`);

expect(
fromCatalog()
.assets()
.select((prev) => list(prev, 'a', 'b', 'c'))
.select((prev) => list(prev, 'd'))
.toString()
).toEqual(`catalog/assets/?select=${encodeURIComponent('a,b,c,d')}`);
});

test('date helper', () => {
Expand Down Expand Up @@ -162,6 +186,20 @@ describe('ODSQL query builder', () => {
).toEqual(
'catalog/datasets/?exclude=field%3A2&limit=45&offset=10&order_by=%60x%60&refine=field%3A1'
);

expect(
fromCatalog()
.assets()
.orderBy(`${field('x')}`)
.limit(40)
.limit((l) => l + 5)
.offset((o) => o + 10)
.refine('field:1')
.exclude('field:2')
.toString()
).toEqual(
'catalog/assets/?exclude=field%3A2&limit=45&offset=10&order_by=%60x%60&refine=field%3A1'
);
});

test('export geojson query', () => {
Expand All @@ -182,6 +220,13 @@ describe('ODSQL query builder', () => {
expect(fromCatalog().datasets().where(not(undefined)).toString()).toEqual(
'catalog/datasets/'
);

expect(fromCatalog().assets().where(not('x = 1')).toString()).toEqual(
'catalog/assets/?where=not+%28x+%3D+1%29'
);
expect(fromCatalog().assets().where(not(undefined)).toString()).toEqual(
'catalog/assets/'
);
});
test('Search clause', () => {
expect(textSearch('my search term', ['field1', 'field2'])).toEqual(
Expand Down

1 comment on commit 110d5c8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

95.24%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
src
   index.ts100%100%100%
src/client
   error.ts100%100%100%
   index.ts75.32%100%96.88%124, 13, 146, 148, 148–149, 15, 15, 151, 162, 169, 169, 17, 17, 171, 176, 179, 182, 184, 52, 82
   types.ts100%100%100%
src/odsql
   clauses.ts71.43%80%90.91%14, 32, 42
   index.ts83.72%95.74%94.19%111, 146, 25, 28, 56–57, 57, 57–58, 68, 78–79

Please sign in to comment.