-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.test.js
74 lines (65 loc) · 2.32 KB
/
server.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
71
72
73
74
const supertest = require("supertest");
const { app, ERRORS, parseDbErrors } = require("./server.js");
const cookieSession = require("cookie-session");
const e = require("express");
const request = supertest(app);
test("[logged out] petition redirects to registration", () => {
cookieSession.mockSessionOnce({});
return request
.get("/petition")
.expect(302)
.expect("location", "/registration");
});
test("[logged in] (registration || login) redirects to petition", () => {
cookieSession.mockSession({ userId: 1 });
return Promise.all([
request
.get("/registration")
.expect(302)
.expect("location", "/petition"),
request.get("/login").expect(302).expect("location", "/petition"),
]);
});
test("[logged in, signed] (petition || submit signature) redirects to thank you", () => {
cookieSession.mockSession({ userId: 1, signatureId: 1 });
return Promise.all([
request.get("/petition").expect(302).expect("location", "/thanks"),
request.post("/petition").expect(302).expect("location", "/thanks"),
]);
});
test("[logged in, not signed] (thanks | signers) redirects to petition", () => {
cookieSession.mockSession({ userId: 1, signatureId: undefined });
return Promise.all([
request.get("/thanks").expect(302).expect("location", "/petition"),
request.get("/signers").expect(302).expect("location", "/petition"),
]);
});
const testUser = {
first: "Arturo",
last: "Bini",
email: "arturo@bini.it",
password: "testpassword",
age: 32,
city: "berlin",
url: "bini.it",
};
const stringifyData = (arr, user) => {
let result = [];
arr.forEach((el) => result.push(`${el}=${user[el]}`));
return result.join("&");
};
// test("registration succeeds with good data", () => {
// cookieSession.mockSession({});
// return request
// .post("/registration")
// .send(stringifyData(["first", "last", "email", "password"], testUser))
// .expect(302)
// .expect("location", "/moreinfo")
// .expect((res) => {
// expect(res.body).not.toContain("error-overlay");
// });
// });
test("registration fails with bad data", () => {
cookieSession.mockSession({});
return request.post("/registration").send("first=test").expect(302);
});