From 5e2020ea561b3c3afdf27a13e326789289241506 Mon Sep 17 00:00:00 2001 From: Angela Cooney Date: Tue, 17 Sep 2024 14:44:23 -0400 Subject: [PATCH] CMDCT-3960: fixing tests, making year an int from the start --- services/app-api/handlers/coreSets/create.ts | 18 +++++---------- services/app-api/handlers/coreSets/delete.ts | 18 ++++----------- services/app-api/handlers/coreSets/get.ts | 6 ++--- .../handlers/coreSets/tests/create.test.ts | 5 ---- .../handlers/coreSets/tests/delete.test.ts | 17 +++++--------- .../handlers/coreSets/tests/get.test.ts | 12 ---------- .../handlers/coreSets/tests/update.test.ts | 12 ++-------- services/app-api/handlers/coreSets/update.ts | 4 +--- .../handlers/dynamoUtils/createCompoundKey.ts | 13 ----------- .../tests/createCompoundKey.test.ts | 20 ---------------- services/app-api/handlers/measures/create.ts | 6 ++--- services/app-api/handlers/measures/delete.ts | 4 +--- services/app-api/handlers/measures/get.ts | 9 +++----- .../handlers/measures/tests/create.test.ts | 9 ++------ .../handlers/measures/tests/delete.test.ts | 18 ++++----------- .../handlers/measures/tests/get.test.ts | 9 ++------ .../handlers/measures/tests/update.test.ts | 23 ++++++++----------- services/app-api/handlers/measures/update.ts | 8 +++---- services/app-api/utils/parseParameters.ts | 17 +++++++++++--- 19 files changed, 63 insertions(+), 165 deletions(-) delete mode 100644 services/app-api/handlers/dynamoUtils/createCompoundKey.ts delete mode 100644 services/app-api/handlers/dynamoUtils/tests/createCompoundKey.test.ts diff --git a/services/app-api/handlers/coreSets/create.ts b/services/app-api/handlers/coreSets/create.ts index 60dd55ce3..6972a5481 100644 --- a/services/app-api/handlers/coreSets/create.ts +++ b/services/app-api/handlers/coreSets/create.ts @@ -1,10 +1,6 @@ import handler from "../../libs/handler-lib"; import dynamoDb from "../../libs/dynamodb-lib"; import { getCoreSet } from "./get"; -import { - createCoreSetKey, - createMeasureKey, -} from "../dynamoUtils/createCompoundKey"; import { MeasureMetaData, measures } from "../dynamoUtils/measureList"; import { hasRolePermissions, @@ -45,7 +41,6 @@ export const createCoreSet = handler(async (event, context) => { body: Errors.CORESET_ALREADY_EXISTS, }; } - const dynamoKey = createCoreSetKey({ state, year, coreSet }); await createDependentMeasures( state, @@ -56,7 +51,7 @@ export const createCoreSet = handler(async (event, context) => { // filter out qualifier and account for autocomplete measures on creation let autoCompletedMeasures = 0; - const measuresLengthWithoutQualifiers = measures[parseInt(year)].filter( + const measuresLengthWithoutQualifiers = measures[year].filter( (measure: MeasureMetaData) => { if (measure.autocompleteOnCreation && measure.type === type) { autoCompletedMeasures++; @@ -73,9 +68,9 @@ export const createCoreSet = handler(async (event, context) => { const params = { TableName: process.env.coreSetTableName!, Item: { - compoundKey: dynamoKey, + compoundKey: `${state}${year}${coreSet}`, state: state, - year: parseInt(year), + year: year, coreSet: coreSet, createdAt: Date.now(), lastAltered: Date.now(), @@ -94,11 +89,11 @@ export const createCoreSet = handler(async (event, context) => { const createDependentMeasures = async ( state: string, - year: string, + year: number, coreSet: Types.CoreSetAbbr, type: string ) => { - const filteredMeasures = measures[parseInt(year)].filter( + const filteredMeasures = measures[year].filter( (measure: MeasureMetaData) => measure.type === type ); @@ -107,11 +102,10 @@ const createDependentMeasures = async ( for await (const measure of filteredMeasures) { // The State Year and ID are all part of the path const measureId = measure["measure"]; - const dynamoKey = createMeasureKey({ state, year, coreSet }); const params = { TableName: process.env.measureTable!, Item: { - compoundKey: dynamoKey, + compoundKey: `${state}${year}${coreSet}`, state: state, year: year, coreSet: coreSet, diff --git a/services/app-api/handlers/coreSets/delete.ts b/services/app-api/handlers/coreSets/delete.ts index 4c33cdd1b..2632a3735 100644 --- a/services/app-api/handlers/coreSets/delete.ts +++ b/services/app-api/handlers/coreSets/delete.ts @@ -1,10 +1,5 @@ import handler from "../../libs/handler-lib"; import dynamoDb from "../../libs/dynamodb-lib"; -import { - createCoreSetKey, - createMeasureKey, -} from "../dynamoUtils/createCompoundKey"; -import { convertToDynamoExpression } from "../dynamoUtils/convertToDynamoExpressionVars"; import { hasStatePermissions } from "../../libs/authorization"; import { Measure } from "../../types"; import { Errors, StatusCodes } from "../../utils/constants/constants"; @@ -27,11 +22,10 @@ export const deleteCoreSet = handler(async (event, context) => { }; } - const dynamoKey = createCoreSetKey({ state, year, coreSet }); const params = { TableName: process.env.coreSetTableName!, Key: { - compoundKey: dynamoKey, + compoundKey: `${state}${year}${coreSet}`, coreSet: coreSet, }, }; @@ -47,18 +41,17 @@ export const deleteCoreSet = handler(async (event, context) => { const deleteDependentMeasures = async ( state: string, - year: string, + year: number, coreSet: string ) => { const measures = await getMeasures(state, year, coreSet); const Items = measures; for await (const { measure } of Items) { - const dynamoKey = createMeasureKey({ state, year, coreSet }); const params = { TableName: process.env.measureTable!, Key: { - compoundKey: dynamoKey, + compoundKey: `${state}${year}${coreSet}`, coreSet: coreSet, }, }; @@ -67,13 +60,12 @@ const deleteDependentMeasures = async ( } }; -const getMeasures = async (state: string, year: string, coreSet: string) => { - const dynamoKey = createMeasureKey({ state, year, coreSet }); +const getMeasures = async (state: string, year: number, coreSet: string) => { const params = { TableName: process.env.measureTable!, KeyConditionExpression: "compoundKey = :compoundKey", ExpressionAttributeValues: { - ":compoundKey": dynamoKey, + ":compoundKey": `${state}${year}${coreSet}`, }, }; const queryValue = await dynamoDb.queryAll(params); diff --git a/services/app-api/handlers/coreSets/get.ts b/services/app-api/handlers/coreSets/get.ts index 379555c7a..203b0e8d5 100644 --- a/services/app-api/handlers/coreSets/get.ts +++ b/services/app-api/handlers/coreSets/get.ts @@ -2,7 +2,6 @@ import handler from "../../libs/handler-lib"; import dynamoDb from "../../libs/dynamodb-lib"; import { updateCoreSetProgress } from "../../libs/updateCoreProgress"; import { convertToDynamoExpression } from "../dynamoUtils/convertToDynamoExpressionVars"; -import { createCoreSetKey } from "../dynamoUtils/createCompoundKey"; import { createCoreSet } from "./create"; import { hasRolePermissions, @@ -41,7 +40,7 @@ export const coreSetList = handler(async (event, context) => { ...convertToDynamoExpression( { state: state, - year: parseInt(year), + year: year, }, "list" ), @@ -121,11 +120,10 @@ export const getCoreSet = handler(async (event, context) => { } } // if not state user, can safely assume admin type user due to baseline handler protections - const dynamoKey = createCoreSetKey({ state, year, coreSet }); const params = { TableName: process.env.coreSetTableName!, Key: { - compoundKey: dynamoKey, + compoundKey: `${state}${year}${coreSet}`, coreSet: coreSet, }, }; diff --git a/services/app-api/handlers/coreSets/tests/create.test.ts b/services/app-api/handlers/coreSets/tests/create.test.ts index e9b62d56a..62b04f29f 100644 --- a/services/app-api/handlers/coreSets/tests/create.test.ts +++ b/services/app-api/handlers/coreSets/tests/create.test.ts @@ -23,11 +23,6 @@ jest.mock("../../../libs/authorization", () => ({ hasStatePermissions: () => mockHasStatePermissions(), })); -jest.mock("../../dynamoUtils/createCompoundKey", () => ({ - __esModule: true, - createCoreSetKey: jest.fn().mockReturnValue("FL2021ACSFUA-AD"), -})); - jest.mock("../get", () => ({ __esModule: true, getCoreSet: jest.fn(), diff --git a/services/app-api/handlers/coreSets/tests/delete.test.ts b/services/app-api/handlers/coreSets/tests/delete.test.ts index b34f9b881..3b0130f9b 100644 --- a/services/app-api/handlers/coreSets/tests/delete.test.ts +++ b/services/app-api/handlers/coreSets/tests/delete.test.ts @@ -6,7 +6,7 @@ import { CoreSetAbbr } from "../../../types"; jest.mock("../../../libs/dynamodb-lib", () => ({ delete: jest.fn(), - scanAll: jest.fn(), + queryAll: jest.fn(), })); const mockHasStatePermissions = jest.fn(); @@ -15,11 +15,6 @@ jest.mock("../../../libs/authorization", () => ({ hasStatePermissions: () => mockHasStatePermissions(), })); -jest.mock("../../dynamoUtils/createCompoundKey", () => ({ - __esModule: true, - createCoreSetKey: jest.fn().mockReturnValue("FL2020ACSFUA-AD"), -})); - jest.mock("../../../libs/updateCoreProgress", () => ({ __esModule: true, updateCoreSetProgress: jest.fn(), @@ -29,7 +24,7 @@ const event = { ...testEvent }; describe("Testing Delete Core Set Functions", () => { beforeEach(() => { - (db.scanAll as jest.Mock).mockReset(); + (db.queryAll as jest.Mock).mockReset(); (db.delete as jest.Mock).mockReset(); mockHasStatePermissions.mockImplementation(() => true); event.pathParameters = { @@ -67,7 +62,7 @@ describe("Testing Delete Core Set Functions", () => { }); test("Test deleteCoreSet with associated measures", async () => { - (db.scanAll as jest.Mock).mockReturnValue([ + (db.queryAll as jest.Mock).mockReturnValue([ testMeasure, testMeasure, testMeasure, @@ -75,16 +70,16 @@ describe("Testing Delete Core Set Functions", () => { await deleteCoreSet(event, null); - expect(db.scanAll).toHaveBeenCalled(); + expect(db.queryAll).toHaveBeenCalled(); expect(db.delete).toHaveBeenCalledTimes(4); }); test("Test deleteCoreSet with no associated measures", async () => { - (db.scanAll as jest.Mock).mockReturnValue([]); + (db.queryAll as jest.Mock).mockReturnValue([]); await deleteCoreSet(event, null); - expect(db.scanAll).toHaveBeenCalled(); + expect(db.queryAll).toHaveBeenCalled(); expect(db.delete).toHaveBeenCalled(); }); }); diff --git a/services/app-api/handlers/coreSets/tests/get.test.ts b/services/app-api/handlers/coreSets/tests/get.test.ts index 6479f39f9..9f2df1f8c 100644 --- a/services/app-api/handlers/coreSets/tests/get.test.ts +++ b/services/app-api/handlers/coreSets/tests/get.test.ts @@ -4,7 +4,6 @@ import { testEvent } from "../../../test-util/testEvents"; import dynamodbLib from "../../../libs/dynamodb-lib"; import { updateCoreSetProgress } from "../../../libs/updateCoreProgress"; -import { createCoreSetKey } from "../../dynamoUtils/createCompoundKey"; import { CoreSetAbbr } from "../../../types"; import { createCoreSet } from "../create"; import { Errors, StatusCodes } from "../../../utils/constants/constants"; @@ -35,11 +34,6 @@ jest.mock("../../../libs/updateCoreProgress", () => ({ updateCoreSetProgress: jest.fn(), })); -jest.mock("../../dynamoUtils/createCompoundKey", () => ({ - __esModule: true, - createCoreSetKey: jest.fn().mockReturnValue("FL2020ACSFUA-AD"), -})); - jest.mock("../../dynamoUtils/convertToDynamoExpressionVars", () => ({ __esModule: true, convertToDynamoExpression: jest.fn().mockReturnValue({ testValue: "test" }), @@ -96,12 +90,6 @@ describe("Test Get Core Set Functions", () => { await getCoreSet(event, null); expect(dynamodbLib.get).toHaveBeenCalled(); - expect(createCoreSetKey).toHaveBeenCalled(); - expect(createCoreSetKey).toHaveBeenCalledWith({ - state: "AL", - year: "2021", - coreSet: "ACS", - }); }); test("Test coreSetList unauthorized user attempt (incorrect state)", async () => { diff --git a/services/app-api/handlers/coreSets/tests/update.test.ts b/services/app-api/handlers/coreSets/tests/update.test.ts index d4638cd7b..f2fe786ad 100644 --- a/services/app-api/handlers/coreSets/tests/update.test.ts +++ b/services/app-api/handlers/coreSets/tests/update.test.ts @@ -1,7 +1,6 @@ import dynamodbLib from "../../../libs/dynamodb-lib"; import { testEvent } from "../../../test-util/testEvents"; import { convertToDynamoExpression } from "../../dynamoUtils/convertToDynamoExpressionVars"; -import { createCoreSetKey } from "../../dynamoUtils/createCompoundKey"; import { editCoreSet } from "../update"; import { Errors, StatusCodes } from "../../../utils/constants/constants"; import { CoreSetAbbr } from "../../../types"; @@ -17,11 +16,6 @@ jest.mock("../../../libs/authorization", () => ({ hasStatePermissions: () => mockHasStatePermissions(), })); -jest.mock("../../dynamoUtils/createCompoundKey", () => ({ - __esModule: true, - createCoreSetKey: jest.fn().mockReturnValue("FL2020ACSFUA-AD"), -})); - jest.mock("../../dynamoUtils/convertToDynamoExpressionVars", () => ({ __esModule: true, convertToDynamoExpression: jest.fn().mockReturnValue({ testValue: "test" }), @@ -73,7 +67,6 @@ describe("Testing Updating Core Set Functions", () => { Date.now = jest.fn(() => 20); const res = await editCoreSet(event, null); - expect(createCoreSetKey).toHaveBeenCalled(); expect(dynamodbLib.update).toHaveBeenCalled(); expect(convertToDynamoExpression).toHaveBeenCalledWith( { @@ -84,14 +77,13 @@ describe("Testing Updating Core Set Functions", () => { "post" ); expect(res.statusCode).toBe(StatusCodes.SUCCESS); - expect(res.body).toContain("FL2020ACSFUA-AD"); + expect(res.body).toContain("WA2021ACS"); }); test("Test with no user id", async () => { Date.now = jest.fn(() => 20); const res = await editCoreSet(event, null); - expect(createCoreSetKey).toHaveBeenCalled(); expect(dynamodbLib.update).toHaveBeenCalled(); expect(convertToDynamoExpression).toHaveBeenCalledWith( { @@ -102,6 +94,6 @@ describe("Testing Updating Core Set Functions", () => { "post" ); expect(res.statusCode).toBe(StatusCodes.SUCCESS); - expect(res.body).toContain("FL2020ACSFUA-AD"); + expect(res.body).toContain("WA2021ACS"); }); }); diff --git a/services/app-api/handlers/coreSets/update.ts b/services/app-api/handlers/coreSets/update.ts index a5e8c456f..85b341c90 100644 --- a/services/app-api/handlers/coreSets/update.ts +++ b/services/app-api/handlers/coreSets/update.ts @@ -1,7 +1,6 @@ import handler from "../../libs/handler-lib"; import dynamoDb from "../../libs/dynamodb-lib"; import { convertToDynamoExpression } from "../dynamoUtils/convertToDynamoExpressionVars"; -import { createCoreSetKey } from "../dynamoUtils/createCompoundKey"; import { getUserNameFromJwt, hasStatePermissions, @@ -27,12 +26,11 @@ export const editCoreSet = handler(async (event, context) => { } const { submitted, status } = JSON.parse(event!.body!); - const dynamoKey = createCoreSetKey({ state, year, coreSet }); const lastAlteredBy = getUserNameFromJwt(event); const params = { TableName: process.env.coreSetTableName!, Key: { - compoundKey: dynamoKey, + compoundKey: `${state}${year}${coreSet}`, coreSet: coreSet, }, ...convertToDynamoExpression( diff --git a/services/app-api/handlers/dynamoUtils/createCompoundKey.ts b/services/app-api/handlers/dynamoUtils/createCompoundKey.ts deleted file mode 100644 index 3ff05ac94..000000000 --- a/services/app-api/handlers/dynamoUtils/createCompoundKey.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { CoreSetParameters, MeasureParameters } from "../../types"; - -export const createMeasureKey = (measureParams: MeasureParameters) => { - const { state, year, coreSet } = measureParams; - - return `${state}${year}${coreSet}`; -}; - -export const createCoreSetKey = (coreSetParams: CoreSetParameters) => { - const { state, year, coreSet } = coreSetParams; - - return `${state}${year}${coreSet}`; -}; diff --git a/services/app-api/handlers/dynamoUtils/tests/createCompoundKey.test.ts b/services/app-api/handlers/dynamoUtils/tests/createCompoundKey.test.ts deleted file mode 100644 index b120f2a8e..000000000 --- a/services/app-api/handlers/dynamoUtils/tests/createCompoundKey.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { createCoreSetKey, createMeasureKey } from "../createCompoundKey"; - -describe("Testing createCoreSetKey", () => { - test("Successful key creation", () => { - const key = createCoreSetKey({ year: "2022", state: "FL", coreSet: "ACS" }); - expect(key).toEqual("FL2022ACS"); - }); -}); - -describe("Testing createMeasureKey", () => { - test("Successful key creation", () => { - const key = createMeasureKey({ - year: "2022", - state: "FL", - coreSet: "ACS", - measure: "FUA-AD", - }); - expect(key).toEqual("FL2022ACSFUA-AD"); - }); -}); diff --git a/services/app-api/handlers/measures/create.ts b/services/app-api/handlers/measures/create.ts index 9eee5c143..ac6362466 100644 --- a/services/app-api/handlers/measures/create.ts +++ b/services/app-api/handlers/measures/create.ts @@ -1,6 +1,5 @@ import handler from "../../libs/handler-lib"; import dynamoDb from "../../libs/dynamodb-lib"; -import { createMeasureKey } from "../dynamoUtils/createCompoundKey"; import { hasRolePermissions, hasStatePermissions, @@ -31,13 +30,12 @@ export const createMeasure = handler(async (event, context) => { } // if not state user, can safely assume admin type user due to baseline handler protections const body = JSON.parse(event!.body!); - const dynamoKey = createMeasureKey({ state, year, coreSet }); const params = { TableName: process.env.measureTable!, Item: { - compoundKey: dynamoKey, + compoundKey: `${state}${year}${coreSet}`, state: state, - year: parseInt(year), + year: year, coreSet: coreSet, measure: measure, createdAt: Date.now(), diff --git a/services/app-api/handlers/measures/delete.ts b/services/app-api/handlers/measures/delete.ts index 865d3ea05..d8fbda021 100644 --- a/services/app-api/handlers/measures/delete.ts +++ b/services/app-api/handlers/measures/delete.ts @@ -1,6 +1,5 @@ import handler from "../../libs/handler-lib"; import dynamoDb from "../../libs/dynamodb-lib"; -import { createMeasureKey } from "../dynamoUtils/createCompoundKey"; import { hasStatePermissions } from "../../libs/authorization"; import { Errors, StatusCodes } from "../../utils/constants/constants"; import { parseMeasureParameters } from "../../utils/parseParameters"; @@ -22,11 +21,10 @@ export const deleteMeasure = handler(async (event, context) => { }; } - const dynamoKey = createMeasureKey({ state, year, coreSet }); const params = { TableName: process.env.measureTable!, Key: { - compoundKey: dynamoKey, + compoundKey: `${state}${year}${coreSet}`, measure: measure, }, }; diff --git a/services/app-api/handlers/measures/get.ts b/services/app-api/handlers/measures/get.ts index 43ff3e103..a8325a0a0 100644 --- a/services/app-api/handlers/measures/get.ts +++ b/services/app-api/handlers/measures/get.ts @@ -1,6 +1,5 @@ import handler from "../../libs/handler-lib"; import dynamoDb from "../../libs/dynamodb-lib"; -import { createMeasureKey } from "../dynamoUtils/createCompoundKey"; import { measures } from "../dynamoUtils/measureList"; import { hasRolePermissions, @@ -33,18 +32,17 @@ export const listMeasures = handler(async (event, context) => { }; } } // if not state user, can safely assume admin type user due to baseline handler protections - const dynamoKey = createMeasureKey({ state, year, coreSet }); const params = { TableName: process.env.measureTable!, KeyConditionExpression: "compoundKey = :compoundKey", ExpressionAttributeValues: { - ":compoundKey": dynamoKey, + ":compoundKey": `${state}${year}${coreSet}`, }, }; const queriedMeasures = await dynamoDb.queryAll(params); for (let v of queriedMeasures) { - const measure = measures[parseInt(year as string)]?.filter( + const measure = measures[year as number]?.filter( (m) => m.measure === (v as Measure)?.measure )[0]; @@ -81,11 +79,10 @@ export const getMeasure = handler(async (event, context) => { } } // if not state user, can safely assume admin type user due to baseline handler protections - const dynamoKey = createMeasureKey({ state, year, coreSet }); const params = { TableName: process.env.measureTable!, Key: { - compoundKey: dynamoKey, + compoundKey: `${state}${year}${coreSet}`, measure: measure, }, }; diff --git a/services/app-api/handlers/measures/tests/create.test.ts b/services/app-api/handlers/measures/tests/create.test.ts index 21dbee992..722fa4937 100644 --- a/services/app-api/handlers/measures/tests/create.test.ts +++ b/services/app-api/handlers/measures/tests/create.test.ts @@ -14,11 +14,6 @@ jest.mock("../../../libs/authorization", () => ({ hasStatePermissions: () => mockHasStatePermissions(), })); -jest.mock("../../dynamoUtils/createCompoundKey", () => ({ - __esModule: true, - createMeasureKey: jest.fn().mockReturnValue("FL2020ACSFUA-AD"), -})); - const event = { ...testEvent }; process.env.measureTableName = "SAMPLE TABLE"; @@ -52,7 +47,7 @@ describe("Test Create Measure Handler", () => { expect(res.statusCode).toBe(StatusCodes.SUCCESS); expect(res.body).toContain("sample desc"); expect(res.body).toContain("sample detailed desc"); - expect(res.body).toContain("FL2020ACSFUA-AD"); + expect(res.body).toContain("IN2022ACS"); }); test("Test Successful Run of Measure Creation without description", async () => { @@ -62,7 +57,7 @@ describe("Test Create Measure Handler", () => { expect(res.statusCode).toBe(StatusCodes.SUCCESS); expect(res.body).toContain("test"); - expect(res.body).toContain("FL2020ACSFUA-AD"); + expect(res.body).toContain("IN2022ACS"); }); test("Fails with bad request when path params are missing", async () => { diff --git a/services/app-api/handlers/measures/tests/delete.test.ts b/services/app-api/handlers/measures/tests/delete.test.ts index fc7e76608..b0886fdfd 100644 --- a/services/app-api/handlers/measures/tests/delete.test.ts +++ b/services/app-api/handlers/measures/tests/delete.test.ts @@ -1,8 +1,5 @@ import { deleteMeasure } from "../delete"; - import dbLib from "../../../libs/dynamodb-lib"; - -import { APIGatewayProxyEvent } from "../../../types"; import { testEvent } from "../../../test-util/testEvents"; import { StatusCodes, Errors } from "../../../utils/constants/constants"; @@ -16,13 +13,8 @@ jest.mock("../../../libs/authorization", () => ({ hasStatePermissions: () => mockHasStatePermissions(), })); -jest.mock("../../dynamoUtils/createCompoundKey", () => ({ - __esModule: true, - createMeasureKey: jest.fn().mockReturnValue("FL2020ACSFUA-AD"), -})); - const event = { ...testEvent }; -process.env.measureTableName = "SAMPLE TABLE"; +process.env.measureTable = "SAMPLE TABLE"; describe("Test Delete Measure Handler", () => { beforeEach(() => { @@ -69,13 +61,13 @@ describe("Test Delete Measure Handler", () => { const res = await deleteMeasure(event, null); expect(res.statusCode).toBe(StatusCodes.SUCCESS); - expect(res.body).toContain("FL2020ACSFUA-AD"); - expect(res.body).toContain('"coreSet":"ACS"'); + expect(res.body).toContain("IN2022ACS"); + expect(res.body).toContain('"measure":"AAB-AD"'); expect(dbLib.delete).toHaveBeenCalledWith({ TableName: "SAMPLE TABLE", Key: { - compoundKey: "FL2020ACSFUA-AD", - coreSet: "ACS", + compoundKey: "IN2022ACS", + measure: "AAB-AD", }, }); }); diff --git a/services/app-api/handlers/measures/tests/get.test.ts b/services/app-api/handlers/measures/tests/get.test.ts index ad52f93c2..a3b7c1676 100644 --- a/services/app-api/handlers/measures/tests/get.test.ts +++ b/services/app-api/handlers/measures/tests/get.test.ts @@ -25,11 +25,6 @@ jest.mock("../../../libs/authorization", () => ({ hasStatePermissions: () => mockHasStatePermissions(), })); -jest.mock("../../dynamoUtils/createCompoundKey", () => ({ - __esModule: true, - createMeasureKey: jest.fn().mockReturnValue("FL2020ACSFUA-AD"), -})); - jest.mock("../../dynamoUtils/convertToDynamoExpressionVars", () => ({ __esModule: true, convertToDynamoExpression: jest.fn().mockReturnValue({ testValue: "test" }), @@ -68,8 +63,8 @@ describe("Test Get Measure Handlers", () => { expect(dbLib.get).toHaveBeenCalledWith({ TableName: "SAMPLE TABLE", Key: { - compoundKey: "FL2020ACSFUA-AD", - coreSet: "ACS", + compoundKey: "IN2022ACS", + measure: "AAB-AD", }, }); }); diff --git a/services/app-api/handlers/measures/tests/update.test.ts b/services/app-api/handlers/measures/tests/update.test.ts index 5c3123c4d..5f2cea281 100644 --- a/services/app-api/handlers/measures/tests/update.test.ts +++ b/services/app-api/handlers/measures/tests/update.test.ts @@ -18,18 +18,13 @@ jest.mock("../../../libs/authorization", () => ({ hasStatePermissions: () => mockHasStatePermissions(), })); -jest.mock("../../dynamoUtils/createCompoundKey", () => ({ - __esModule: true, - createMeasureKey: jest.fn().mockReturnValue("FL2020ACSFUA-AD"), -})); - jest.mock("../../dynamoUtils/convertToDynamoExpressionVars", () => ({ __esModule: true, convertToDynamoExpression: jest.fn().mockReturnValue({ testValue: "test" }), })); const event = { ...testEvent }; -process.env.measureTableName = "SAMPLE TABLE"; +process.env.measureTable = "SAMPLE TABLE"; describe("Test Update Measure Handler", () => { beforeEach(() => { @@ -78,8 +73,8 @@ describe("Test Update Measure Handler", () => { const res = await editMeasure(event, null); expect(res.statusCode).toBe(StatusCodes.SUCCESS); - expect(res.body).toContain("FL2020ACSFUA-AD"); - expect(res.body).toContain('"coreSet":"ACS"'); + expect(res.body).toContain("IN2022ACS"); + expect(res.body).toContain('"measure":"AAB-AD"'); expect(convertToDynamoExpression).toHaveBeenCalledWith( { status: "status", @@ -93,8 +88,8 @@ describe("Test Update Measure Handler", () => { expect(dbLib.update).toHaveBeenCalledWith({ TableName: "SAMPLE TABLE", Key: { - compoundKey: "FL2020ACSFUA-AD", - coreSet: "ACS", + compoundKey: "IN2022ACS", + measure: "AAB-AD", }, testValue: "test", }); @@ -107,8 +102,8 @@ describe("Test Update Measure Handler", () => { const res = await editMeasure(event, null); expect(res.statusCode).toBe(StatusCodes.SUCCESS); - expect(res.body).toContain("FL2020ACSFUA-AD"); - expect(res.body).toContain('"coreSet":"ACS"'); + expect(res.body).toContain("IN2022ACS"); + expect(res.body).toContain('"measure":"AAB-AD"'); expect(convertToDynamoExpression).toHaveBeenCalledWith( { status: "status", @@ -122,8 +117,8 @@ describe("Test Update Measure Handler", () => { expect(dbLib.update).toHaveBeenCalledWith({ TableName: "SAMPLE TABLE", Key: { - compoundKey: "FL2020ACSFUA-AD", - coreSet: "ACS", + compoundKey: "IN2022ACS", + measure: "AAB-AD", }, testValue: "test", }); diff --git a/services/app-api/handlers/measures/update.ts b/services/app-api/handlers/measures/update.ts index c258682b6..cae549cf7 100644 --- a/services/app-api/handlers/measures/update.ts +++ b/services/app-api/handlers/measures/update.ts @@ -1,7 +1,6 @@ import handler from "../../libs/handler-lib"; import dynamoDb from "../../libs/dynamodb-lib"; import { convertToDynamoExpression } from "../dynamoUtils/convertToDynamoExpressionVars"; -import { createMeasureKey } from "../dynamoUtils/createCompoundKey"; import { getUserNameFromJwt, hasStatePermissions, @@ -35,7 +34,6 @@ export const editMeasure = handler(async (event, context) => { detailedDescription, } = JSON.parse(event!.body!); - const dynamoKey = createMeasureKey({ state, year, coreSet }); const lastAlteredBy = getUserNameFromJwt(event); const descriptionParams = @@ -48,7 +46,7 @@ export const editMeasure = handler(async (event, context) => { const params = { TableName: process.env.measureTable!, Key: { - compoundKey: dynamoKey, + compoundKey: `${state}${year}${coreSet}`, measure: measure, }, ...convertToDynamoExpression( @@ -66,11 +64,11 @@ export const editMeasure = handler(async (event, context) => { await dynamoDb.update(params); //in 2024 and onward, we added a new feature called combined rates which requires rate calculations to the rates table - if (parseInt(year) >= 2024) { + if (year >= 2024) { //after updating the database with the latest values for the measure, we run the combine rates calculations for said measure await calculateAndPutRate({ state, - year, + year: year.toString(), coreSet, measure, }); diff --git a/services/app-api/utils/parseParameters.ts b/services/app-api/utils/parseParameters.ts index 7ed6b1040..c61df5a3f 100644 --- a/services/app-api/utils/parseParameters.ts +++ b/services/app-api/utils/parseParameters.ts @@ -29,7 +29,7 @@ export const parseStateAndYearParameters = (event: APIGatewayProxyEvent) => { logger.warn("Invalid or missing year in path"); return { allParamsValid: false as const }; } - return { allParamsValid: true as const, state, year }; + return { allParamsValid: true as const, state, year: parseInt(year) }; }; export const parseCoreSetParameters = (event: APIGatewayProxyEvent) => { @@ -47,7 +47,12 @@ export const parseCoreSetParameters = (event: APIGatewayProxyEvent) => { logger.warn("Invalid or missing coreset in path"); return { allParamsValid: false as const }; } - return { allParamsValid: true as const, state, year, coreSet }; + return { + allParamsValid: true as const, + state, + year: parseInt(year), + coreSet, + }; }; export const parseMeasureParameters = (event: APIGatewayProxyEvent) => { @@ -69,5 +74,11 @@ export const parseMeasureParameters = (event: APIGatewayProxyEvent) => { logger.warn("Invalid or missing measure in path"); return { allParamsValid: false as const }; } - return { allParamsValid: true as const, state, year, coreSet, measure }; + return { + allParamsValid: true as const, + state, + year: parseInt(year), + coreSet, + measure, + }; };