-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparticipants-service.test.ts
More file actions
79 lines (64 loc) · 2.51 KB
/
participants-service.test.ts
File metadata and controls
79 lines (64 loc) · 2.51 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { ParticipantsService } from "../../../app/challenges-platform";
import { uuid } from "../../../app/common";
import { participantFactory } from "../factories/participant-factory";
describe("ParticipantsService", () => {
describe("create", () => {
describe("when the email is valid", () => {
it("succesfully creates a challenge", async () => {
const email = "test@email.com";
const result = await ParticipantsService.create(email);
if (!result.ok) fail("Expected result to be Ok");
expect(result.val.email).toBe(email);
});
});
});
describe("findByUuid", () => {
describe("when the id is invalid", () => {
it("returns an error", async () => {
const result = await ParticipantsService.findByUuid("invalid-id");
expect(result.err).toBe(true);
expect(result.val.toString()).toBe("Error: Invalid UUID");
});
});
describe("when there is an existing record", () => {
it("returns the participant", async () => {
const participant = await participantFactory();
const result = await ParticipantsService.findByUuid(participant.uuid);
if (!result.ok) fail("Expected result to be Ok");
expect(result.val.email).toBe(participant.email);
});
});
describe("when there is no record", () => {
it("returns an error", async () => {
const testUuid = uuid.create();
const result = await ParticipantsService.findByUuid(testUuid);
expect(result.err).toBe(true);
expect(result.val.toString()).toBe("Error: Participant not found");
});
});
});
describe("findById", () => {
describe("when there is an existing record", () => {
it("returns the participant", async () => {
const participant = await participantFactory();
const result = await ParticipantsService.findById(participant.id);
if (!result.ok) fail("Expected result to be Ok");
expect(result.val.email).toBe(participant.email);
});
});
describe("when there is no record", () => {
it("returns an error", async () => {
const testId = -1;
const result = await ParticipantsService.findById(testId);
expect(result.err).toBe(true);
expect(result.val.toString()).toBe("Error: Participant not found");
});
});
});
describe("findByEmail", () => {
it("throws an error", async () => {
const result = await ParticipantsService.findByEmail();
expect(result.err).toBe(true);
});
});
});