Skip to content

Commit

Permalink
Fix tests and licence headers
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhand committed Nov 21, 2024
1 parent f095ebd commit 8fa4e5a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
10 changes: 5 additions & 5 deletions hrm-domain/hrm-core/unit-tests/case/caseService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import { workerSid, accountSid } from '../mocks';
import { newTwilioUser } from '@tech-matters/twilio-worker-auth';
import { rulesMap } from '../../permissions';
import { RulesFile } from '../../permissions/rulesMap';
import * as publishToSearchIndex from '../../jobs/search/publishToSearchIndex';
import * as entityChangeNotify from '../../notifications/entityChangeNotify';

const publishToSearchIndexSpy = jest
.spyOn(publishToSearchIndex, 'publishCaseToSearchIndex')
.mockImplementation(async () => Promise.resolve('Ok') as any);
const publishCaseChangeNotificationSpy = jest
.spyOn(entityChangeNotify, 'publishCaseChangeNotification')
.mockImplementation(() => Promise.resolve('Ok') as any);

jest.mock('../../case/caseDataAccess');
const baselineCreatedDate = new Date(2013, 6, 13).toISOString();
Expand Down Expand Up @@ -77,7 +77,7 @@ test('create case', async () => {
});

await new Promise(process.nextTick);
expect(publishToSearchIndexSpy).toHaveBeenCalled();
expect(publishCaseChangeNotificationSpy).toHaveBeenCalled();
});

describe('searchCases', () => {
Expand Down
26 changes: 13 additions & 13 deletions hrm-domain/hrm-core/unit-tests/contact/contactService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ import { ALWAYS_CAN, OPEN_CONTACT_ACTION_CONDITIONS } from '../mocks';
import '@tech-matters/testing/expectToParseAsDate';
import { openPermissions } from '../../permissions/json-permissions';
import { RulesFile, TKConditionsSets } from '../../permissions/rulesMap';
import * as publishToSearchIndex from '../../jobs/search/publishToSearchIndex';
import * as entityChangeNotify from '../../notifications/entityChangeNotify';

const flushPromises = async () => {
await new Promise(process.nextTick);
await new Promise(process.nextTick);
await new Promise(process.nextTick);
};

const publishToSearchIndexSpy = jest
.spyOn(publishToSearchIndex, 'publishContactToSearchIndex')
.mockImplementation(async () => Promise.resolve('Ok') as any);
const publishContactChangeNotificationSpy = jest
.spyOn(entityChangeNotify, 'publishContactChangeNotification')
.mockImplementation(() => Promise.resolve('Ok') as any);

const accountSid = 'AC-accountSid';
const workerSid = 'WK-WORKER_SID';
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('createContact', () => {
});

await flushPromises();
expect(publishToSearchIndexSpy).toHaveBeenCalled();
expect(publishContactChangeNotificationSpy).toHaveBeenCalled();
expect(returnValue).toStrictEqual(mockContact);
});

Expand Down Expand Up @@ -191,7 +191,7 @@ describe('createContact', () => {
});

await flushPromises();
expect(publishToSearchIndexSpy).toHaveBeenCalled();
expect(publishContactChangeNotificationSpy).toHaveBeenCalled();
expect(returnValue).toStrictEqual(mockContact);
});

Expand Down Expand Up @@ -227,7 +227,7 @@ describe('createContact', () => {
});

await flushPromises();
expect(publishToSearchIndexSpy).toHaveBeenCalled();
expect(publishContactChangeNotificationSpy).toHaveBeenCalled();
expect(returnValue).toStrictEqual(mockContact);
});

Expand All @@ -250,7 +250,7 @@ describe('createContact', () => {
});

await flushPromises();
expect(publishToSearchIndexSpy).toHaveBeenCalled();
expect(publishContactChangeNotificationSpy).toHaveBeenCalled();
expect(returnValue).toStrictEqual(mockContact);
});

Expand All @@ -274,7 +274,7 @@ describe('createContact', () => {
});

await flushPromises();
expect(publishToSearchIndexSpy).toHaveBeenCalled();
expect(publishContactChangeNotificationSpy).toHaveBeenCalled();
expect(returnValue).toStrictEqual(mockContact);
});
});
Expand All @@ -294,7 +294,7 @@ describe('connectContactToCase', () => {
);

await flushPromises();
expect(publishToSearchIndexSpy).toHaveBeenCalled();
expect(publishContactChangeNotificationSpy).toHaveBeenCalled();
expect(result).toStrictEqual(mockContact);
});

Expand All @@ -305,7 +305,7 @@ describe('connectContactToCase', () => {
expect(
connectContactToCase(accountSid, '1234', '4321', ALWAYS_CAN),
).rejects.toThrow();
expect(publishToSearchIndexSpy).not.toHaveBeenCalled();
expect(publishContactChangeNotificationSpy).not.toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -343,7 +343,7 @@ describe('patchContact', () => {
);

await flushPromises();
expect(publishToSearchIndexSpy).toHaveBeenCalled();
expect(publishContactChangeNotificationSpy).toHaveBeenCalled();
expect(result).toStrictEqual(mockContact);
expect(patchSpy).toHaveBeenCalledWith(accountSid, '1234', true, {
updatedBy: contactPatcherSid,
Expand All @@ -368,7 +368,7 @@ describe('patchContact', () => {
jest.spyOn(contactDb, 'patch').mockReturnValue(patchSpy);
patchSpy.mockResolvedValue(undefined);

expect(publishToSearchIndexSpy).not.toHaveBeenCalled();
expect(publishContactChangeNotificationSpy).not.toHaveBeenCalled();
expect(
patchContact(accountSid, contactPatcherSid, true, '1234', samplePatch, ALWAYS_CAN),
).rejects.toThrow();
Expand Down
16 changes: 16 additions & 0 deletions hrm-domain/packages/hrm-types/NotificationOperation.ts
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
/**
* Copyright (C) 2021-2023 Technology Matters
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/

export type NotificationOperation = 'update' | 'create' | 'delete' | 'reindex';

0 comments on commit 8fa4e5a

Please sign in to comment.