-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
70 lines (64 loc) · 2.28 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
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
const supertest = require("supertest");
const { app } = require("./index.js");
const cookieSession = require("cookie-session");
test("Users who are logged out are redirected to registration when attempting to go to petition", () => {
cookieSession.mockSessionOnce({
userId: false,
});
return supertest(app)
.get("/petition")
.then((response) => {
expect(response.headers.location).toBe("/register");
});
});
test("Users who are logged in are redirected to the petition page when they attempt to go the registration page", () => {
cookieSession.mockSessionOnce({
userId: true,
});
return supertest(app)
.get("/register")
.then((response) => {
expect(response.headers.location).toBe("/petition");
});
});
test("Users who are logged in are redirected to the petition page when they attempt to go the login page", () => {
cookieSession.mockSessionOnce({
userId: true,
});
return supertest(app)
.get("/login")
.then((response) => {
expect(response.headers.location).toBe("/petition");
});
});
test("Users who are logged in and have signed the petition are redirected to the thank you page when they attempt to go to the petition page or submit a signature", () => {
cookieSession.mockSessionOnce({
userId: true,
sigId: true,
});
return supertest(app)
.get("/petition")
.then((response) => {
expect(response.headers.location).toBe("thanks");
});
});
test("Users who are logged in and have not signed the petition are redirected to the petition page when they attempt to go to the thank you page", () => {
cookieSession.mockSession({
userId: true,
});
return supertest(app)
.get("/thanks")
.then((response) => {
expect(response.headers.location).toBe("/petition");
});
});
test("Users who are logged in and have not signed the petition are redirected to the petition page when they attempt to go to the signers page", () => {
cookieSession.mockSession({
userId: true,
});
return supertest(app)
.get("/signers")
.then((response) => {
expect(response.headers.location).toBe("/petition");
});
});