Skip to content

Commit 8d52e87

Browse files
committed
fix(tests): resolve all pre-existing tests failing
1 parent a250348 commit 8d52e87

41 files changed

Lines changed: 567 additions & 842 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/controllers/generalProject.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const generateGeneralProjectData = async (
9292

9393
// Create activity and link contact if required
9494
if (!activityId) {
95-
activityId = (await createActivity(tx, Initiative.GENERAL, generateCreateStamps(currentContext)))?.activityId;
95+
activityId = (await createActivity(tx, Initiative.GENERAL, generateCreateStamps(currentContext))).activityId;
9696
const contacts = await searchContacts(tx, { userId: [currentContext.userId!] });
9797
if (contacts[0]) await createActivityContact(tx, activityId, contacts[0].contactId, ActivityContactRole.PRIMARY);
9898
}
@@ -108,7 +108,8 @@ const generateGeneralProjectData = async (
108108
companyNameRegistered: data.basic.registeredName,
109109
projectName: data.basic.projectName,
110110
projectNumber: data.basic.projectNumber,
111-
projectDescription: data.basic.projectDescription
111+
projectDescription: data.basic.projectDescription,
112+
isRegisteredInBc: data.basic.registeredId !== null
112113
};
113114
}
114115

@@ -208,7 +209,11 @@ const generateGeneralProjectData = async (
208209
astNotes: null,
209210
atsClientId: null,
210211
checkProvincialPermits: null,
211-
atsEnquiryId: null
212+
atsEnquiryId: null,
213+
region: null,
214+
area: null,
215+
activityType: null,
216+
businessArea: null
212217
} as GeneralProject,
213218
appliedPermits,
214219
investigatePermits

app/src/services/generalProject.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Prisma } from '@prisma/client';
22

