Skip to content

Commit cba21de

Browse files
add tests for auctions validator (#1202)
1 parent 1aa75af commit cba21de

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const Sinon = require("sinon");
2+
const { createAuction, placeBid } = require("../../../middlewares/validators/auctions");
3+
const { expect } = require("chai");
4+
5+
describe("auctions validator", function () {
6+
describe("create auctions validator", function () {
7+
it("allows the request to pass", async function () {
8+
const req = {
9+
body: {
10+
item_type: "css art",
11+
quantity: 100,
12+
initial_price: 100,
13+
end_time: 1234234234,
14+
},
15+
};
16+
const res = {};
17+
const nextSpy = Sinon.spy();
18+
await createAuction(req, res, nextSpy);
19+
expect(nextSpy.calledOnce).to.be.equal(true);
20+
});
21+
it("stops the request to propogate to next", async function () {
22+
const req = {
23+
body: {
24+
"": "",
25+
},
26+
};
27+
const res = {
28+
boom: {
29+
badRequest: () => {},
30+
},
31+
};
32+
const nextSpy = Sinon.spy();
33+
await createAuction(req, res, nextSpy).catch((err) => {
34+
expect(err).to.be.an.instanceOf(Error);
35+
});
36+
expect(nextSpy.callCount).to.be.equal(0);
37+
});
38+
});
39+
describe("place bid validator", function () {
40+
it("allows the request to pass", async function () {
41+
const req = {
42+
body: {
43+
bid: 100,
44+
},
45+
};
46+
const res = {};
47+
const nextSpy = Sinon.spy();
48+
await placeBid(req, res, nextSpy);
49+
expect(nextSpy.calledOnce).to.be.equal(true);
50+
});
51+
52+
it("stops the request to propogate to next", async function () {
53+
const req = {
54+
body: {
55+
"": "",
56+
},
57+
};
58+
const res = {
59+
boom: {
60+
badRequest: () => {},
61+
},
62+
};
63+
const nextSpy = Sinon.spy();
64+
await placeBid(req, res, nextSpy).catch((err) => {
65+
expect(err).to.be.an.instanceOf(Error);
66+
expect(nextSpy.callCount).to.be.equal(0);
67+
});
68+
});
69+
});
70+
});

0 commit comments

Comments
 (0)