mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-22 01:02:00 -07:00
Added tests for delete user
This commit is contained in:
+2
-2
@@ -51,8 +51,8 @@ User.methods.generateToken = function generateToken () {
|
||||
const user = this
|
||||
|
||||
const token = jwt.sign({ id: user.id }, config.token)
|
||||
//console.log(`config.token: ${config.token}`)
|
||||
//console.log(`generated token: ${token}`)
|
||||
// console.log(`config.token: ${config.token}`)
|
||||
// console.log(`generated token: ${token}`)
|
||||
return token
|
||||
}
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ async function updateUser (ctx) {
|
||||
async function deleteUser (ctx) {
|
||||
const user = ctx.body.user
|
||||
|
||||
await user.deleteOne()
|
||||
await user.remove()
|
||||
|
||||
ctx.status = 200
|
||||
ctx.body = {
|
||||
|
||||
+52
-25
@@ -333,44 +333,71 @@ describe('Users', () => {
|
||||
assert.equal(user.username, 'updatedcoolname')
|
||||
})
|
||||
})
|
||||
/*
|
||||
|
||||
describe('DELETE /users/:id', () => {
|
||||
it('should not delete user if token is invalid', (done) => {
|
||||
request
|
||||
.delete('/users/1')
|
||||
.set({
|
||||
Accept: 'application/json',
|
||||
Authorization: 'Bearer 1'
|
||||
})
|
||||
.expect(401, done)
|
||||
it('should not delete user if token is invalid', async () => {
|
||||
try {
|
||||
const options = {
|
||||
method: 'DELETE',
|
||||
uri: `${LOCALHOST}/users/1`,
|
||||
resolveWithFullResponse: true,
|
||||
json: true,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer 1`
|
||||
}
|
||||
}
|
||||
|
||||
await rp(options)
|
||||
assert.equal(true, false, 'Unexpected behavior')
|
||||
} catch (err) {
|
||||
assert.equal(err.statusCode, 401)
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw 404 if user doesn\'t exist', (done) => {
|
||||
it('should throw 404 if user doesn\'t exist', async () => {
|
||||
const { token } = context
|
||||
request
|
||||
.delete('/users/1')
|
||||
.set({
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
})
|
||||
.expect(404, done)
|
||||
|
||||
try {
|
||||
const options = {
|
||||
method: 'DELETE',
|
||||
uri: `${LOCALHOST}/users/1`,
|
||||
resolveWithFullResponse: true,
|
||||
json: true,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
|
||||
await rp(options)
|
||||
assert.equal(true, false, 'Unexpected behavior')
|
||||
} catch (err) {
|
||||
assert.equal(err.statusCode, 404)
|
||||
}
|
||||
})
|
||||
|
||||
it('should delete user', (done) => {
|
||||
it('should delete user', async () => {
|
||||
const {
|
||||
user: { _id },
|
||||
token
|
||||
} = context
|
||||
|
||||
request
|
||||
.delete(`/users/${_id}`)
|
||||
.set({
|
||||
const options = {
|
||||
method: 'DELETE',
|
||||
uri: `${LOCALHOST}/users/${_id}`,
|
||||
resolveWithFullResponse: true,
|
||||
json: true,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
})
|
||||
.expect(200, done)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const result = await rp(options)
|
||||
// console.log(`result: ${util.inspect(result.body)}`)
|
||||
|
||||
assert.equal(result.body.success, true)
|
||||
})
|
||||
})
|
||||
*/
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user