fixtures restart implementation
This commit is contained in:
parent
468b9195ac
commit
dd89df9a71
|
@ -32,7 +32,7 @@ module.exports = function(Client) {
|
|||
Client.activate = function(id, ctx, cb) {
|
||||
Client.findById(id, function(err, client) {
|
||||
if (!err) {
|
||||
Client.update({id: client.id}, {active: !client.active});
|
||||
Client.update({id: client.id}, {active: !client.active});
|
||||
|
||||
let filter = {where: {clientFk: client.id}, fields: ['started', 'ended']};
|
||||
|
||||
|
@ -56,7 +56,7 @@ module.exports = function(Client) {
|
|||
request(options);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
cb(null, !client.active);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,10 +1,25 @@
|
|||
import app from '../../../../server/server';
|
||||
import {catchErrors} from '../../../../../../services/utils/jasmineHelpers';
|
||||
import {restoreFixtures} from '../../../../../../services/db/testing_fixtures';
|
||||
import restoreFixtures from '../../../../../../services/db/testing_fixtures';
|
||||
|
||||
describe('Client Create()', () => {
|
||||
beforeEach(() => {
|
||||
restoreFixtures();
|
||||
let fixturesToApply = {tables: ['`account`.`user`'], inserts: [
|
||||
`INSERT INTO salix.Account(id,name,password,roleFk,active,email)
|
||||
VALUES
|
||||
(1, 'BruceWayne', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'BruceWayne@verdnatura.es'),
|
||||
(2, 'PetterParker', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'PetterParker@verdnatura.es'),
|
||||
(3, 'ClarkKent', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'ClarkKent@verdnatura.es'),
|
||||
(4, 'TonyStark', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'TonyStark@verdnatura.es'),
|
||||
(5, 'MaxEisenhardt', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'MaxEisenhardt@verdnatura.es'),
|
||||
(6, 'DavidCharlesHaller', 'ac754a330530832ba1bf7687f577da91', 18, 1, 'DavidCharlesHaller@verdnatura.es'),
|
||||
(7, 'HankPym', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'HankPym@verdnatura.es'),
|
||||
(8, 'CharlesXavier', 'ac754a330530832ba1bf7687f577da91', 18, 1, 'CharlesXavier@verdnatura.es'),
|
||||
(9, 'BruceBanner', 'ac754a330530832ba1bf7687f577da91', 18, 1, 'BruceBanner@verdnatura.es'),
|
||||
(10, 'JessicaJones', 'ac754a330530832ba1bf7687f577da91', 9, 1, 'JessicaJones@verdnatura.es'),
|
||||
(11, 'Cyborg', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'cyborg@verdnatura.es');`
|
||||
]};
|
||||
beforeEach(done => {
|
||||
restoreFixtures(fixturesToApply, done);
|
||||
});
|
||||
|
||||
let newAccountData = {
|
||||
|
|
|
@ -1,16 +1,42 @@
|
|||
let mysql = require('mysql');
|
||||
|
||||
let connection = mysql.createConnection({
|
||||
multipleStatements: false,
|
||||
multipleStatements: true,
|
||||
host: 'localhost',
|
||||
user: 'root',
|
||||
password: '',
|
||||
database: 'salix'
|
||||
});
|
||||
|
||||
export function restoreFixtures() {
|
||||
// connection.connect();
|
||||
// connection.query('CALL truncateDatabase');
|
||||
// connection.disconect();
|
||||
// console.log('dirty fixtures');
|
||||
let errorHandler = callback => {
|
||||
return error => {
|
||||
if (error)
|
||||
throw error;
|
||||
callback();
|
||||
};
|
||||
};
|
||||
|
||||
let insertFixtures = (inserts, callback) => {
|
||||
connection.query(inserts[0], errorHandler(callback));
|
||||
// connection.query('SET FOREIGN_KEY_CHECKS = 1');
|
||||
};
|
||||
|
||||
let truncate = (tables, callback) => {
|
||||
let truncatesSQL = tables.reduce((accumulator, currentValue, i) => {
|
||||
let sql = 'TRUNCATE TABLE ' + currentValue + '; ';
|
||||
return (`${accumulator}${sql}`);
|
||||
}, '');
|
||||
|
||||
connection.query(truncatesSQL.slice(0, -2), errorHandler(callback));
|
||||
};
|
||||
|
||||
connection.connect();
|
||||
|
||||
export default function restoreFixtures(fixturesToApply, callback) {
|
||||
connection.query('SET FOREIGN_KEY_CHECKS = 0', () => {
|
||||
truncate(fixturesToApply.tables, () => {
|
||||
insertFixtures(fixturesToApply.inserts, callback);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue