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

feat(sources): add new endpoint to retrieve list of sources according to a list of IDs #799

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions src/resources/Sources/Sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ export default class Sources extends Resource {
);
}

/**
* Returns a list of sources according to an operational status and a list of source IDs
*
* @param {ListOperationalStatusSourcesParams} params
* @returns {Promise<PageModel<SourceModel, 'sourceModels'>>} A paginated list of IDs
*/
listOperationalStatusBySourceIds(
params?: ListOperationalStatusSourcesParams,
sourceIds?: string[],
): Promise<PageModel<SourceModel, 'sourceModels'>> {
return this.api.post<PageModel<SourceModel, 'sourceModels'>>(
this.buildPath(`${Sources.baseUrl}/sourceoperationalstatus/ids`, params),
sourceIds,
);
}

createFromRaw(rawSourceConfig: RawSourceConfig, options?: CreateSourceOptions) {
return this.api.post<{id: string}>(this.buildPath(`${Sources.baseUrl}/raw`, options), rawSourceConfig);
}
Expand Down
24 changes: 23 additions & 1 deletion src/resources/Sources/tests/Sources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import {ActivityOperation} from '../../Enums.js';
import {ScheduleModel} from '../../SecurityCache/index.js';
import Sources from '../Sources.js';
import SourcesFields from '../SourcesFields/SourcesFields.js';
import {CreateSourceModel, ListSourcesParams, RawSourceConfig} from '../SourcesInterfaces.js';
import {
CreateSourceModel,
ListOperationalStatusSourcesParams,
ListSourcesParams,
RawSourceConfig,
} from '../SourcesInterfaces.js';
import SourcesMappings from '../SourcesMappings/SourcesMappings.js';

jest.mock('../../../APICore.js');
Expand Down Expand Up @@ -56,6 +61,23 @@ describe('Sources', () => {
});
});

describe('listOperationalStatusBySourceIds', () => {
it('should make a POST call to the specific Sources url', () => {
const mockParams = {
page: 0,
perPage: 50,
} as ListOperationalStatusSourcesParams;
const mockSourceIds = ['source-1', 'source-2'];

source.listOperationalStatusBySourceIds(mockParams, mockSourceIds);
expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(
`${Sources.baseUrl}/sourceoperationalstatus/ids?page=0&perPage=50`,
mockSourceIds,
);
});
});

describe('createFromRaw', () => {
it('should make a POST call to the specific Sources url', () => {
const rawSource: RawSourceConfig = {};
Expand Down
Loading