Skip to content

Commit d417c32

Browse files
committed
write first 2 tests for login endpoint
1 parent 9012521 commit d417c32

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

api/server.test.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe("[POST] /api/auth/register", () => {
117117
expect(res.body.password).not.toBe("matthew");
118118
})
119119

120-
test('[5] responds with newly created user', async () => {
120+
test('[6] responds with newly created user', async () => {
121121
let res = await request(server).post("/api/auth/register").send({username: "george", password: "pass"});
122122
expect(res.body).toMatchObject({username: "george"});
123123

@@ -128,7 +128,7 @@ describe("[POST] /api/auth/register", () => {
128128
expect(res.body).toMatchObject({username: "caleb"});
129129
})
130130

131-
test('[6] new user is in db', async () => {
131+
test('[7] new user is in db', async () => {
132132
let res = await request(server)
133133
.post("/api/auth/register")
134134
.send({username: "george", password: "pass"});
@@ -156,3 +156,33 @@ describe("[POST] /api/auth/register", () => {
156156
})
157157

158158
})
159+
160+
describe("[POST] /api/auth/login", () => {
161+
test('[1] responds with "username and password required" if not provided', async () => {
162+
let res = await request(server).post("/api/auth/login");
163+
expect(res.body.message).toBe("username and password required");
164+
165+
res = await request(server).post("/api/auth/login").send({username: "", password: "pass"})
166+
expect(res.body.message).toBe("username and password required");
167+
168+
res = await request(server).post("/api/auth/login").send({username: " ", password: "pass"})
169+
expect(res.body.message).toBe("username and password required");
170+
171+
res = await request(server).post("/api/auth/login").send({username: "user", password: ""})
172+
expect(res.body.message).toBe("username and password required");
173+
174+
res = await request(server).post("/api/auth/login").send({username: "", password: ""})
175+
expect(res.body.message).toBe("username and password required");
176+
177+
res = await request(server).post("/api/auth/login").send({username: "user"})
178+
expect(res.body.message).toBe("username and password required");
179+
180+
res = await request(server).post("/api/auth/login").send({password: "pass"})
181+
expect(res.body.message).toBe("username and password required");
182+
})
183+
184+
test('[2] responds with "invalid credentials" if username is not in db', async () => {
185+
let res = await request(server).post("/api/auth/login").send({username: "george", password: "pass"});
186+
expect(res.body.message).toBe("invalid credentials");
187+
})
188+
})

0 commit comments

Comments
 (0)