-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
36 lines (33 loc) · 1.23 KB
/
index.test.js
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
const { app } = require("./index");
const supertest = require("supertest");
const cookieSession = require("cookie-session");
// test("GET /home returns h1 as response", (req, res) => {
// return supertest(app)
// .get("/home")
// .then(res => {
// expect(res.statusCode).toBe(200);
// expect(res.text).toContain("welcome");
// });
// });
test("POST / product redirects to /home", () => {
return supertest(app)
.post("/product")
.then(res => {
expect(res.statusCode).toBe(302);
expect(res.text).toContain("Found");
expect(res.headers.location).toBe("/home");
});
});
test("POST /product sets req.session.wouldLikeToBuy to true", () => {
//step 1: create the cookie
let cookie = {};
//step 2: tell cookie-session-mock that the "cookie" variable is our cookie and that, any time a user writes data to a cookie, it should be placed in the "cookie-variable"
cookieSession.mockSessionOnce(cookie);
return supertest(app)
.post("/product")
.then(res => {
console.log("cookie: ", cookie);
expect(cookie.wouldLikeToBuy).toBe(true);
expect(res.statusCode).toBe(302);
});
});