back end refactor for the fixtures setup plus some test on client create()
This commit is contained in:
parent
78e5dd3109
commit
984540a3f2
|
@ -58,6 +58,7 @@
|
|||
"karma-jasmine": "^1.1.0",
|
||||
"karma-sourcemap-loader": "^0.3.7",
|
||||
"karma-webpack": "^2.0.4",
|
||||
"md5": "^2.2.1",
|
||||
"merge-stream": "^1.0.1",
|
||||
"mysql": "^2.15.0",
|
||||
"nightmare": "^2.10.0",
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
"posttest": "npm run lint && nsp check"
|
||||
},
|
||||
"dependencies": {
|
||||
"md5": "^2.2.1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var app = require('../../../server/server');
|
||||
let app = require('../../../server/server');
|
||||
let md5 = require('md5');
|
||||
|
||||
module.exports = function(Client) {
|
||||
Client.remoteMethod('createUserProfile', {
|
||||
|
@ -23,7 +24,7 @@ module.exports = function(Client) {
|
|||
let user = {
|
||||
name: data.userName,
|
||||
email: firstEmail,
|
||||
password: parseInt(Math.random() * 100000000000000)
|
||||
password: md5(parseInt(Math.random() * 100000000000000))
|
||||
};
|
||||
|
||||
app.models.Account.beginTransaction('READ COMMITTED', (error, transaction) => {
|
||||
|
|
|
@ -9,15 +9,15 @@ describe('Client Create()', () => {
|
|||
restoreFixtures();
|
||||
});
|
||||
|
||||
let data = {
|
||||
name: 'MaxEisenhardt',
|
||||
userName: 'Magneto',
|
||||
email: 'magneto@marvel.com',
|
||||
fi: 'X-tax number',
|
||||
socialName: 'The X-Men'
|
||||
let newAccountData = {
|
||||
name: 'Wade',
|
||||
userName: 'Deadpool',
|
||||
email: 'Deadpool@marvel.com',
|
||||
fi: 'DP',
|
||||
socialName: 'Deadpool Marvel'
|
||||
};
|
||||
|
||||
it('should find jessica', done => {
|
||||
it('should find Charles Xavier', done => {
|
||||
app.models.Account.findOne({where: {name: 'CharlesXavier'}})
|
||||
.then(account => {
|
||||
expect(account.name).toEqual('CharlesXavier');
|
||||
|
@ -26,22 +26,52 @@ describe('Client Create()', () => {
|
|||
.catch(catchErrors(done));
|
||||
});
|
||||
|
||||
it('should create a new account', done => {
|
||||
app.models.Client.createUserProfile(data, () => {
|
||||
app.models.Account.findOne({where: {name: data.userName}})
|
||||
it("should not find Deadpool as he's not created yet", done => {
|
||||
app.models.Account.findOne({where: {name: newAccountData.userName}})
|
||||
.then(account => {
|
||||
expect(account.name).toEqual(data.userName);
|
||||
app.models.Client.findOne({where: {name: data.name}})
|
||||
expect(account).toEqual(null);
|
||||
app.models.Client.findOne({where: {name: newAccountData.name}})
|
||||
.then(client => {
|
||||
expect(client.id).toEqual(account.id);
|
||||
expect(client.name).toEqual(data.name);
|
||||
expect(client.email).toEqual(data.email);
|
||||
expect(client.fi).toEqual(data.fi);
|
||||
expect(client.socialName).toEqual(data.socialName);
|
||||
expect(client).toEqual(null);
|
||||
done();
|
||||
});
|
||||
})
|
||||
.catch(catchErrors(done));
|
||||
});
|
||||
|
||||
it('should not be able to create a user if exists', done => {
|
||||
app.models.Client.findOne({where: {name: 'Charles Xavier'}})
|
||||
.then(client => {
|
||||
let formerAccountData = {
|
||||
name: client.name,
|
||||
userName: client.userName,
|
||||
email: client.email,
|
||||
fi: client.fi,
|
||||
socialName: client.socialName
|
||||
};
|
||||
|
||||
expect(app.models.Client.createUserProfile(formerAccountData)).toBeFalsy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
// awaiting for fixtures
|
||||
// it('should create a new account', done => {
|
||||
// app.models.Client.createUserProfile(data => {
|
||||
// app.models.Account.findOne({where: {name: data.userName}})
|
||||
// .then(account => {
|
||||
// expect(account.name).toEqual(data.userName);
|
||||
// app.models.Client.findOne({where: {name: data.name}})
|
||||
// .then(client => {
|
||||
// expect(client.id).toEqual(account.id);
|
||||
// expect(client.name).toEqual(data.name);
|
||||
// expect(client.email).toEqual(data.email);
|
||||
// expect(client.fi).toEqual(data.fi);
|
||||
// expect(client.socialName).toEqual(data.socialName);
|
||||
// done();
|
||||
// });
|
||||
// })
|
||||
// .catch(catchErrors(done));
|
||||
// });
|
||||
// });
|
||||
});
|
||||
|
|
|
@ -1,57 +1,16 @@
|
|||
// let mysql = require('mysql');
|
||||
let mysql = require('mysql');
|
||||
|
||||
// let connection = mysql.createConnection({
|
||||
// multipleStatements: false,
|
||||
// host: 'localhost',
|
||||
// user: 'root',
|
||||
// password: '',
|
||||
// database: 'salix'
|
||||
// });
|
||||
// let connected;
|
||||
// let firstQuery;
|
||||
// let secondQuery;
|
||||
// let thirdQuery;
|
||||
// let start = Date.now();
|
||||
// let end = false;
|
||||
// let callback = (error, results, fields) => {
|
||||
// thirdQuery = Date.now() - start - connected - firstQuery - secondQuery;
|
||||
// console.log('connected', connected);
|
||||
// console.log('firstQuery', firstQuery);
|
||||
// console.log('secondQuery', secondQuery);
|
||||
// console.log('thirdQuery', thirdQuery);
|
||||
|
||||
// if (error) {
|
||||
// connection.end();
|
||||
// throw error;
|
||||
// }
|
||||
// if (end)
|
||||
// connection.end();
|
||||
// };
|
||||
|
||||
// let truncate = (error, results, fields) => {
|
||||
// if (error) {
|
||||
// connection.end();
|
||||
// connection.query('SET FOREIGN_KEY_CHECKS = 1', callback);
|
||||
// throw error;
|
||||
// }
|
||||
// let truncatesSQL = results.reduce((accumulator, currentValue, i) => {
|
||||
// let sql = 'TRUNCATE TABLE `' + currentValue.table_schema + '`.`' + currentValue.table_name + '`; ';
|
||||
// return `${accumulator}${sql}`;
|
||||
// }, '');
|
||||
|
||||
// end = true;
|
||||
// connection.query(truncatesSQL.slice(0, -2), callback);
|
||||
// };
|
||||
|
||||
// connection.connect();
|
||||
// connected = Date.now() - start;
|
||||
// connection.query('SET FOREIGN_KEY_CHECKS = 0', callback);
|
||||
// firstQuery = Date.now() - start - connected;
|
||||
// connection.query(`SELECT table_schema, table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema IN ('account', 'bi','bs', 'cache', 'edi', 'hedera', 'pbx', 'salix', 'util', 'vn', 'vn2008', 'vncontrol') AND table_rows < 1;`, truncate);
|
||||
// secondQuery = Date.now() - start - connected - firstQuery;
|
||||
let connection = mysql.createConnection({
|
||||
multipleStatements: false,
|
||||
host: 'localhost',
|
||||
user: 'root',
|
||||
password: '',
|
||||
database: 'salix'
|
||||
});
|
||||
|
||||
export function restoreFixtures() {
|
||||
// connection.connect();
|
||||
// connection.query('CALL truncateDatabase'); calls the MySQL procedure
|
||||
console.log('fixtures restored');
|
||||
// connection.query('CALL truncateDatabase');
|
||||
// connection.disconect();
|
||||
// console.log('fixtures restored');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue