diff --git a/src/resources/Catalogs/CatalogContent.ts b/src/resources/Catalogs/CatalogContent.ts new file mode 100644 index 000000000..6ad2b057d --- /dev/null +++ b/src/resources/Catalogs/CatalogContent.ts @@ -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)); + } +} diff --git a/src/resources/Catalogs/index.ts b/src/resources/Catalogs/index.ts index 48a3da4e9..41fc6a971 100644 --- a/src/resources/Catalogs/index.ts +++ b/src/resources/Catalogs/index.ts @@ -5,3 +5,4 @@ export * from './ProductListing.js'; export * from './ProductListingInterfaces.js'; export * from './ProductListingConfiguration.js'; export * from './ProductListingConfigurationInterfaces.js'; +export * from './CatalogContent.js'; diff --git a/src/resources/Catalogs/tests/CatalogContent.spec.ts b/src/resources/Catalogs/tests/CatalogContent.spec.ts new file mode 100644 index 000000000..abcb722ca --- /dev/null +++ b/src/resources/Catalogs/tests/CatalogContent.spec.ts @@ -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 as any; + +describe('CatalogContent', () => { + let metadata: CatalogContent; + const api = new APIMock() as jest.Mocked; + const serverlessApi = new APIMock() as jest.Mocked; + + 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})}`, + ); + }); + }); +}); diff --git a/src/resources/PlatformResources.ts b/src/resources/PlatformResources.ts index 7840fa4d9..7d80c96da 100644 --- a/src/resources/PlatformResources.ts +++ b/src/resources/PlatformResources.ts @@ -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}, @@ -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}, @@ -165,6 +167,7 @@ class PlatformResources { vault: Vaults; project: Project; resources: Resources; + catalogContent: CatalogContent; registerAll() { resourcesMap.forEach(({key, resource}) => {