Skip to content

Commit

Permalink
feat: add new paged metadataNames call (#837)
Browse files Browse the repository at this point in the history
* feat: add new paged metadataNames call

* fix: fix naming
  • Loading branch information
cjun-coveo authored Jul 8, 2024
1 parent 2dd8ce4 commit 784b59e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/resources/Catalogs/CatalogContent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import API from '../../APICore.js';
import Resource from '../Resource.js';
import {CatalogMetadata, CatalogMetadataName, CatalogObjectType} from './CatalogInterfaces.js';
import {MetadataPageModel} from '../Sources/index.js';
import {
CatalogMetadata,
CatalogMetadataName,
CatalogMetadataNameParams,
CatalogObjectType,
} from './CatalogInterfaces.js';

export type ObjectType = {
objectType: string;
Expand All @@ -24,4 +30,10 @@ export default class CatalogContent extends Resource {
this.buildPath(`${CatalogContent.baseUrl}/${sourceId}/metadata`, objectType),
);
}

getMetadataV2(sourceId: string, params?: CatalogMetadataNameParams) {
return this.api.get<MetadataPageModel>(
this.buildPath(`${CatalogContent.baseUrl}/${sourceId}/metadata`, params),
);
}
}
18 changes: 18 additions & 0 deletions src/resources/Catalogs/CatalogInterfaces.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Paginated} from '../BaseInterfaces.js';

export interface CatalogsListOptions {
/**
* Filter that will be matched against the catalog name, description and its configuration name.
Expand Down Expand Up @@ -457,3 +459,19 @@ export interface CatalogMetadataName {
*/
metadataNames: string[];
}

export interface CatalogMetadataNameParams extends Paginated {
/**
* Object type parameter.
*/
objectType: string;
/**
* Filters applied to the returned metadata. Only applies to metadata names, not values or origins.
*/
filter?: string;

/**
* Indicate the version of MetadataName call
*/
version?: number;
}
22 changes: 22 additions & 0 deletions src/resources/Catalogs/tests/CatalogContent.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import API from '../../../APICore.js';
import CatalogContent, {ObjectType} from '../CatalogContent.js';
import {CatalogMetadataNameParams} from '../CatalogInterfaces.js';
import queryString from '#query-string';

jest.mock('../../../APICore.js');
Expand Down Expand Up @@ -55,4 +56,25 @@ describe('CatalogContent', () => {
);
});
});

describe('getMetadataV2', () => {
it('should make a GET call to the specific metadataName url', () => {
const defaultOptions: queryString.StringifyOptions = {skipEmptyString: true, skipNull: true, sort: false};
const sourceId = 'KFC';

const params: CatalogMetadataNameParams = {
objectType: 'provigo',
filter: 'a',
version: 2,
page: 0,
perPage: 100,
};

metadata.getMetadataV2(sourceId, params);
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(
`${baseUrl}/${sourceId}/metadata?${queryString.stringify(params, {...defaultOptions})}`,
);
});
});
});

0 comments on commit 784b59e

Please sign in to comment.