Skip to content

Commit fd96e76

Browse files
add tests for challenges validator (#1203)
1 parent cba21de commit fd96e76

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const Sinon = require("sinon");
2+
const { createChallenge } = require("../../../middlewares/validators/challenges");
3+
const { expect } = require("chai");
4+
5+
describe("Middleware | Validators | Challenges", function () {
6+
describe("create challenge validator", function () {
7+
it("lets the request pass to next", async function () {
8+
const req = {
9+
body: {
10+
level: "Noob",
11+
title: "The noob challenge",
12+
start_date: 1254324345,
13+
end_date: 354654345,
14+
},
15+
};
16+
const res = {};
17+
const nextSpy = Sinon.spy();
18+
await createChallenge(req, res, nextSpy);
19+
expect(nextSpy.calledOnce).to.be.equal(true);
20+
});
21+
it("Stops the propogation of the next", async function () {
22+
const req = {
23+
body: {
24+
level: "Noob",
25+
},
26+
};
27+
const res = {
28+
boom: {
29+
badRequest: () => {},
30+
},
31+
};
32+
const nextSpy = Sinon.spy();
33+
await createChallenge(req, res, nextSpy).catch((err) => {
34+
expect(err).to.be.an.instanceOf(Error);
35+
});
36+
expect(nextSpy.calledOnce).to.be.equal(false);
37+
});
38+
});
39+
});

0 commit comments

Comments
 (0)