Skip to content

Commit

Permalink
Merge pull request #170 from theopensystemslab/oz/social-rent-earning…
Browse files Browse the repository at this point in the history
…s-table

feat: Rename social_rent_earnings table, make fields non-nullable
  • Loading branch information
zz-hh-aa authored Dec 13, 2024
2 parents 6321c94 + 0807c90 commit 20b9755
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
10 changes: 5 additions & 5 deletions app/data/socialRentEarningsRepo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { socialRentEarningsRepo } from "./socialRentEarningsRepo"; // Adjust the
import prisma from "./db"; // Your Prisma setup file

jest.mock("./db", () => ({
socialRent: {
socialRentEarnings: {
aggregate: jest.fn(), // Mock the aggregate method
},
}));
Expand All @@ -18,15 +18,15 @@ describe("socialRentEarningsRepo", () => {
const mockEarnings = 500; // Example average earnings

// Mock the Prisma client response
(prisma.socialRent.aggregate as jest.Mock).mockResolvedValueOnce({
(prisma.socialRentEarnings.aggregate as jest.Mock).mockResolvedValueOnce({
_avg: { earningsPerWeek: mockEarnings },
});

const result =
await socialRentEarningsRepo.getSocialRentEarningsByITL3(itl3);

expect(result).toBe(mockEarnings);
expect(prisma.socialRent.aggregate).toHaveBeenCalledWith({
expect(prisma.socialRentEarnings.aggregate).toHaveBeenCalledWith({
where: {
itl3: {
startsWith: itl3.substring(0, 3),
Expand All @@ -42,7 +42,7 @@ describe("socialRentEarningsRepo", () => {
const itl3 = "XYZ123";

// Mock the Prisma client response to return null for earningsPerWeek
(prisma.socialRent.aggregate as jest.Mock).mockResolvedValueOnce({
(prisma.socialRentEarnings.aggregate as jest.Mock).mockResolvedValueOnce({
_avg: { earningsPerWeek: null },
});

Expand All @@ -57,7 +57,7 @@ describe("socialRentEarningsRepo", () => {
const itl3 = "XYZ123";

// Mock the Prisma client to throw an error
(prisma.socialRent.aggregate as jest.Mock).mockRejectedValueOnce(
(prisma.socialRentEarnings.aggregate as jest.Mock).mockRejectedValueOnce(
new Error("Database error")
);

Expand Down
2 changes: 1 addition & 1 deletion app/data/socialRentEarningsRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import prisma from "./db";

const getSocialRentEarningsByITL3 = async (itl3: string): Promise<number> => {
try {
const result = await prisma.socialRent.aggregate({
const result = await prisma.socialRentEarnings.aggregate({
where: {
itl3: {
startsWith: itl3.substring(0, 3),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Alter table
ALTER TABLE "socialrent" RENAME TO "social_rent_earnings";

-- Alter table
ALTER TABLE "social_rent_earnings" RENAME COLUMN "earningsperweek" TO "earnings_per_week";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "social_rent_earnings" RENAME CONSTRAINT "socialrent_pkey" TO "social_rent_earnings_pkey";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

-- AlterTable
ALTER TABLE "social_rent_earnings" ALTER COLUMN "county" SET NOT NULL,
ALTER COLUMN "itl3" SET NOT NULL,
ALTER COLUMN "earnings_per_week" SET NOT NULL;
10 changes: 5 additions & 5 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ model SocialRentAdjustments {
@@map("soc_rent_adjustments")
}

model SocialRent {
model SocialRentEarnings {
id Int @id @default(autoincrement())
county String? @db.VarChar(250)
itl3 String? @db.VarChar(250)
earningsPerWeek Float? @map("earningsperweek")
county String @db.VarChar(250)
itl3 String @db.VarChar(250)
earningsPerWeek Float @map("earnings_per_week")
@@map("socialrent")
@@map("social_rent_earnings")
}

model GasBills {
Expand Down

0 comments on commit 20b9755

Please sign in to comment.