Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the new api call in the platform client #802

Merged
merged 7 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/resources/Tailgate/Tailgate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import API from '../../APICore.js';
cjun-coveo marked this conversation as resolved.
Show resolved Hide resolved
import Resource from '../Resource.js';
import CatalogContent from './TailgateCatalogContent/CatalogContent.js';

export default class Tailgate extends Resource {
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/tailgate`;

metadata: CatalogContent;

constructor(
protected api: API,
protected serverlessApi: API,
) {
super(api, serverlessApi);

this.metadata = new CatalogContent(api, serverlessApi);
}

getWorkerCount() {
return this.api.get(`${Tailgate.baseUrl}/workers/count`);
}
}
18 changes: 18 additions & 0 deletions src/resources/Tailgate/TailgateCatalogContent/CatalogContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Resource from '../../Resource.js';
cjun-coveo marked this conversation as resolved.
Show resolved Hide resolved
import API from '../../../APICore.js';

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: string) {
return this.api.get(this.buildPath(`${CatalogContent.baseUrl}/${sourceId}/metadatavalues`, objectType));
cjun-coveo marked this conversation as resolved.
Show resolved Hide resolved
}

getMetadata(sourceId: string, objectType: string) {
return this.api.get(this.buildPath(`${CatalogContent.baseUrl}/${sourceId}/metadata`, objectType));
cjun-coveo marked this conversation as resolved.
Show resolved Hide resolved
}
}
1 change: 1 addition & 0 deletions src/resources/Tailgate/TailgateCatalogContent/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './CatalogContent.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import API from '../../../../APICore.js';
import CatalogContent 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: any = '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: any = 'Provigo';

metadata.getMetadata(sourceId, objectType);
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(
`${baseUrl}/${sourceId}/metadata?${queryString.stringify(objectType, {...defaultOptions})}`,
);
});
});
});
2 changes: 2 additions & 0 deletions src/resources/Tailgate/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Tailgate.js';
export * from './TailgateCatalogContent/index.js';
25 changes: 25 additions & 0 deletions src/resources/Tailgate/tests/Tailgate.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import API from '../../../APICore.js';
import Tailgate from '../Tailgate.js';

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

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

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

beforeEach(() => {
jest.clearAllMocks();
tailgate = new Tailgate(api, serverlessApi);
});

describe('get', () => {
it('should make a GET call to the specific Tailgate url', () => {
tailgate.getWorkerCount();
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`/rest/organizations/${API.orgPlaceholder}/tailgate/workers/count`);
});
});
});
Loading