From 80da5abc02d15dffa4e7a58e7de4b2ffd4874a53 Mon Sep 17 00:00:00 2001 From: Emily Jablonski Date: Thu, 2 Jan 2025 10:03:35 -0700 Subject: [PATCH] test: unit test --- api/src/services/script-runner.service.ts | 97 ++++++++++++++++++- .../services/script-runner.service.spec.ts | 39 ++++++++ 2 files changed, 134 insertions(+), 2 deletions(-) diff --git a/api/src/services/script-runner.service.ts b/api/src/services/script-runner.service.ts index 1c485145d5..e74f888a34 100644 --- a/api/src/services/script-runner.service.ts +++ b/api/src/services/script-runner.service.ts @@ -1522,7 +1522,7 @@ export class ScriptRunnerService { prev: string, updated: HouseholdMemberRelationship, ) => { - const { count: count } = await this.prisma.householdMember.updateMany({ + const result = await this.prisma.householdMember.updateMany({ data: { relationship: updated, }, @@ -1532,7 +1532,9 @@ export class ScriptRunnerService { }); console.log( - `updated relationship from ${prev} to ${updated} for ${count} household members`, + `updated relationship from ${prev} to ${updated} for ${ + result?.count ?? 0 + } household members`, ); }; @@ -1691,3 +1693,94 @@ export class ScriptRunnerService { ); } } + +const test = [ + { income: 109600, percentOfAmi: 100, householdSize: 1 }, + { income: 125300, percentOfAmi: 100, householdSize: 2 }, + { income: 141000, percentOfAmi: 100, householdSize: 3 }, + { income: 156600, percentOfAmi: 100, householdSize: 4 }, + { income: 169200, percentOfAmi: 100, householdSize: 5 }, + { income: 181800, percentOfAmi: 100, householdSize: 6 }, + { income: 194300, percentOfAmi: 100, householdSize: 7 }, + { income: 206900, percentOfAmi: 100, householdSize: 8 }, + { income: 87680, percentOfAmi: 80, householdSize: 1 }, + { income: 100240, percentOfAmi: 80, householdSize: 2 }, + { income: 112800, percentOfAmi: 80, householdSize: 3 }, + { income: 125280, percentOfAmi: 80, householdSize: 4 }, + { income: 135360, percentOfAmi: 80, householdSize: 5 }, + { income: 145440, percentOfAmi: 80, householdSize: 6 }, + { income: 155280, percentOfAmi: 80, householdSize: 7 }, + { income: 165360, percentOfAmi: 80, householdSize: 8 }, + { income: 76720, percentOfAmi: 70, householdSize: 1 }, + { income: 87710, percentOfAmi: 70, householdSize: 2 }, + { income: 98700, percentOfAmi: 70, householdSize: 3 }, + { income: 109620, percentOfAmi: 70, householdSize: 4 }, + { income: 118440, percentOfAmi: 70, householdSize: 5 }, + { income: 127260, percentOfAmi: 70, householdSize: 6 }, + { income: 136140, percentOfAmi: 70, householdSize: 7 }, + { income: 144960, percentOfAmi: 70, householdSize: 8 }, + { income: 65760, percentOfAmi: 60, householdSize: 1 }, + { income: 75320, percentOfAmi: 60, householdSize: 2 }, + { income: 84900, percentOfAmi: 60, householdSize: 3 }, + { income: 93800, percentOfAmi: 60, householdSize: 4 }, + { income: 101520, percentOfAmi: 60, householdSize: 5 }, + { income: 109240, percentOfAmi: 60, householdSize: 6 }, + { income: 116880, percentOfAmi: 60, householdSize: 7 }, + { income: 124600, percentOfAmi: 60, householdSize: 8 }, + { income: 60280, percentOfAmi: 55, householdSize: 1 }, + { income: 69065, percentOfAmi: 55, householdSize: 2 }, + { income: 77850, percentOfAmi: 55, householdSize: 3 }, + { income: 86530, percentOfAmi: 55, householdSize: 4 }, + { income: 93660, percentOfAmi: 55, householdSize: 5 }, + { income: 100790, percentOfAmi: 55, householdSize: 6 }, + { income: 108000, percentOfAmi: 55, householdSize: 7 }, + { income: 115130, percentOfAmi: 55, householdSize: 8 }, + { income: 54800, percentOfAmi: 50, householdSize: 1 }, + { income: 62800, percentOfAmi: 50, householdSize: 2 }, + { income: 70900, percentOfAmi: 50, householdSize: 3 }, + { income: 78200, percentOfAmi: 50, householdSize: 4 }, + { income: 85800, percentOfAmi: 50, householdSize: 5 }, + { income: 93400, percentOfAmi: 50, householdSize: 6 }, + { income: 100560, percentOfAmi: 50, householdSize: 7 }, + { income: 108200, percentOfAmi: 50, householdSize: 8 }, + { income: 49320, percentOfAmi: 45, householdSize: 1 }, + { income: 56520, percentOfAmi: 45, householdSize: 2 }, + { income: 63900, percentOfAmi: 45, householdSize: 3 }, + { income: 69870, percentOfAmi: 45, householdSize: 4 }, + { income: 78060, percentOfAmi: 45, householdSize: 5 }, + { income: 86250, percentOfAmi: 45, householdSize: 6 }, + { income: 93120, percentOfAmi: 45, householdSize: 7 }, + { income: 97140, percentOfAmi: 45, householdSize: 8 }, + { income: 43840, percentOfAmi: 40, householdSize: 1 }, + { income: 50240, percentOfAmi: 40, householdSize: 2 }, + { income: 56900, percentOfAmi: 40, householdSize: 3 }, + { income: 61540, percentOfAmi: 40, householdSize: 4 }, + { income: 70320, percentOfAmi: 40, householdSize: 5 }, + { income: 79100, percentOfAmi: 40, householdSize: 6 }, + { income: 85680, percentOfAmi: 40, householdSize: 7 }, + { income: 86540, percentOfAmi: 40, householdSize: 8 }, + { income: 38360, percentOfAmi: 35, householdSize: 1 }, + { income: 43930, percentOfAmi: 35, householdSize: 2 }, + { income: 49900, percentOfAmi: 35, householdSize: 3 }, + { income: 53210, percentOfAmi: 35, householdSize: 4 }, + { income: 62580, percentOfAmi: 35, householdSize: 5 }, + { income: 71950, percentOfAmi: 35, householdSize: 6 }, + { income: 78240, percentOfAmi: 35, householdSize: 7 }, + { income: 79330, percentOfAmi: 35, householdSize: 8 }, + { income: 32880, percentOfAmi: 30, householdSize: 1 }, + { income: 37640, percentOfAmi: 30, householdSize: 2 }, + { income: 42900, percentOfAmi: 30, householdSize: 3 }, + { income: 44880, percentOfAmi: 30, householdSize: 4 }, + { income: 54840, percentOfAmi: 30, householdSize: 5 }, + { income: 64800, percentOfAmi: 30, householdSize: 6 }, + { income: 70800, percentOfAmi: 30, householdSize: 7 }, + { income: 72120, percentOfAmi: 30, householdSize: 8 }, + { income: 21920, percentOfAmi: 20, householdSize: 1 }, + { income: 25120, percentOfAmi: 20, householdSize: 2 }, + { income: 28320, percentOfAmi: 20, householdSize: 3 }, + { income: 31360, percentOfAmi: 20, householdSize: 4 }, + { income: 37360, percentOfAmi: 20, householdSize: 5 }, + { income: 43360, percentOfAmi: 20, householdSize: 6 }, + { income: 49200, percentOfAmi: 20, householdSize: 7 }, + { income: 50720, percentOfAmi: 20, householdSize: 8 }, +]; diff --git a/api/test/unit/services/script-runner.service.spec.ts b/api/test/unit/services/script-runner.service.spec.ts index aa7b5b8514..cb06f3f351 100644 --- a/api/test/unit/services/script-runner.service.spec.ts +++ b/api/test/unit/services/script-runner.service.spec.ts @@ -1880,6 +1880,45 @@ describe('Testing script runner service', () => { }); }); + it('should update household member relationships', async () => { + const id = randomUUID(); + const scriptName = 'update household member relationships'; + + prisma.scriptRuns.findUnique = jest.fn().mockResolvedValue(null); + prisma.scriptRuns.create = jest.fn().mockResolvedValue(null); + prisma.scriptRuns.update = jest.fn().mockResolvedValue(null); + prisma.householdMember.updateMany = jest.fn().mockResolvedValue(null); + + const res = await service.updateHouseholdMemberRelationships({ + user: { + id, + } as unknown as User, + } as unknown as ExpressRequest); + + expect(res.success).toBe(true); + + expect(prisma.scriptRuns.findUnique).toHaveBeenCalledWith({ + where: { + scriptName, + }, + }); + expect(prisma.scriptRuns.create).toHaveBeenCalledWith({ + data: { + scriptName, + triggeringUser: id, + }, + }); + expect(prisma.scriptRuns.update).toHaveBeenCalledWith({ + data: { + didScriptRun: true, + triggeringUser: id, + }, + where: { + scriptName, + }, + }); + }); + it('should remove all working addresses', async () => { const id = randomUUID(); const scriptName = 'remove work addresses';