Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('edit resource', async t => {
let user = new User({
name: 'ademir',
password: await argon2.hash('123456', await argon2.generateSalt())
})
await user.save()
const {status} = await t.context.request.patch(`/users/${user.get('name')}`).send({
password: '654321'
})
t.is(status, 200)
user = await User.findById(user.get('_id'))
t.true(await argon2.verify(user.get('password'), '654321'))
})
test.before(async () => {
const user = new User({
name: 'ademir',
password: await argon2.hash('123456', await argon2.generateSalt())
})
await user.save()
})
router.post('/', async ctx => {
const {name, password} = ctx.request.body
const hash = await argon2.hash(password, await argon2.generateSalt())
const user = new User({name, password: hash})
await user.save()
ctx.body = {user}
ctx.status = 201
})