Skip to content

Commit 29c5cc0

Browse files
committed
test(api): add tests for updateLastActivityDate function to validate date constraints and successful updates
1 parent 7fcbaf8 commit 29c5cc0

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { createCandidacyHelper } from "../../../test/helpers/entities/create-candidacy-helper";
2+
import { updateLastActivityDate } from "./updateLastActivityDate";
3+
4+
describe("updateLastActivityDate", () => {
5+
test("should fail when readyForJuryEstimatedAt is in the past", async () => {
6+
const candidacy = await createCandidacyHelper();
7+
const pastDate = new Date();
8+
pastDate.setDate(pastDate.getDate() - 1);
9+
10+
await expect(async () => {
11+
await updateLastActivityDate({
12+
candidacyId: candidacy.id,
13+
readyForJuryEstimatedAt: pastDate,
14+
});
15+
}).rejects.toThrow(
16+
"La date de préparation pour le jury ne peut être dans le passé",
17+
);
18+
});
19+
20+
test("should fail when candidacy does not exist", async () => {
21+
const futureDate = new Date();
22+
futureDate.setDate(futureDate.getDate() + 30);
23+
24+
await expect(async () => {
25+
await updateLastActivityDate({
26+
candidacyId: "non-existent-id",
27+
readyForJuryEstimatedAt: futureDate,
28+
});
29+
}).rejects.toThrow();
30+
});
31+
32+
test("should successfully update lastActivityDate and readyForJuryEstimatedAt", async () => {
33+
const candidacy = await createCandidacyHelper();
34+
const futureDate = new Date();
35+
futureDate.setDate(futureDate.getDate() + 30);
36+
37+
const updatedCandidacy = await updateLastActivityDate({
38+
candidacyId: candidacy.id,
39+
readyForJuryEstimatedAt: futureDate,
40+
});
41+
42+
expect(updatedCandidacy.readyForJuryEstimatedAt?.getTime()).toBe(
43+
futureDate.getTime(),
44+
);
45+
46+
const now = new Date();
47+
const fiveSecondsAgo = new Date(now.getTime() - 5000);
48+
expect(updatedCandidacy.lastActivityDate?.getTime()).toBeGreaterThan(
49+
fiveSecondsAgo.getTime(),
50+
);
51+
expect(updatedCandidacy.lastActivityDate?.getTime()).toBeLessThanOrEqual(
52+
now.getTime(),
53+
);
54+
});
55+
});

0 commit comments

Comments
 (0)