Skip to content

Commit

Permalink
feat: add CatalogContent resource
Browse files Browse the repository at this point in the history
  • Loading branch information
cjun-coveo authored and louis-bompart committed Mar 12, 2024
1 parent ce89008 commit 19fa274
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/resources/Catalogs/CatalogContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import API from '../../APICore.js';
import Resource from '../Resource.js';

export type ObjectType = {
objectType: string;
};

export default class CatalogContent extends Resource {
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/catalogcontent/source`;

getObjectTypes(sourceId: string) {
return this.api.get(`${CatalogContent.baseUrl}/${sourceId}/objecttypes`);
}

getMetadataValues(sourceId: string, objectType: ObjectType) {
return this.api.get(this.buildPath(`${CatalogContent.baseUrl}/${sourceId}/metadatavalues`, objectType));
}

getMetadata(sourceId: string, objectType: ObjectType) {
return this.api.get(this.buildPath(`${CatalogContent.baseUrl}/${sourceId}/metadata`, objectType));
}
}
1 change: 1 addition & 0 deletions src/resources/Catalogs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './ProductListing.js';
export * from './ProductListingInterfaces.js';
export * from './ProductListingConfiguration.js';
export * from './ProductListingConfigurationInterfaces.js';
export * from './CatalogContent.js';
58 changes: 58 additions & 0 deletions src/resources/Catalogs/tests/CatalogContent.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import API from '../../../APICore.js';
import CatalogContent, {ObjectType} from '../CatalogContent.js';
import queryString from '#query-string';

jest.mock('../../../APICore.js');

const APIMock: jest.Mock<API> = API as any;

describe('CatalogContent', () => {
let metadata: CatalogContent;
const api = new APIMock() as jest.Mocked<API>;
const serverlessApi = new APIMock() as jest.Mocked<API>;

const baseUrl = `/rest/organizations/${API.orgPlaceholder}/catalogcontent/source`;

beforeEach(() => {
jest.clearAllMocks();
metadata = new CatalogContent(api, serverlessApi);
});

describe('getObjectTypes', () => {
it('should make a GET call to the specific CatalogContent url', () => {
const sourceId = 'McDonald';

metadata.getObjectTypes(sourceId);
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${baseUrl}/${sourceId}/objecttypes`);
});
});

describe('getMetadataValues', () => {
it('should make a GET call to the specific CatalogContent url', () => {
const defaultOptions: queryString.StringifyOptions = {skipEmptyString: true, skipNull: true, sort: false};
const sourceId = 'McDonald';
const objectType: ObjectType = {objectType: 'Provigo'};

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

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

metadata.getMetadata(sourceId, objectType);
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(
`${baseUrl}/${sourceId}/metadata?${queryString.stringify(objectType, {...defaultOptions})}`,
);
});
});
});
3 changes: 3 additions & 0 deletions src/resources/PlatformResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import HostedPages from './HostedPages/HostedPages.js';
import SearchAnalysis from './SearchAnalysis/SearchAnalysis.js';
import Project from './Projects/Project.js';
import Resources from './Resources/Resources.js';
import CatalogContent from './Catalogs/CatalogContent.js';

const resourcesMap: Array<{key: string; resource: typeof Resource}> = [
{key: 'activity', resource: Activity},
Expand All @@ -60,6 +61,7 @@ const resourcesMap: Array<{key: string; resource: typeof Resource}> = [
{key: 'caseAssistConfig', resource: CaseAssistConfig},
{key: 'catalog', resource: Catalog},
{key: 'catalogConfiguration', resource: CatalogConfiguration},
{key: 'catalogContent', resource: CatalogContent},
{key: 'cluster', resource: Cluster},
{key: 'connectivity', resource: Connectivity},
{key: 'crawlingModule', resource: CrawlingModule},
Expand Down Expand Up @@ -165,6 +167,7 @@ class PlatformResources {
vault: Vaults;
project: Project;
resources: Resources;
catalogContent: CatalogContent;

registerAll() {
resourcesMap.forEach(({key, resource}) => {
Expand Down

0 comments on commit 19fa274

Please sign in to comment.