diff --git a/app/data/gdhiRepo.test.ts b/app/data/gdhiRepo.test.ts index ac4dabd9..4793c5c6 100644 --- a/app/data/gdhiRepo.test.ts +++ b/app/data/gdhiRepo.test.ts @@ -19,11 +19,11 @@ describe("gdhiRepo", () => { // Mock the Prisma client response (prisma.gDHI.findFirstOrThrow as jest.Mock).mockResolvedValueOnce({ - gdhi2020: mockGDHI, + gdhi: mockGDHI, }); // Call the function - const result = await gdhiRepo.getGDHI2020ByITL3(itl3); + const result = await gdhiRepo.getGDHIByITL3(itl3); // Assertions expect(result).toBe(mockGDHI); @@ -33,7 +33,7 @@ describe("gdhiRepo", () => { itl3: { equals: itl3 }, }, }, - select: { gdhi2020: true }, + select: { gdhi: true }, }); }); @@ -46,8 +46,8 @@ describe("gdhiRepo", () => { ); // Call the function and expect an error - await expect(gdhiRepo.getGDHI2020ByITL3(itl3)).rejects.toThrow( - `Data error: Unable to find gdhi2020 for itl3 ${itl3}` + await expect(gdhiRepo.getGDHIByITL3(itl3)).rejects.toThrow( + `Data error: Unable to find gdhi for itl3 ${itl3}` ); }); @@ -60,8 +60,8 @@ describe("gdhiRepo", () => { ); // Call the function and expect an error - await expect(gdhiRepo.getGDHI2020ByITL3(itl3)).rejects.toThrow( - `Data error: Unable to find gdhi2020 for itl3 ${itl3}` + await expect(gdhiRepo.getGDHIByITL3(itl3)).rejects.toThrow( + `Data error: Unable to find gdhi for itl3 ${itl3}` ); }); }); diff --git a/app/data/gdhiRepo.ts b/app/data/gdhiRepo.ts index 8146136a..b96c3be8 100644 --- a/app/data/gdhiRepo.ts +++ b/app/data/gdhiRepo.ts @@ -1,23 +1,22 @@ import prisma from "./db"; -const getGDHI2020ByITL3 = async (itl3: string): Promise => { +const getGDHIByITL3 = async (itl3: string): Promise => { try { - const { gdhi2020 } = await prisma.gDHI.findFirstOrThrow({ + const { gdhi } = await prisma.gDHI.findFirstOrThrow({ where: { AND: { itl3: { equals: itl3 }, }, }, - select: { gdhi2020: true }, + select: { gdhi: true }, }); - - return gdhi2020; + return gdhi; } catch (error) { - throw Error(`Data error: Unable to find gdhi2020 for itl3 ${itl3}`); + throw Error(`Data error: Unable to find gdhi for itl3 ${itl3}`); } }; export const gdhiRepo = { - getGDHI2020ByITL3, + getGDHIByITL3, }; diff --git a/app/services/gdhiService.test.ts b/app/services/gdhiService.test.ts index 2b404926..8990eeac 100644 --- a/app/services/gdhiService.test.ts +++ b/app/services/gdhiService.test.ts @@ -14,20 +14,20 @@ describe("gdhiService.getByITL3", () => { it("should return GDHI for a valid ITL3", async () => { // Arrange const itl3 = "ITL3-123"; - (gdhiRepo.getGDHI2020ByITL3 as jest.Mock).mockResolvedValueOnce(mockGDHI); + (gdhiRepo.getGDHIByITL3 as jest.Mock).mockResolvedValueOnce(mockGDHI); // Act const result = await gdhiService.getByITL3(itl3); // Assert - expect(gdhiRepo.getGDHI2020ByITL3).toHaveBeenCalledWith(itl3); + expect(gdhiRepo.getGDHIByITL3).toHaveBeenCalledWith(itl3); expect(result).toBe(mockGDHI); }); it("should throw an error when the repo fails", async () => { // Arrange const errorMessage = "Failed to fetch GDHI"; - (gdhiRepo.getGDHI2020ByITL3 as jest.Mock).mockRejectedValueOnce( + (gdhiRepo.getGDHIByITL3 as jest.Mock).mockRejectedValueOnce( new Error(errorMessage) ); diff --git a/app/services/gdhiService.ts b/app/services/gdhiService.ts index 3dbb7529..24bcaa5d 100644 --- a/app/services/gdhiService.ts +++ b/app/services/gdhiService.ts @@ -1,7 +1,7 @@ import { gdhiRepo } from "../data/gdhiRepo"; const getByITL3 = async (itl3: string) => { - return await gdhiRepo.getGDHI2020ByITL3(itl3); + return await gdhiRepo.getGDHIByITL3(itl3); }; export const gdhiService = { diff --git a/prisma/migrations/20241218105236_rename_gdhi_column/migration.sql b/prisma/migrations/20241218105236_rename_gdhi_column/migration.sql new file mode 100644 index 00000000..8d4f1508 --- /dev/null +++ b/prisma/migrations/20241218105236_rename_gdhi_column/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "gdhi" RENAME COLUMN "gdhi_2020" TO "gdhi"; \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 08f212fd..716505a1 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -22,7 +22,7 @@ model GDHI { id Int @id @default(autoincrement()) itl3 String @db.VarChar(250) region String @db.VarChar(250) - gdhi2020 Float @map("gdhi_2020") + gdhi Float @@map("gdhi") }