Skip to content

Commit

Permalink
TestedEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Inlet-back committed Oct 26, 2024
1 parent cd7ddd1 commit 2a4eec7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 105 deletions.
10 changes: 0 additions & 10 deletions task_yell/.env.sample

This file was deleted.

54 changes: 36 additions & 18 deletions task_yell/test/event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import {
deleteEvent,
} from "../src/lib/events";
import { Event } from "../src/lib/types";
import {
createData,
readData,
readSingleData,
updateData,
deleteData,
} from "../src/firebase/firestore";

// Firebase 認証をモック
jest.mock("../src/firebase/client-app", () => ({
Expand Down Expand Up @@ -40,48 +47,59 @@ describe("Event CRUD operations", () => {
reccurence: ["weekly"],
};

const mockUserId = "mockUserId";

it("should create an event", async () => {
const { createData } = require("../src/firebase/firestore");
(createData as jest.Mock).mockResolvedValue("mockEventId");
(readData as jest.Mock).mockResolvedValue([]);

const eventId = await createEvent(mockEvent);
expect(eventId).toBe("mockEventId");
expect(createData).toHaveBeenCalledWith("events", mockEvent);
const result = await createEvent(mockUserId, mockEvent);
expect(result).toBeNull();
expect(createData).toHaveBeenCalledWith(
`users/${mockUserId}/events`,
mockEvent
);
});

it("should read all events", async () => {
const { readData } = require("../src/firebase/firestore");
(readData as jest.Mock).mockResolvedValue([mockEvent]);

const events = await readEvents();
const events = await readEvents(mockUserId);
expect(events).toEqual([mockEvent]);
expect(readData).toHaveBeenCalledWith("events");
expect(readData).toHaveBeenCalledWith(`users/${mockUserId}/events`);
});

it("should read a single event", async () => {
const { readSingleData } = require("../src/firebase/firestore");
(readSingleData as jest.Mock).mockResolvedValue(mockEvent);

const event = await readSingleEvent("mockEventId");
const event = await readSingleEvent(mockUserId, "mockEventId");
expect(event).toEqual(mockEvent);
expect(readSingleData).toHaveBeenCalledWith("events", "mockEventId");
expect(readSingleData).toHaveBeenCalledWith(
`users/${mockUserId}/events`,
"mockEventId"
);
});

it("should update an event", async () => {
const { updateData } = require("../src/firebase/firestore");
(updateData as jest.Mock).mockResolvedValue(undefined);

await updateEvent("mockEventId", { title: "Updated Event" });
expect(updateData).toHaveBeenCalledWith("events", "mockEventId", {
title: "Updated Event",
});
await updateEvent(mockUserId, "mockEventId", { title: "Updated Event" });
expect(updateData).toHaveBeenCalledWith(
`users/${mockUserId}/events`,
"mockEventId",
{
title: "Updated Event",
}
);
});

it("should delete an event", async () => {
const { deleteData } = require("../src/firebase/firestore");
(deleteData as jest.Mock).mockResolvedValue(undefined);

await deleteEvent("mockEventId");
expect(deleteData).toHaveBeenCalledWith("events", "mockEventId");
await deleteEvent(mockUserId, "mockEventId");
expect(deleteData).toHaveBeenCalledWith(
`users/${mockUserId}/events`,
"mockEventId"
);
});
});
77 changes: 0 additions & 77 deletions task_yell/test/firestore.test.ts

This file was deleted.

0 comments on commit 2a4eec7

Please sign in to comment.