3-
import { jsonToPrismaInputJson } from '../db/utils/utils.ts';
4-
53
import type { PrismaTransactionClient } from '../db/dataConnection.ts';
64
import type { IStamps } from '../interfaces/IStamps.ts';
75
import type {

app/src/types/models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export type EscalationTypeCode = EscalationTypeCodeBase;
6060

6161
const generalProjectBase = Prisma.validator<Prisma.general_projectDefaultArgs>()({});
6262
export type GeneralProjectBase = Prisma.general_projectGetPayload<typeof generalProjectBase>;
63-
export type GeneralProject = GeneralProjectBase & { activity?: Activity; user?: User | null };
63+
export type GeneralProject = GeneralProjectBase & { activity?: Activity; projectId?: string; user?: User | null };
6464

6565
const housingProjectBase = Prisma.validator<Prisma.housing_projectDefaultArgs>()({});
6666
export type HousingProjectBase = Prisma.housing_projectGetPayload<typeof housingProjectBase>;

app/src/types/stuff.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ export interface GeneralProjectIntake {
214214
geomarkUrl: string | null;
215215
geoJson: Prisma.JsonValue;
216216
ltsaPidLookup: string | null;
217+
locationPids: string | null;
217218
latitude: number | null;
218219
longitude: number | null;
219220
streetAddress: string;

app/tests/unit/controllers/activityContact.spec.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ const FAKE_MEMBER_ACTIVITY_CONTACT = {
3737
};
3838
const FAKE_PRIMARY_ACTIVITY_CONTACT = { ...TEST_ACTIVITY_CONTACT_1, contact: TEST_CONTACT_1 };
3939

40+
const PROJECT_WITH_PROJECTID = {
41+
...TEST_HOUSING_PROJECT_1,
42+
projectId: TEST_HOUSING_PROJECT_1.housingProjectId
43+
};
44+
4045
const verifyPrimaryChangeSpy = jest.spyOn(activityContactHelpers, 'verifyPrimaryChange');
4146

4247
let app: express.Express;
@@ -83,9 +88,7 @@ describe('DELETE /activity/:activityId/contact/:contactId', () => {
8388
const emailSpy = jest.spyOn(emailService, 'email');
8489

8590
beforeEach(() => {
86-
getProjectByActivityIdSpy.mockResolvedValue({
87-
...TEST_HOUSING_PROJECT_1
88-
});
91+
getProjectByActivityIdSpy.mockResolvedValue(PROJECT_WITH_PROJECTID);
8992
});
9093

9194
it('should call services and respond with 204', async () => {
@@ -149,9 +152,7 @@ describe('POST /activity/:activityId/contact/:contactId', () => {
149152

150153
beforeEach(() => {
151154
searchContactsSpy.mockResolvedValue([TEST_CONTACT_1]);
152-
getProjectByActivityIdSpy.mockResolvedValue({
153-
...TEST_HOUSING_PROJECT_1
154-
});
155+
getProjectByActivityIdSpy.mockResolvedValue(PROJECT_WITH_PROJECTID);
155156
});
156157

157158
it('should call services and respond with 201 and result', async () => {
@@ -219,9 +220,7 @@ describe('PUT /activity/:activityId/contact/:contactId', () => {
219220

220221
beforeEach(() => {
221222
searchContactsSpy.mockResolvedValue([TEST_CONTACT_1]);
222-
getProjectByActivityIdSpy.mockResolvedValue({
223-
...TEST_HOUSING_PROJECT_1
224-
});
223+
getProjectByActivityIdSpy.mockResolvedValue(PROJECT_WITH_PROJECTID);
225224
});
226225

227226
it('should call services and respond with 200', async () => {

app/tests/unit/controllers/electrificationProject.spec.ts

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Prisma } from '@prisma/client';
2+
13
import {
24
TEST_CURRENT_CONTEXT,
35
TEST_ELECTRIFICATION_INTAKE,
@@ -36,7 +38,6 @@ import { uuidv4Pattern } from '../../../src/utils/regexp.ts';
3638
import type { Request, Response } from 'express';
3739
import type {
3840
ActivityContact,
39-
Contact,
4041
Draft,
4142
ElectrificationProject,
4243
ElectrificationProjectIntake,
@@ -570,28 +571,46 @@ describe('updateElectrificationProjectDraftController', () => {
570571
describe('updateElectrificationProjectController', () => {
571572
const updateSpy = jest.spyOn(electrificationProjectService, 'updateElectrificationProject');
572573

574+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
575+
const { electrificationProjectId, ...rest } = TEST_ELECTRIFICATION_PROJECT_1;
576+
577+
const UPDATED_BODY: Omit<ElectrificationProject, 'electrificationProjectId'> = {
578+
...rest,
579+
projectName: 'NEW NAME'
580+
};
581+
const UPDATED_PROJECT: ElectrificationProject = { ...TEST_ELECTRIFICATION_PROJECT_1, projectName: 'NEW NAME' };
582+
573583
it('should call services and respond with 200 and result', async () => {
574584
const req = {
575-
body: { project: TEST_ELECTRIFICATION_PROJECT_1 },
576-
currentContext: TEST_CURRENT_CONTEXT
585+
body: UPDATED_BODY,
586+
currentContext: TEST_CURRENT_CONTEXT,
587+
params: {
588+
electrificationProjectId: TEST_ELECTRIFICATION_PROJECT_1.electrificationProjectId
589+
}
577590
};
578591

579-
const updated: ElectrificationProject = { ...TEST_ELECTRIFICATION_PROJECT_1, projectName: 'NEW NAME' };
580-
581-
updateSpy.mockResolvedValue(updated);
592+
updateSpy.mockResolvedValue(UPDATED_PROJECT);
582593

583594
await updateElectrificationProjectController(
584-
req as unknown as Request<never, never, { project: ElectrificationProject; contacts: Contact[] }>,
595+
req as unknown as Request<
596+
{ electrificationProjectId: string },
597+
never,
598+
Omit<Prisma.electrification_projectUpdateInput, 'electrificationProjectId'>
599+
>,
585600
res as unknown as Response
586601
);
587602

588603
expect(updateSpy).toHaveBeenCalledTimes(1);
589-
expect(updateSpy).toHaveBeenCalledWith(prismaTxMock, {
590-
...req.body.project,
591-
updatedAt: expect.any(Date) as Date,
592-
updatedBy: TEST_CURRENT_CONTEXT.userId
593-
});
604+
expect(updateSpy).toHaveBeenCalledWith(
605+
prismaTxMock,
606+
{
607+
...UPDATED_BODY,
608+
updatedAt: expect.any(Date) as Date,
609+
updatedBy: TEST_CURRENT_CONTEXT.userId
610+
},
611+
UPDATED_PROJECT.electrificationProjectId
612+
);
594613
expect(res.status).toHaveBeenCalledWith(200);
595-
expect(res.json).toHaveBeenCalledWith(updated);
614+
expect(res.json).toHaveBeenCalledWith(UPDATED_PROJECT);
596615
});
597616
});

app/tests/unit/controllers/enquiry.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ describe('createEnquiryController', () => {
6565
currentContext: TEST_CURRENT_CONTEXT
6666
};
6767

68+
const PROJECT_WITH_PROJECTID = {
69+
...TEST_HOUSING_PROJECT_1,
70+
projectId: TEST_HOUSING_PROJECT_1.housingProjectId
71+
};
72+
6873
createActivitySpy.mockResolvedValue(TEST_ACTIVITY_ELECTRIFICATION);
6974
searchContactsSpy.mockResolvedValue([TEST_CONTACT_1]);
7075
createActivityContactSpy.mockResolvedValue({
@@ -79,7 +84,7 @@ describe('createEnquiryController', () => {
7984
]);
8085
upsertContactsSpy.mockResolvedValue([TEST_CONTACT_1]);
8186
createEnquirySpy.mockResolvedValue(TEST_ENQUIRY_1);
82-
getProjectByActivityIdSpy.mockResolvedValue(TEST_HOUSING_PROJECT_1);
87+
getProjectByActivityIdSpy.mockResolvedValue(PROJECT_WITH_PROJECTID);
8388

8489
await createEnquiryController(req as unknown as Request<never, never, EnquiryIntake>, res as unknown as Response);
8590

app/tests/unit/controllers/generalProject.spec.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Prisma } from '@prisma/client';
2+
13
import {
24
createGeneralProjectController,
35
deleteGeneralProjectController,
@@ -754,27 +756,45 @@ describe('updateGeneralProjectDraftController', () => {
754756
describe('updateGeneralProjectController', () => {
755757
const updateSpy = jest.spyOn(generalProjectService, 'updateGeneralProject');
756758

759+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
760+
const { generalProjectId, ...rest } = TEST_GENERAL_PROJECT_1;
761+
762+
const UPDATED_BODY: Omit<GeneralProject, 'generalProjectId'> = {
763+
...rest,
764+
projectName: 'NEW NAME'
765+
};
757766
const UPDATED_PROJECT: GeneralProject = { ...TEST_GENERAL_PROJECT_1, projectName: 'NEW NAME' };
758767

759768
it('should call services and respond with 200 and result', async () => {
760769
const req = {
761-
body: UPDATED_PROJECT,
762-
currentContext: TEST_CURRENT_CONTEXT
770+
body: UPDATED_BODY,
771+
currentContext: TEST_CURRENT_CONTEXT,
772+
params: {
773+
generalProjectId: UPDATED_PROJECT.generalProjectId
774+
}
763775
};
764776

765777
updateSpy.mockResolvedValue(UPDATED_PROJECT);
766778

767779
await updateGeneralProjectController(
768-
req as unknown as Request<never, never, GeneralProject>,
780+
req as unknown as Request<
781+
{ generalProjectId: string },
782+
never,
783+
Omit<Prisma.general_projectUpdateInput, 'generalProjectId'>
784+
>,
769785
res as unknown as Response
770786
);
771787

772788
expect(updateSpy).toHaveBeenCalledTimes(1);
773-
expect(updateSpy).toHaveBeenCalledWith(prismaTxMock, {
774-
...UPDATED_PROJECT,
775-
updatedAt: expect.any(Date) as Date,
776-
updatedBy: TEST_CURRENT_CONTEXT.userId
777-
});
789+
expect(updateSpy).toHaveBeenCalledWith(
790+
prismaTxMock,
791+
{
792+
...UPDATED_BODY,
793+
updatedAt: expect.any(Date) as Date,
794+
updatedBy: TEST_CURRENT_CONTEXT.userId
795+
},
796+
UPDATED_PROJECT.generalProjectId
797+
);
778798
expect(res.status).toHaveBeenCalledWith(200);
779799
expect(res.json).toHaveBeenCalledWith(UPDATED_PROJECT);
780800
});

0 commit comments

Comments
 (0)