-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlagChallenge.test.ts
More file actions
103 lines (85 loc) · 3.2 KB
/
FlagChallenge.test.ts
File metadata and controls
103 lines (85 loc) · 3.2 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { Format } from "../../../app/challenges-platform/models";
import {
FlagChallenge,
FlagChallengeSubmission,
FlagTransformer,
} from "../../../app/event-management/models/FlagChallenge";
import { challengeFactory } from "../../challenges-platform/factories/challenge-factory";
import { participantFactory } from "../../challenges-platform/factories/participant-factory";
describe("FlagTransformer", () => {
describe("newChallenge", () => {
it("will create a new FlagChallenge instance with the provided payload", () => {
const payload = {
id: 1,
uuid: "abc123",
title: "Test Challenge",
body: "This is a test challenge",
points: 10,
metadata: {
flag: "test_flag",
},
};
const challenge = FlagTransformer.newChallenge(payload);
expect(challenge).toBeInstanceOf(FlagChallenge);
expect(challenge.id).toBe(payload.id);
expect(challenge.uuid).toBe(payload.uuid);
expect(challenge.title).toBe(payload.title);
expect(challenge.body).toBe(payload.body);
expect(challenge.format).toBe(Format.TEXT);
expect(challenge.points).toBe(payload.points);
expect(challenge.flag).toBe(payload.metadata.flag);
});
});
describe("validateChallengeMetadata", () => {
it('will return true if the payload has the "flag" property', () => {
const payload = {
flag: "test_flag",
};
const result = FlagTransformer.validateChallengeMetadata(payload);
expect(result).toBe(true);
});
it('will return false if the payload does not have the "flag" property', () => {
const payload = {};
const result = FlagTransformer.validateChallengeMetadata(payload);
expect(result).toBe(false);
});
});
describe("newSubmission", () => {
it("will create a new FlagChallengeSubmission instance with the provided payload, challenge, and participant", async () => {
const payload = {
id: 1,
uuid: "abc123",
flag: "test_flag",
};
const challenge = await challengeFactory();
const participant = await participantFactory();
const submission = FlagTransformer.newSubmission(
payload,
challenge,
participant,
);
if (!(submission instanceof FlagChallengeSubmission))
fail("Expected submission to be correct type");
expect(submission).toBeInstanceOf(FlagChallengeSubmission);
expect(submission.id).toBe(payload.id);
expect(submission.uuid).toBe(payload.uuid);
expect(submission.challenge).toBe(challenge);
expect(submission.participant).toBe(participant);
expect(submission.flag).toBe(payload.flag);
});
});
describe("validateSubmissionMetadata", () => {
it('should return true if the payload has the "flag" property', () => {
const payload = {
flag: "test_flag",
};
const result = FlagTransformer.validateSubmissionMetadata(payload);
expect(result).toBe(true);
});
it('should return false if the payload does not have the "flag" property', () => {
const payload = {};
const result = FlagTransformer.validateSubmissionMetadata(payload);
expect(result).toBe(false);
});
});
});