Commit 74e323e3 authored by Jure's avatar Jure

Merge branch 'fix_user_mutations' into 'master'

fix(model-user): fix update user mutation's password hashing

See merge request !498
parents f48be8c5 5c50fda4
Pipeline #11295 passed with stages
in 8 minutes and 37 seconds
......@@ -30,7 +30,14 @@ const resolvers = {
deleteUser(_, { id }, ctx) {
return ctx.connectors.User.delete(id, ctx)
},
updateUser(_, { id, input }, ctx) {
async updateUser(_, { id, input }, ctx) {
if (input.password) {
input.passwordHash = await ctx.connectors.User.model.hashPassword(
input.password,
)
delete input.password
}
return ctx.connectors.User.update(id, input, ctx)
},
// Authentication
......
process.env.NODE_CONFIG = `{"pubsweet":{
"components":[
"@pubsweet/model-user",
"@pubsweet/model-team"
]
}}`
const User = require('../src/user')
const { dbCleaner, api } = require('pubsweet-server/test')
const { fixtures } = require('@pubsweet/model-user/test')
const authentication = require('pubsweet-server/src/authentication')
describe('User mutations', () => {
// let token
// let user
beforeEach(async () => {
await dbCleaner()
// user = await new User(fixtures.user).save()
// token = authentication.token.create(user)
})
it('a user can sign up', async () => {
const { body } = await api.graphql.query(
`mutation($input: UserInput) {
createUser(input: $input) {
username
}
}`,
{
input: {
username: 'hi',
email: 'hi@example.com',
password: 'hello',
},
},
)
expect(body).toEqual({
data: {
createUser: {
username: 'hi',
},
},
})
})
it('a user can update a password', async () => {
const user = await new User(fixtures.user).save()
const token = authentication.token.create(user)
const { body } = await api.graphql.query(
`mutation($id: ID, $input: UserInput) {
updateUser(id: $id, input: $input) {
username
}
}`,
{
id: user.id,
input: {
username: 'hi',
email: 'hi@example.com',
password: 'hello2',
},
},
token,
)
expect(body).toEqual({
data: {
updateUser: {
username: 'hi',
},
},
})
const oldHash = user.passwordHash
const newHash = await User.find(user.id).passwordHash
expect(oldHash).not.toEqual(newHash)
})
})
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