Skip to content

Commit

Permalink
feat(sources): add call to feedback endpoint
Browse files Browse the repository at this point in the history
[CTCORE-10099]
  • Loading branch information
ClaudineL committed Jun 19, 2024
1 parent 2d5e19f commit c7adfcd
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/resources/Enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1159,3 +1159,7 @@ export enum ProductsSortByType {
fields = 'fields',
relevance = 'relevance',
}

export enum FeedbackConsumerType {
SOURCE_MANAGEMENT_IMPROVEMENTS = 'SOURCE_MANAGEMENT_IMPROVEMENTS',
}
12 changes: 12 additions & 0 deletions src/resources/Sources/SourcesFeedback/SourcesFeedback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import API from '../../../APICore.js';
import {FeedbackConsumerType} from '../../Enums.js';
import Resource from '../../Resource.js';
import {FeedbackPayload} from './SourcesFeedbackInterfaces.js';

export default class SourcesFeedback extends Resource {
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/sources/feedback`;

sendFeedback(feedbackConsumerType: FeedbackConsumerType, feedbackPayload: FeedbackPayload) {
return this.api.post(this.buildPath(SourcesFeedback.baseUrl, {feedbackConsumerType}), feedbackPayload);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface FeedbackPayload {
message: string;
}
2 changes: 2 additions & 0 deletions src/resources/Sources/SourcesFeedback/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './SourcesFeedback.js';
export * from './SourcesFeedbackInterfaces.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import API from '../../../../APICore.js';
import {FeedbackConsumerType} from '../../../Enums.js';
import SourcesFeedback from '../SourcesFeedback.js';
import {FeedbackPayload} from '../SourcesFeedbackInterfaces.js';

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

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

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

beforeEach(() => {
jest.clearAllMocks();
sourceFeedback = new SourcesFeedback(api, serverlessApi);
});

describe('sendFeedback', () => {
it('should make a POST call to the specific feedback url', () => {
const feedback = {message: 'allo!'} as FeedbackPayload;
sourceFeedback.sendFeedback(FeedbackConsumerType.SOURCE_MANAGEMENT_IMPROVEMENTS, feedback);
expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(
`${SourcesFeedback.baseUrl}?feedbackConsumerType=SOURCE_MANAGEMENT_IMPROVEMENTS`,
feedback,
);
});
});
});

0 comments on commit c7adfcd

Please sign in to comment.