forked from ayesha1209/taskChamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirebaseOperations.test.js
More file actions
62 lines (52 loc) · 1.43 KB
/
FirebaseOperations.test.js
File metadata and controls
62 lines (52 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { createUser, addTask } from "./FirebaseOperations";
import { User } from "./models/User";
import { Task } from "./models/Task";
import { ref, set } from "firebase/database";
jest.mock("firebase/database", () => ({
ref: jest.fn(),
set: jest.fn(),
}));
describe("Firebase Operations", () => {
beforeEach(() => {
jest.clearAllMocks();
});
it("should create a user in Firebase", async () => {
const user = new User(
"userId1",
"username",
"password",
"01-01-2000",
"CountryName"
);
ref.mockReturnValue("mockRef");
set.mockResolvedValueOnce("mockResponse");
await createUser(user);
expect(ref).toHaveBeenCalledWith("users/userId1");
expect(set).toHaveBeenCalledWith("mockRef", {
username: "username",
password: "password",
birthdate: "01-01-2000",
country: "CountryName",
tasks: user.tasks,
});
});
it("should add a task to a user in Firebase", async () => {
const task = new Task(
"taskId1",
"01-09-2024",
"Example Task",
"medium",
false
);
ref.mockReturnValue("mockRef");
set.mockResolvedValueOnce("mockResponse");
await addTask("userId1", task);
expect(ref).toHaveBeenCalledWith("users/userId1/tasks/taskId1");
expect(set).toHaveBeenCalledWith("mockRef", {
date: "01-09-2024",
taskname: "Example Task",
level: "medium",
is_done: false,
});
});
});