Skip to content

Commit

Permalink
notification tested
Browse files Browse the repository at this point in the history
  • Loading branch information
Inlet-back committed Oct 26, 2024
1 parent e88ed15 commit 7d50472
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions task_yell/test/notification.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import {
createNotification,
readNotification,
readSingleNotification,
updateNotification,
deleteNotification,
} from "../src/lib/notifications";
import { Notification } from "../src/lib/types";
import {
createData,
readData,
readSingleData,
updateData,
deleteData,
} from "../src/firebase/firestore";

// Firebase 認証をモック
jest.mock("../src/firebase/client-app", () => ({
auth: {
signInWithEmailAndPassword: jest.fn(),
signOut: jest.fn(),
onAuthStateChanged: jest.fn(),
},
db: jest.fn(),
storage: jest.fn(),
firebaseApp: jest.fn(),
}));

jest.mock("../src/firebase/firestore", () => ({
createData: jest.fn(),
readData: jest.fn(),
readSingleData: jest.fn(),
updateData: jest.fn(),
deleteData: jest.fn(),
}));

describe("Notification CRUD operations", () => {
const mockNotification: Notification = {
datetime: new Date(),
type: "push",
eventOrTaskRef: "mockEventId",
userId: "mockUserId",
};

it("should create a notification", async () => {
(createData as jest.Mock).mockResolvedValue("mockNotificationId");

const notificationId = await createNotification(mockNotification);
expect(notificationId).toBe("mockNotificationId");
expect(createData).toHaveBeenCalledWith("notifications", mockNotification);
});

it("should read all notifications", async () => {
(readData as jest.Mock).mockResolvedValue([mockNotification]);

const notifications = await readNotification();
expect(notifications).toEqual([mockNotification]);
expect(readData).toHaveBeenCalledWith("notifications");
});

it("should read a single notification", async () => {
(readSingleData as jest.Mock).mockResolvedValue(mockNotification);

const notification = await readSingleNotification("mockNotificationId");
expect(notification).toEqual(mockNotification);
expect(readSingleData).toHaveBeenCalledWith(
"notifications",
"mockNotificationId",
);
});

it("should update a notification", async () => {
(updateData as jest.Mock).mockResolvedValue(undefined);

await updateNotification("mockNotificationId", {
eventOrTaskRef: "Updated Event ID",
});
expect(updateData).toHaveBeenCalledWith(
"notifications",
"mockNotificationId",
{
eventOrTaskRef: "Updated Event ID",
},
);
});

it("should delete a notification", async () => {
(deleteData as jest.Mock).mockResolvedValue(undefined);

await deleteNotification("mockNotificationId");
expect(deleteData).toHaveBeenCalledWith(
"notifications",
"mockNotificationId",
);
});
});

0 comments on commit 7d50472

Please sign in to comment.