Skip to content

Commit 124cb5c

Browse files
committed
write test bloominstituteoftechnology#4 and fix some bugs to make it pass
1 parent 39f0a43 commit 124cb5c

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

api/auth/auth-router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const {
66
} = require("../middleware/checkCreds");
77
const Users = require("../users/user-model");
88

9-
router.post('/register', checkUserAndPass, usernameNotTaken, (req, res) => {
9+
router.post('/register', checkUserAndPass, usernameNotTaken, (req, res, next) => {
1010
Users.add(req.body)
1111
.then( newUser => res.status(201).json(newUser))
1212
.catch(next);

api/server.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,9 @@ describe("[POST] /api/auth/register", () => {
7171
expect(await db("users")).toHaveLength(6);
7272
})
7373

74+
test('[4] responds with newly created user', async () => {
75+
let res = await request(server).post("/api/auth/register").send({username: "george", password: "pass"});
76+
expect(res.body).toMatchObject({username: "george"});
77+
})
78+
7479
})

api/users/user-model.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
db = require("../../data/dbConfig");
22

33
async function add(user) {
4-
db("users").insert(user)
5-
.then( ([newUserID]) => {
6-
return getBy({id: newUserID});
7-
});
4+
return db("users").insert(user)
5+
.then( async ([newUserID]) => getBy({id: newUserID}) )
86
}
97

108
function getBy(filter) {

0 commit comments

Comments
 (0)