-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.test.js
119 lines (107 loc) · 2.22 KB
/
main.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
require("./config/env");
const request = require("supertest");
const main = require("./main");
const defaultConfig = {
session: {
driver: "memory"
},
strategies: {
google: {
clientID: "abc",
clientSecret: "def"
}
},
origins: {
"localhost:8080": {
domain: "google.com",
ip: undefined,
headers: {},
guard_emails: undefined
}
}
};
beforeEach(() => {
const debug = require("debug")("app");
global.debug = debug;
});
test("does nothing", () => {
expect(main).toThrow(Error);
});
test("starts", () => {
db = {
session: {
driver: "memory"
},
strategies: {
google: {
clientID: "abc",
clientSecret: "def"
}
}
};
const app = main(db);
expect(app).toBeDefined();
});
test("[GET] /status", done => {
const app = main(defaultConfig);
request(app)
.get("/status")
.expect(200)
.end(function(err, res) {
if (err) throw err;
done();
});
});
test("[GET] /api/user requires login", done => {
const app = main(defaultConfig);
request(app)
.get("/api/user")
.expect(302)
.expect("Location", "/login")
.end(function(err, res) {
if (err) throw err;
done();
});
});
test("[GET] /api/user/id requires login", done => {
const app = main(defaultConfig);
request(app)
.get("/api/user/id")
.expect(302)
.expect("Location", "/login")
.end(function(err, res) {
if (err) throw err;
done();
});
});
test("[GET] /logout", done => {
const app = main(defaultConfig);
request(app)
.get("/logout")
.expect(302)
.expect("Location", "/login")
.end(function(err, res) {
if (err) throw err;
done();
});
});
test("[GET] /auth/google", done => {
const app = main(defaultConfig);
request(app)
.get("/auth/google")
.expect(302)
.end(function(err, res) {
if (err) throw err;
expect(res.headers.location).toContain("accounts.google.com");
done();
});
});
xtest("[GET] /auth/google/callback", () => {
// todo: figure out how to test this
});
xtest("[GET] /api/user", done => {
// todo: figure out how to test this
});
xtest("[GET] /api/user/id", done => {
// todo: figure out how to test this
});