mirror of
https://github.com/ansible/awx.git
synced 2026-03-09 13:39:27 -02:30
add test coverage for api notification mixin
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import Organizations from '../../src/api/models/Organizations';
|
import Organizations from '../../src/api/models/Organizations';
|
||||||
|
import { describeNotificationMixin } from './reusable';
|
||||||
|
|
||||||
describe('OrganizationsAPI', () => {
|
describe('OrganizationsAPI', () => {
|
||||||
const orgId = 1;
|
const orgId = 1;
|
||||||
@@ -34,3 +35,5 @@ describe('OrganizationsAPI', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describeNotificationMixin(Organizations, 'Organizations[NotificationsMixin]');
|
||||||
|
|||||||
34
__tests__/api/reusable.jsx
Normal file
34
__tests__/api/reusable.jsx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// eslint-disable-next-line import/prefer-default-export
|
||||||
|
export function describeNotificationMixin (Model, name) {
|
||||||
|
describe(name, () => {
|
||||||
|
const mockHttp = ({ post: jest.fn(() => Promise.resolve()) });
|
||||||
|
const ModelAPI = new Model(mockHttp);
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
const parameters = [
|
||||||
|
['success', true],
|
||||||
|
['success', false],
|
||||||
|
['error', true],
|
||||||
|
['error', false],
|
||||||
|
];
|
||||||
|
parameters.forEach(([type, state]) => {
|
||||||
|
const label = `[notificationType=${type}, associationState=${state}]`;
|
||||||
|
const testName = `updateNotificationTemplateAssociation ${label} makes expected http calls`;
|
||||||
|
|
||||||
|
test(testName, async (done) => {
|
||||||
|
await ModelAPI.updateNotificationTemplateAssociation(1, 21, type, state);
|
||||||
|
|
||||||
|
const expectedPath = `${ModelAPI.baseUrl}1/notification_templates_${type}/`;
|
||||||
|
expect(mockHttp.post).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
const expectedParams = state ? { id: 21 } : { id: 21, disassociate: true };
|
||||||
|
expect(mockHttp.post.mock.calls.pop()).toEqual([expectedPath, expectedParams]);
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -51,7 +51,7 @@ const NotificationsMixin = (parent) => class extends parent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (notificationType === 'error' && associationState === false) {
|
if (notificationType === 'error' && associationState === false) {
|
||||||
return this.disassociateNotificationTemplatesSuccess(resourceId, notificationId);
|
return this.disassociateNotificationTemplatesError(resourceId, notificationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(`Unsupported notificationType, associationState combination: ${notificationType}, ${associationState}`);
|
throw new Error(`Unsupported notificationType, associationState combination: ${notificationType}, ${associationState}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user