Skip to content
Merged

Dev #44

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "groups" ADD COLUMN "result_house_id" UUID;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ model Group {
houseRank4 String? @map("house_rank_4") @db.Uuid
houseRank5 String? @map("house_rank_5") @db.Uuid
houseRankSub String? @map("house_rank_sub") @db.Uuid
resultHouseId String? @map("result_house_id") @db.Uuid

owner User @relation("GroupOwner", fields: [ownerId], references: [id])
users User[] @relation("UserGroup")
Expand Down
1 change: 1 addition & 0 deletions src/controller/group/groupController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ describe("GroupController", () => {
houseRank4: null,
houseRank5: null,
houseRankSub: null,
resultHouseId: null,
};

mockGroupUsecase.createGroup.mockResolvedValue(mockGroup);
Expand Down
8 changes: 5 additions & 3 deletions src/repository/group/groupRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe("GroupRepository", () => {
house4: null,
house5: null,
houseSub: null,
resultHouseId: null,
};

(mockPrisma.group.findUnique as jest.Mock).mockResolvedValue(mockGroup);
Expand Down Expand Up @@ -188,12 +189,12 @@ describe("GroupRepository", () => {
it("should remove user from group with transaction", async () => {
const mockTx = {
user: { update: jest.fn() },
group: {
group: {
update: jest.fn().mockResolvedValue({ memberCount: 2 }), // Group still has members
findUnique: jest.fn(),
delete: jest.fn()
delete: jest.fn(),
},
house: { update: jest.fn() }
house: { update: jest.fn() },
} as any;

(mockPrisma.$transaction as jest.Mock).mockImplementation(
Expand Down Expand Up @@ -227,6 +228,7 @@ describe("GroupRepository", () => {
houseRank4: null,
houseRank5: null,
houseRankSub: null,
resultHouseId: null,
};

(mockPrisma.group.update as jest.Mock).mockResolvedValue(mockGroup);
Expand Down
26 changes: 16 additions & 10 deletions src/usecase/group/groupUsecase.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { GroupRepository } from "@/repository/group/groupRepository";
import { HouseRepository } from "@/repository/house/houseRepository";
import { InviteCodeGenerator } from "@/utils/inviteCodeGenerator";
Expand Down Expand Up @@ -46,6 +45,7 @@ describe("GroupUsecase", () => {
houseRank4: null,
houseRank5: null,
houseRankSub: null,
resultHouseId: null,
};

mockGroupRepository.findUserGroup.mockResolvedValue(null);
Expand Down Expand Up @@ -115,6 +115,7 @@ describe("GroupUsecase", () => {
houseRank4: null,
houseRank5: null,
houseRankSub: null,
resultHouseId: null,
};

mockGroupRepository.findUserGroup.mockResolvedValue(existingGroup as any);
Expand Down Expand Up @@ -187,6 +188,7 @@ describe("GroupUsecase", () => {
houseRank4: null,
houseRank5: null,
houseRankSub: null,
resultHouseId: null,
};

(InviteCodeGenerator.isValidFormat as jest.Mock).mockReturnValue(true);
Expand Down Expand Up @@ -255,6 +257,7 @@ describe("GroupUsecase", () => {
houseRank4: null,
houseRank5: null,
houseRankSub: null,
resultHouseId: null,
};

(InviteCodeGenerator.isValidFormat as jest.Mock).mockReturnValue(true);
Expand Down Expand Up @@ -285,6 +288,7 @@ describe("GroupUsecase", () => {
houseRank4: null,
houseRank5: null,
houseRankSub: null,
resultHouseId: null,
};

(InviteCodeGenerator.isValidFormat as jest.Mock).mockReturnValue(true);
Expand All @@ -308,6 +312,7 @@ describe("GroupUsecase", () => {
houseRank4: null,
houseRank5: null,
houseRankSub: null,
resultHouseId: null,
};

const currentGroup = {
Expand Down Expand Up @@ -337,6 +342,7 @@ describe("GroupUsecase", () => {
houseRank4: null,
houseRank5: null,
houseRankSub: null,
resultHouseId: null,
};

(InviteCodeGenerator.isValidFormat as jest.Mock).mockReturnValue(true);
Expand Down Expand Up @@ -379,9 +385,9 @@ describe("GroupUsecase", () => {
it("should throw error if user is not in any group", async () => {
mockGroupRepository.findGroupById.mockResolvedValue(null);

await expect(groupUsecase.leaveGroup("group-1", "user-1")).rejects.toThrow(
"User is not in any group"
);
await expect(
groupUsecase.leaveGroup("group-1", "user-1")
).rejects.toThrow("User is not in any group");
});

it("should throw error if group is confirmed", async () => {
Expand All @@ -401,9 +407,9 @@ describe("GroupUsecase", () => {

mockGroupRepository.findGroupById.mockResolvedValue(currentGroup as any);

await expect(groupUsecase.leaveGroup("group-1", "user-1")).rejects.toThrow(
"Cannot leave a confirmed group"
);
await expect(
groupUsecase.leaveGroup("group-1", "user-1")
).rejects.toThrow("Cannot leave a confirmed group");
});

it("should throw error if owner tries to leave", async () => {
Expand All @@ -423,9 +429,9 @@ describe("GroupUsecase", () => {

mockGroupRepository.findGroupById.mockResolvedValue(currentGroup as any);

await expect(groupUsecase.leaveGroup("group-1", "user-1")).rejects.toThrow(
"Group owner cannot leave their own group"
);
await expect(
groupUsecase.leaveGroup("group-1", "user-1")
).rejects.toThrow("Group owner cannot leave their own group");
});
});

Expand Down