diff --git a/app/data/hpiRepo.test.ts b/app/data/hpiRepo.test.ts index c33afcdd..b902da61 100644 --- a/app/data/hpiRepo.test.ts +++ b/app/data/hpiRepo.test.ts @@ -1,6 +1,5 @@ -// __tests__/hpiRepo.test.ts -import { hpi2000Repo } from "./hpiRepo"; // Adjust the import according to your file structure -import prisma from "./db"; // Your Prisma setup file +import { hpi1999Repo } from "./hpiRepo"; +import prisma from "./db"; jest.mock("./db", () => ({ hPI: { @@ -8,7 +7,7 @@ jest.mock("./db", () => ({ }, })); -describe("hpi2000Repo", () => { +describe("hpi1999Repo", () => { afterEach(() => { jest.clearAllMocks(); }); @@ -19,11 +18,11 @@ describe("hpi2000Repo", () => { // Mock the Prisma client response (prisma.hPI.aggregate as jest.Mock).mockResolvedValueOnce({ - _avg: { hpi2000: mockAverageHpi }, + _avg: { hpi1999: mockAverageHpi }, }); // Call the function - const result = await hpi2000Repo.getHPIByITL3(itl3); + const result = await hpi1999Repo.getHPIByITL3(itl3); // Assertions expect(result).toBe(mockAverageHpi); @@ -34,7 +33,7 @@ describe("hpi2000Repo", () => { }, }, _avg: { - hpi2000: true, + hpi1999: true, }, }); }); @@ -44,12 +43,12 @@ describe("hpi2000Repo", () => { // Mock rejection of the Prisma client (prisma.hPI.aggregate as jest.Mock).mockResolvedValueOnce({ - _avg: { hpi2000: null }, + _avg: { hpi1999: null }, }); // Call the function and expect an error - await expect(hpi2000Repo.getHPIByITL3(itl3)).rejects.toThrow( - `Data error: Unable to find hpi2000 for itl3 ${itl3}` + await expect(hpi1999Repo.getHPIByITL3(itl3)).rejects.toThrow( + `Data error: Unable to find hpi1999 for itl3 ${itl3}` ); }); @@ -62,8 +61,8 @@ describe("hpi2000Repo", () => { ); // Call the function and expect an error - await expect(hpi2000Repo.getHPIByITL3(itl3)).rejects.toThrow( - `Data error: Unable to find hpi2000 for itl3 ${itl3}` + await expect(hpi1999Repo.getHPIByITL3(itl3)).rejects.toThrow( + `Data error: Unable to find hpi1999 for itl3 ${itl3}` ); }); }); diff --git a/app/data/hpiRepo.ts b/app/data/hpiRepo.ts index 8c869477..2f6e5499 100644 --- a/app/data/hpiRepo.ts +++ b/app/data/hpiRepo.ts @@ -3,7 +3,7 @@ import prisma from "./db"; const getHPIByITL3 = async (itl3: string): Promise => { try { const { - _avg: { hpi2000: averageHpi }, + _avg: { hpi1999: averageHpi }, } = await prisma.hPI.aggregate({ // TODO: Should there be a relationship on ITL3? where: { @@ -12,21 +12,21 @@ const getHPIByITL3 = async (itl3: string): Promise => { }, }, _avg: { - hpi2000: true, + hpi1999: true, }, }); // Check if the average HPI is null and throw an error if (averageHpi === null) { - throw new Error(`Data error: Unable to find hpi2000 for itl3 ${itl3}`); + throw new Error(`Data error: Unable to find hpi1999 for itl3 ${itl3}`); } return averageHpi; } catch (error) { - throw Error(`Data error: Unable to find hpi2000 for itl3 ${itl3}`); + throw Error(`Data error: Unable to find hpi1999 for itl3 ${itl3}`); } }; -export const hpi2000Repo = { +export const hpi1999Repo = { getHPIByITL3, }; diff --git a/app/services/hpiService.test.ts b/app/services/hpiService.test.ts index 9ed0240d..a69a7285 100644 --- a/app/services/hpiService.test.ts +++ b/app/services/hpiService.test.ts @@ -1,6 +1,6 @@ // __tests__/hpiService.test.ts import { hpiService } from "../services/hpiService"; // Adjust the path according to your structure -import { hpi2000Repo } from "../data/hpiRepo"; // Adjust the path according to your structure +import { hpi1999Repo } from "../data/hpiRepo"; // Adjust the path according to your structure jest.mock("../data/hpiRepo"); @@ -14,20 +14,20 @@ describe("hpiService.getByITL3", () => { it("should return HPI for a valid ITL3", async () => { // Arrange const itl3 = "ITL3-123"; - (hpi2000Repo.getHPIByITL3 as jest.Mock).mockResolvedValueOnce(mockHPI); + (hpi1999Repo.getHPIByITL3 as jest.Mock).mockResolvedValueOnce(mockHPI); // Act const result = await hpiService.getByITL3(itl3); // Assert - expect(hpi2000Repo.getHPIByITL3).toHaveBeenCalledWith(itl3); + expect(hpi1999Repo.getHPIByITL3).toHaveBeenCalledWith(itl3); expect(result).toBe(mockHPI); }); it("should throw an error when the repo fails", async () => { // Arrange const errorMessage = "Failed to fetch HPI"; - (hpi2000Repo.getHPIByITL3 as jest.Mock).mockRejectedValueOnce( + (hpi1999Repo.getHPIByITL3 as jest.Mock).mockRejectedValueOnce( new Error(errorMessage) ); diff --git a/app/services/hpiService.ts b/app/services/hpiService.ts index d7384e4e..bc9319c3 100644 --- a/app/services/hpiService.ts +++ b/app/services/hpiService.ts @@ -1,7 +1,7 @@ -import { hpi2000Repo } from "../data/hpiRepo"; +import { hpi1999Repo } from "../data/hpiRepo"; const getByITL3 = async (itl3: string) => { - return await hpi2000Repo.getHPIByITL3(itl3); + return await hpi1999Repo.getHPIByITL3(itl3); }; export const hpiService = { diff --git a/prisma/migrations/20241218155911_update_hpi_year/migration.sql b/prisma/migrations/20241218155911_update_hpi_year/migration.sql new file mode 100644 index 00000000..979ebffe --- /dev/null +++ b/prisma/migrations/20241218155911_update_hpi_year/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "hpi" RENAME COLUMN "hpi_2000" TO "hpi_1999"; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index f3efd44c..b5fc3125 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -31,7 +31,7 @@ model HPI { id Int @id @default(autoincrement()) region String @db.VarChar(250) itl3 String @db.VarChar(250) - hpi2000 Float @map("hpi_2000") + hpi1999 Float @map("hpi_1999") @@map("hpi") }