Commit ddd7a349 authored by Simon Breiter's avatar Simon Breiter
Browse files

feat: wip

parent 186510d0
Pipeline #394187148 failed with stages
in 61 minutes and 53 seconds
......@@ -27,14 +27,30 @@ function createUsersRoute (dbConnection) {
}
})
router.get('/:userId', async (req, res) => {
try {
const user = await users.findOne({ _id: new ObjectId(req.params.userId) })
res.send(user)
} catch (e) {
console.error(e)
}
})
router
.route('/:userId')
.get(async (req, res) => {
try {
const user = await users.findOne({
_id: new ObjectId(req.params.userId)
})
res.send(user)
} catch (e) {
console.error(e)
}
})
.delete(async (req, res) => {
try {
const user = await users.remove({
_id: new ObjectId(req.params.userId)
})
res.send({
message: 'Deleted user.'
})
} catch (e) {
console.error(e)
}
})
return router
}
......
......@@ -18,9 +18,9 @@ beforeEach(() => {
db = dbConnection.db('test')
})
// afterEach(async () => {
// await db.dropDatabase()
// })
afterEach(async () => {
await db.dropDatabase()
})
test('Create a single users', done => {
request(app)
......@@ -81,7 +81,7 @@ test('Get all users', done => {
])
})
test('Get a single users', done => {
test('Get a single user', done => {
async.waterfall([
cb =>
request(app)
......@@ -98,7 +98,7 @@ test('Get a single users', done => {
.then(response => {
return cb(null, response)
}),
response => {
(response, cb) =>
request(app)
.get(`/users/${response.body[0]._id}`)
.set('Accept', 'application/json')
......@@ -106,10 +106,54 @@ test('Get a single users', done => {
.then(response => {
expect(response.body).toEqual({
_id: expect.anything(),
name: 'simon'
name: 'john'
})
done()
})
])
})
test('Delete a single user', done => {
async.waterfall([
cb =>
request(app)
.post('/users')
.send({ name: 'john' })
.set('Accept', 'application/json')
.expect(200)
.then(() => cb(null)),
cb =>
request(app)
.get('/users')
.set('Accept', 'application/json')
.expect(200)
.then(response => {
return cb(null, response)
}),
(response, cb) => {
const userId = response.body[0]._id
request(app)
.get(`/users/${userId}`)
.set('Accept', 'application/json')
.expect(200)
.then(response => {
expect(response.body).toEqual({
_id: expect.anything(),
name: 'john'
})
return cb(null, userId)
})
},
(userId, cb) =>
request(app)
.delete(`/users/${userId}`)
.set('Accept', 'application/json')
.expect(200)
.then(response => {
expect(response.body).toEqual({
message: 'Deleted user.'
})
done()
})
}
])
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment