-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.spec.js
100 lines (91 loc) · 3.08 KB
/
server.spec.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
const request = require("supertest");
const server = require("./server");
const db = require("./data/dbConfig");
const checkuser = require("./API/PatientAPI/auth-user-middleware");
describe("auth model", () => {
it("should set testing environment", () => {
expect(process.env.NODE_ENV).toBe("testing");
});
});
describe("user registration function", () => {
it("should register new user and return 201", async () => {
await db("users").truncate();
const res = await request(server)
.post("/api/auth/user-register")
.send({
userEmail: "[email protected]",
userPassword: "pokerface",
userName: "Lady Gaga",
});
expect(res.status).toBe(201);
});
});
describe("user login function", () => {
it("should return messagen and token after correct login", async () => {
const login = await request(server)
.post("/api/auth/user-login")
.send({ userEmail: "[email protected]", userPassword: "pokerface" });
expect(login.status).toBe(200);
expect(login.text).toContain("token");
expect(login.text).toContain("message");
});
});
describe("login function failure", () => {
it("should return 401 error when login credential is incomplete", async () => {
const loginfail = await request(server)
.post("/api/auth/user-login")
.send({ userEmail: "[email protected]" });
expect(loginfail.status).toBe(401);
});
});
describe("medical professional registration", () => {
it("should return 404 error if registration is incomplete", async () => {
const medregfail = await request(server)
.post("/api/auth/med-register")
.send({ medicEmail: "[email protected]" });
expect(medregfail.status).toBe(404);
});
});
//Registration test not working
describe("medical professional registration", () => {
it("registration type is json", async () => {
await db("medicalProfessionals").truncate();
const med = await request(server)
.post("/api/auth/med-register")
.send({
medicEmail: "[email protected]",
medicPassword: "grande",
medicFirstName: "Sam",
medicLastName: "Grande",
company: "Methodist",
position: "Nurse",
});
// expect(med.type).toMatch(/json/i);
expect(med.status).toBe(200);
});
});
// describe("get patient from user successfully", () => {
// it("testing middleware", () => {
// return new Promise(resolve => {
// const mock = jest.checkuser(req, res, err => {
// if (!err) {
// // resolve(req.localStorage.token);
// console.log(res);
// }
// });
// expect(mock).toBeTruthy();
// });
// });
// // it("will display data", async () => {
// // const login = await request(server)
// // .post("/api/auth/user-login")
// // .send({ userEmail: "[email protected]", userPassword: "pokerface" });
// // const token = login.token;
// // return request(server)
// // req.headers.authorization = token
// // .get("/api/user/1")
// // .then(response => {
// // expect(response.status).toBe(200);
// // });
// // });
// });