Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/database/developmentDbConfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"username": "api",
"username": "dev_user",
"password": "ecp1950",
"database": "dev_db",
"host": "127.0.0.1",
"host": "ecp_dev_db",
"dialect": "postgres",
"logging": false,
"seederStorage": "json",
Expand Down
6 changes: 3 additions & 3 deletions config/database/testDbConfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"username": "api",
"password": "notsetyet",
"username": "test_user",
"password": "ecp1950",
"database": "test_db",
"host": "127.0.0.1",
"host": "ecp_test_db",
"dialect": "postgres",
"logging": false,
"seederStorage": "json",
Expand Down
2 changes: 1 addition & 1 deletion controllers/authentication/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const validate = {

function authenticate(req, res, next) {
User.findOne({
where: { email: req.body.email },
where: { email: req.body.email.toLowerCase() },
include: { model: Resource, required: false }
})
.then( user => {
Expand Down
4 changes: 2 additions & 2 deletions controllers/users/changeEmail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ tests('POST /users/:userId/changeEmail', changeEmail => {
.send({ token: emailConfirmation.token })
.end( (err, res) => {
test.same(
{ status: res.status, message: res.body.message },
{ status: 200, message: lang.messages.emailConfirmed }
{ status: res.status, email: res.body.email },
{ status: 200, email: '[email protected]' }
);
test.end();
});
Expand Down
4 changes: 2 additions & 2 deletions controllers/users/emailConfirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const validate = {

function confirm(req, res, next) {
services.emailConfirmation.confirm(req.body.token)
.then( () => {
.then( userEmail => {
res.status(200);
res.locals.message = lang.messages.emailConfirmed;
res.locals.email = userEmail;
next();
})
.catch(err => next(err));
Expand Down
4 changes: 2 additions & 2 deletions controllers/users/emailConfirmation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ tests('POST /emailConfirm', emailConfirmation => {
.send({ token: emailConfirmationData.token })
.end( (err, res) => {
test.same(
{ status: res.status, message: res.body.message },
{ status: 200, message: lang.messages.emailConfirmed }
{ status: res.status, email: res.body.email },
{ status: 200, email: '[email protected]' }
);
emailConfirmationData.getUser().then( user => {
test.error(!user.confirmed, 'User not confirmed');
Expand Down
2 changes: 1 addition & 1 deletion models/services/_generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.exports = (Model, keyword) => {
order: ['id']
};

_.mapKeys(optionalArguments, val => _.merge(params, val));
_.mapKeys(optionalArguments, (val, key) => _.merge(params, { [key]: val }));

return Model.findAndCountAll(params);
};
Expand Down
4 changes: 4 additions & 0 deletions models/services/emailConfirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ function confirm(token) {
return user.save();
})
.then(function(user) {
this.userEmail = user.email;
return removeEmailConfirmation(user.id);
})
.then(function() {
return this.userEmail;
});
}

Expand Down
34 changes: 25 additions & 9 deletions utils/fixtures/index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
'use strict';
/* eslint-disable no-console */
const pg = require('pg');
const Promise = require('bluebird');
const cleaner = require('postgres-cleaner');

const dbArgument = () => (process.argv[3] === 'dev')
? 'dev_db'
: 'test_db';

const dbUser = () => (process.argv[3] === 'dev')
? 'dev_user'
: 'test_user';

function recreateDatabase() {
var connectionString = 'postgres://postgres@localhost/postgres';
var connectionString =
`postgres://${dbUser()}:ecp1950@ecp_${dbArgument()}/${dbArgument()}`;

pg.connect(connectionString)
.then( connection =>
connection.query(`drop database ${dbArgument()}`).then( () => connection)
)
.then( connection =>
connection.query(`create database ${dbArgument()}`)
.then( () => process.exit(0))
)
.then( connection => {
return connection.query(
'SELECT table_name FROM information_schema.tables ' +
'WHERE table_schema = \'public\''
)
.then( tables => {
if (tables.rows.length === 0) return;

let promises = tables.rows.map(table =>
connection.query(`DROP TABLE "${table.table_name}" CASCADE`)
);

return Promise.all(promises);
});
})
.then( () => process.exit(0))
.catch( err => {
console.log(err);
process.exit(1);
});
}

function cleanDatabase() {
var connectionString = `postgres://postgres@localhost/${dbArgument()}`;
var connectionString =
`postgres://${dbUser()}:ecp1950@ecp_${dbArgument()}/${dbArgument()}`;

pg.connect(connectionString, (err, connection) => {
if (err) throw err;
Expand Down
2 changes: 1 addition & 1 deletion utils/fixtures/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const uuid = require('node-uuid');
const populatePresets = require('../migrations').populatePresets;

const preset = () => ({
path: uuid.v1(),
path: `images/${uuid.v1()}.jpg`,
mimetype: 'image/jpeg',
extension: 'jpg'
});
Expand Down
5 changes: 1 addition & 4 deletions utils/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ function prependS3(model, name, keepResources = false) {
let obj = model.toJSON();

if (!keepResources) obj.resource = undefined;
if (img) {
obj[name] =
`${s3Prefix}/images/${model.resource.path}.${model.resource.extension}`;
}
if (img) obj[name] = `${s3Prefix}/${model.resource.path}`;
return obj;
}

Expand Down