Skip to content

Commit

Permalink
Merge branch 'master' into CHI-3207-single_case_section_permission
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhand committed Feb 4, 2025
2 parents 75f41c9 + 281c05d commit 96c3a22
Show file tree
Hide file tree
Showing 49 changed files with 26,392 additions and 2,114 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/hrm-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,15 @@ jobs:
run: npm run build

- name: Run Unit Tests
run: npm run test:unit
run: npm run test:unit:ci

- name: Publish Test Reports
uses: dorny/test-reporter@v1
if: success() || failure() # always run even if the previous step fails
with:
name: Unit Tests Report
path: '!(node_modules)/**/junit.xml'
reporter: jest-junit
service-tests:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -153,3 +160,11 @@ jobs:

- name: Run Service Tests
run: npm run test:service:ci

- name: Publish Test Reports
uses: dorny/test-reporter@v1
if: success() || failure() # always run even if the previous step fails
with:
name: Service Tests Report
path: '!(node_modules)/**/junit.xml'
reporter: jest-junit
30 changes: 27 additions & 3 deletions hrm-domain/hrm-core/contact/contactService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
AccountSID,
HrmAccountId,
TwilioUserIdentifier,
ErrorResult,
} from '@tech-matters/types';
import { getClient } from '@tech-matters/elasticsearch-client';
import {
Expand Down Expand Up @@ -209,6 +210,9 @@ const createContactInSearchIndex = doContactChangeNotification('create');
const updateContactInSearchIndex = doContactChangeNotification('update');
const deleteContactInSearchIndex = doContactChangeNotification('delete');

type InvalidParameterError = ErrorResult<'InvalidParameterError'>;
type CreateError = DatabaseErrorResult | InvalidParameterError;

// Creates a contact with all its related records within a single transaction
export const createContact = async (
accountSid: HrmAccountId,
Expand All @@ -217,15 +221,25 @@ export const createContact = async (
{ can, user }: { can: InitializedCan; user: TwilioUser },
skipSearchIndex = false,
): Promise<Contact> => {
let result: Result<DatabaseErrorResult, Contact>;
let result: Result<CreateError, Contact>;
for (let retries = 1; retries < 4; retries++) {
result = await ensureRejection<DatabaseErrorResult, Contact>(db.tx)(async conn => {
result = await ensureRejection<CreateError, Contact>(db.tx)(async conn => {
const res = await initProfile(conn, accountSid, newContact);
if (isErr(res)) {
return res;
}
const { profileId, identifierId } = res.data;

const definitionVersion =
newContact.definitionVersion || newContact.rawJson.definitionVersion;

if (!definitionVersion) {
return newErr({
error: 'InvalidParameterError',
message: 'creteContact error: missing definition version parameter',
});
}

const completeNewContact: NewContactRecord = {
...newContact,
helpline: newContact.helpline ?? '',
Expand All @@ -245,6 +259,7 @@ export const createContact = async (
// Hardcoded to first profile for now, but will be updated to support multiple profiles
profileId,
identifierId,
definitionVersion,
};
const contactCreateResult = await create(conn)(accountSid, completeNewContact);
if (isErr(contactCreateResult)) {
Expand Down Expand Up @@ -336,7 +351,16 @@ export const patchContact = async (
// trigger index operation but don't await for it

if (!skipSearchIndex) {
updateContactInSearchIndex({ accountSid, contactId: parseInt(contactId, 10) });
if (
updated.taskId?.startsWith('offline-contact-task-') &&
!updated.rawJson.callType &&
!updated.finalizedAt
) {
// If the task is an offline contact task and the call type is not set, this is a 'reset' contact, effectively deleted, so we should remove it from the index
deleteContactInSearchIndex({ accountSid, contactId: parseInt(contactId, 10) });
} else {
updateContactInSearchIndex({ accountSid, contactId: parseInt(contactId, 10) });
}
}

return applyTransformations(updated);
Expand Down
6 changes: 4 additions & 2 deletions hrm-domain/hrm-core/contact/sql/contactInsertSql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export const INSERT_CONTACT_SQL = `
"channelSid",
"serviceSid",
"profileId",
"identifierId"
"identifierId",
"definitionVersion"
) (SELECT
$<accountSid>,
$<rawJson>,
Expand All @@ -58,7 +59,8 @@ export const INSERT_CONTACT_SQL = `
$<channelSid>,
$<serviceSid>,
$<profileId>,
$<identifierId>
$<identifierId>,
$<definitionVersion>
WHERE NOT EXISTS (
${selectSingleContactByTaskId('Contacts')}
)
Expand Down
1 change: 1 addition & 0 deletions hrm-domain/hrm-core/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = config => {
useExperimentalLanguageServer: true,
},
},
reporters: ['default', 'jest-junit'],
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('create', () => {
channelSid: undefined,
serviceSid: undefined,
isNewRecord: true,
definitionVersion: 'as-v1',
};

test('Task ID specified in payload that is already associated with a contact - returns that contact', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ describe('createContact', () => {
number: "that's numberwang",
channelSid: 'a channel',
serviceSid: 'a service',
definitionVersion: 'as-v1',
};

const spyOnContact = ({
Expand Down
1 change: 1 addition & 0 deletions hrm-domain/hrm-service/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = config => {
useExperimentalLanguageServer: true,
},
},
reporters: ['default', 'jest-junit'],
}
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 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/.
*/
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async queryInterface => {
await queryInterface.sequelize.query(`
ALTER TABLE "Contacts" ADD COLUMN IF NOT EXISTS "definitionVersion" TEXT;
`);
console.log('"definitionVersion" column added to table "Contacts"');

await queryInterface.sequelize.query(`
UPDATE "Contacts" SET "definitionVersion" = "rawJson"->>'definitionVersion';
`);
console.log('"definitionVersion" column populated in table "Contacts"');
},
down: async queryInterface => {
await queryInterface.sequelize.query(`
ALTER TABLE public."Contacts"
DROP COLUMN IF EXISTS "definitionVersion";
`);
console.log('"definitionVersion" column dropped from table "Contacts"');
},
};
2 changes: 1 addition & 1 deletion hrm-domain/hrm-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"test:service:run": "cross-env AWS_REGION=us-east-1 SSM_ENDPOINT=http://mock-ssm/ jest --verbose --maxWorkers=1 --forceExit service-tests",
"test:service:ci": "run-s test:service:ci:migrate test:service:ci:run",
"test:service:ci:migrate": "cross-env CI=true RDS_PASSWORD=postgres node ./db-migrate",
"test:service:ci:run": "cross-env AWS_REGION=us-east-1 SSM_ENDPOINT=http://mock-ssm/ CI=true TWILIO_ACCOUNT_SID=ACxxx TWILIO_AUTH_TOKEN=xxxxxx RDS_PASSWORD=postgres jest --verbose --maxWorkers=1 --forceExit service-tests",
"test:service:ci:run": "cross-env AWS_REGION=us-east-1 SSM_ENDPOINT=http://mock-ssm/ CI=true TWILIO_ACCOUNT_SID=ACxxx TWILIO_AUTH_TOKEN=xxxxxx RDS_PASSWORD=postgres jest --verbose --maxWorkers=1 --forceExit --coverage service-tests",
"test:coverage": "run-s docker:compose:test:up test:service:ci:migrate test:coverage:run docker:compose:test:down",
"test:coverage:run": "cross-env POSTGRES_PORT=5433 AWS_REGION=us-east-1 jest --verbose --maxWorkers=1 --coverage",
"test:migrate": "run-s test:service:ci:migrate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ describe('isCaseContactOwner condition', () => {
},
queueName: 'buh',
conversationDuration: 0,
definitionVersion: 'as-v1',
},
ALWAYS_CAN,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const createContact = async (
helpline: 'helpline',
conversationDuration: 5,
serviceSid: 'ISxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
definitionVersion: 'as-v1',
},
ALWAYS_CAN,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ each([
taskId: 'empty-contact-tasksid',
channelSid: null,
serviceSid: null,
definitionVersion: 'as-v1',
},
expectedGetContact: {
rawJson: {} as ContactRawJson,
Expand Down
3 changes: 3 additions & 0 deletions hrm-domain/hrm-service/service-tests/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const contact1: NewContactRecord = {
conversationDuration: 14,
profileId: undefined,
identifierId: undefined,
definitionVersion: 'as-v1',
};

export const contact2: NewContactRecord = {
Expand Down Expand Up @@ -148,6 +149,7 @@ export const contact2: NewContactRecord = {
conversationDuration: 10,
profileId: undefined,
identifierId: undefined,
definitionVersion: 'as-v1',
};

export const nonData1: NewContactRecord = {
Expand Down Expand Up @@ -262,6 +264,7 @@ export const withTaskId: NewContactRecord = {
taskId: 'taskId',
profileId: undefined,
identifierId: undefined,
definitionVersion: 'as-v1',
};
export type CaseSectionInsert = {
section: NewCaseSection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const createContact = async (twilioWorkerId: WorkerSID): Promise<contactDb.Conta
helpline: 'helpline',
conversationDuration: 5,
serviceSid: 'ISxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
definitionVersion: 'as-v1',
},
ALWAYS_CAN,
);
Expand Down
1 change: 1 addition & 0 deletions hrm-domain/integration-tests/transcripts/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = config => {
},
},
setupFiles: ['<rootDir>/src/setTestEnvVars.js'],
reporters: ['default', 'jest-junit'],
}
);
};
1 change: 1 addition & 0 deletions hrm-domain/integration-tests/transcripts/src/contactDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const createContact = async (newContact: NewContactRecord): Promise<Conta
const { isNewRecord, ...created }: CreateResultRecord =
await conn.one<CreateResultRecord>(INSERT_CONTACT_SQL, {
...newContact,
definitionVersion: 'as-v1',
identifierId: identifier.id,
profileId: profile.id,
accountSid: ACCOUNT_SID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const MINIMAL_CONTACT: NewContactRecord = {
twilioWorkerId: 'WK-integration-test-counselor',
taskId: 'TK-integration-test',

definitionVersion: 'as-v1',
helpline: '',
number: '',
timeOfContact: new Date().toISOString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = config => {
useExperimentalLanguageServer: true,
},
},
reporters: ['default', 'jest-junit'],
}
);
};
1 change: 1 addition & 0 deletions hrm-domain/lambdas/files-urls/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = config => {
useExperimentalLanguageServer: true,
},
},
reporters: ['default', 'jest-junit'],
}
);
};
1 change: 1 addition & 0 deletions hrm-domain/packages/hrm-types/Contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export type NewContactRecord = {
caseId?: CaseService['id'];
profileId?: number;
identifierId?: number;
definitionVersion: string;
};

export type ExistingContactRecord = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = config => {
useExperimentalLanguageServer: true,
},
},
reporters: ['default', 'jest-junit'],
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = config => {
useExperimentalLanguageServer: true,
},
},
reporters: ['default', 'jest-junit'],
}
);
};
1 change: 1 addition & 0 deletions hrm-domain/scheduled-tasks/hrm-data-pull/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = config => {
useExperimentalLanguageServer: true,
},
},
reporters: ['default', 'jest-junit'],
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = config => {
useExperimentalLanguageServer: true,
},
},
reporters: ['default', 'jest-junit'],
}
);
};
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = config => {
useExperimentalLanguageServer: true,
},
},
reporters: ['default', 'jest-junit'],
}
);
};
1 change: 1 addition & 0 deletions lambdas/packages/alb-handler/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = config => {
useExperimentalLanguageServer: true,
},
},
reporters: ['default', 'jest-junit'],
}
);
};
1 change: 1 addition & 0 deletions lambdas/packages/hrm-authentication/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = config => {
useExperimentalLanguageServer: true,
},
},
reporters: ['default', 'jest-junit'],
}
);
};
Loading

0 comments on commit 96c3a22

Please sign in to comment.