From 4aa44909333dfabcce3d4315a4c81003aa94ad96 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Fri, 14 Jun 2019 09:24:54 -0400 Subject: [PATCH] add test coverage for api notification mixin --- __tests__/api/organizations.test.jsx | 3 +++ __tests__/api/reusable.jsx | 34 +++++++++++++++++++++++++++ src/api/mixins/Notifications.mixin.js | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 __tests__/api/reusable.jsx diff --git a/__tests__/api/organizations.test.jsx b/__tests__/api/organizations.test.jsx index 249661c634..1b7fc1b6f6 100644 --- a/__tests__/api/organizations.test.jsx +++ b/__tests__/api/organizations.test.jsx @@ -1,4 +1,5 @@ import Organizations from '../../src/api/models/Organizations'; +import { describeNotificationMixin } from './reusable'; describe('OrganizationsAPI', () => { const orgId = 1; @@ -34,3 +35,5 @@ describe('OrganizationsAPI', () => { done(); }); }); + +describeNotificationMixin(Organizations, 'Organizations[NotificationsMixin]'); diff --git a/__tests__/api/reusable.jsx b/__tests__/api/reusable.jsx new file mode 100644 index 0000000000..11f9fca7c7 --- /dev/null +++ b/__tests__/api/reusable.jsx @@ -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(); + }); + }); + }); +} diff --git a/src/api/mixins/Notifications.mixin.js b/src/api/mixins/Notifications.mixin.js index bbc9048ad2..85e37dc3f3 100644 --- a/src/api/mixins/Notifications.mixin.js +++ b/src/api/mixins/Notifications.mixin.js @@ -51,7 +51,7 @@ const NotificationsMixin = (parent) => class extends parent { } if (notificationType === 'error' && associationState === false) { - return this.disassociateNotificationTemplatesSuccess(resourceId, notificationId); + return this.disassociateNotificationTemplatesError(resourceId, notificationId); } throw new Error(`Unsupported notificationType, associationState combination: ${notificationType}, ${associationState}`);