Skip to content

Commit

Permalink
Problème lors de la mise à jour de l'adresse d'activité close #87
Browse files Browse the repository at this point in the history
Problème lors de la mise à jour des informations de profil close #56
  • Loading branch information
jsmadja committed Oct 1, 2017
1 parent faddc86 commit 1256653
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions back/src/user/user-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Promise = require('bluebird');
const Bcrypt = require('bcrypt-then');
const saltRounds = 10;
const _ = require('lodash');

const Database = require('../database');

Expand Down Expand Up @@ -252,9 +253,9 @@ const UserRepository = {

updatePhone: (userId, phone) => Database.query(`UPDATE User SET phone = '${phone}' WHERE id = ${userId}`),

updateAddress: (userId, address) => Database.query(`UPDATE User SET address = '${JSON.stringify(address)}' WHERE id = ${userId}`),
updateAddress: (userId, address) => Database.query(`UPDATE User SET address = '${_.replace(JSON.stringify(address), `'`, `\\'`)}' WHERE id = ${userId}`),

updateHome: (userId, home) => Database.query(`UPDATE User SET home = '${JSON.stringify(home)}' WHERE id = ${userId}`),
updateHome: (userId, home) => Database.query(`UPDATE User SET home = '${_.replace(JSON.stringify(home), `'`, `\\'`)}' WHERE id = ${userId}`),

getManagement: () =>
Database.query(`
Expand Down
30 changes: 30 additions & 0 deletions back/tests/integration/user/user-repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,34 @@ describe('User Repository', () => {
.then(done)
.catch(done);
});

it('should update address with quote', (done) => {
const email = 'jsmadja@xebia.fr';
const name = 'Julien Smadja';
const password = 'password';

UserRepository
.addNewUser({email, name, password})
.then(() => UserRepository.findUserByEmail(email, password))
.then((user) => UserRepository.updateAddress(user.id, '12 rue d\'amsterdam'))
.then(() => UserRepository.findUserByEmailAndPassword(email, password))
.then(user => assert.equal(user.address, '"12 rue d\'amsterdam"'))
.then(done)
.catch(done);
});

it('should update home with quote', (done) => {
const email = 'jsmadja@xebia.fr';
const name = 'Julien Smadja';
const password = 'password';

UserRepository
.addNewUser({email, name, password})
.then(() => UserRepository.findUserByEmail(email, password))
.then((user) => UserRepository.updateHome(user.id, '12 rue d\'amsterdam'))
.then(() => UserRepository.findUserByEmailAndPassword(email, password))
.then(user => assert.equal(user.home, '"12 rue d\'amsterdam"'))
.then(done)
.catch(done);
});
});

0 comments on commit 1256653

Please sign in to comment.