Skip to content

Commit 413e593

Browse files
add tests for discord actions validator (#1204)
1 parent fd96e76 commit 413e593

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const Sinon = require("sinon");
2+
const { validateGroupRoleBody, validateMemberRoleBody } = require("../../../middlewares/validators/discordactions");
3+
const { expect } = require("chai");
4+
5+
describe("Middleware | Validators | discord actions", function () {
6+
describe("validateGroupRoleBody", function () {
7+
it("lets the request pass to the next function", async function () {
8+
const res = {};
9+
const req = {
10+
body: {
11+
rolename: "test",
12+
},
13+
};
14+
const nextSpy = Sinon.spy();
15+
await validateGroupRoleBody(req, res, nextSpy);
16+
expect(nextSpy.calledOnce).to.be.equal(true);
17+
});
18+
it("stops the propogation of the event to next function", async function () {
19+
const res = {
20+
boom: {
21+
badRequest: () => {},
22+
},
23+
};
24+
const nextSpy = Sinon.spy();
25+
const req = {
26+
body: {},
27+
};
28+
await validateGroupRoleBody(req, res, nextSpy).catch((err) => {
29+
expect(err).to.be.an.instanceOf(Error);
30+
});
31+
expect(nextSpy.callCount).to.be.equal(0);
32+
});
33+
});
34+
describe("validateMemberRoleBody", function () {
35+
it("lets the request pass to the next function", async function () {
36+
const req = {
37+
body: {
38+
userid: "12346re54d4e434",
39+
roleid: "12345654325544565",
40+
},
41+
};
42+
const nextSpy = Sinon.spy();
43+
const res = {};
44+
await validateMemberRoleBody(req, res, nextSpy);
45+
expect(nextSpy.calledOnce).to.be.equal(true);
46+
});
47+
it("stops the propogation to the next function", async function () {
48+
const res = {
49+
boom: {
50+
badRequest: () => {},
51+
},
52+
};
53+
const nextSpy = Sinon.spy();
54+
const req = {
55+
body: {},
56+
};
57+
await validateMemberRoleBody(req, res, nextSpy).catch((err) => {
58+
expect(err).to.be.an.instanceOf(Error);
59+
});
60+
expect(nextSpy.callCount).to.be.equal(0);
61+
});
62+
});
63+
});

0 commit comments

Comments
 (0)