diff --git a/services/client/common/methods/client/specs/create.spec.js b/services/client/common/methods/client/specs/create.spec.js index a19ef074c..7894c2812 100644 --- a/services/client/common/methods/client/specs/create.spec.js +++ b/services/client/common/methods/client/specs/create.spec.js @@ -1,7 +1,14 @@ +import app from '../../../../server/server'; import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; -let app = require('../../../../server/server'); +import {restoreFixtures} from '../../../../../../services/db/testing_fixtures'; + +jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; describe('Client Create()', () => { + beforeEach(() => { + restoreFixtures(); + }); + let data = { name: 'MaxEisenhardt', userName: 'Magneto', @@ -10,7 +17,16 @@ describe('Client Create()', () => { socialName: 'The X-Men' }; - it('should createa new account', done => { + it('should find jessica', done => { + app.models.Account.findOne({where: {name: 'CharlesXavier'}}) + .then(account => { + expect(account.name).toEqual('CharlesXavier'); + done(); + }) + .catch(catchErrors(done)); + }); + + it('should create a new account', done => { app.models.Client.createUserProfile(data, () => { app.models.Account.findOne({where: {name: data.userName}}) .then(account => { diff --git a/services/db/localDB09Inserts.sql b/services/db/localDB09Inserts.sql index 66046946c..da5599ff4 100644 --- a/services/db/localDB09Inserts.sql +++ b/services/db/localDB09Inserts.sql @@ -459,7 +459,7 @@ INSERT INTO `vn2008`.`empresa_grupo`(`empresa_grupo_id`, `grupo`) INSERT INTO `vn2008`.`empresa`(`id`, `abbreviation`, `registro`, `gerente_id`, `alta`, `baja`, `logo`, `oficial`, `cyc`, `rgb`, `mail`, `cuno`, `ODBC_DATE`, `Id_Cliente`, `digito_factura`, `Id_Proveedores_account`, `morosidad`, `empresa_grupo`) VALUES - ('442', 'WAY', 'Wayne Industries, Inc. operates as a warehouse for steel products. Wayne Industries, Inc. was founded in 1989 and is based in Wayne, Michigan.', '2', '1989-11-19', NULL, NULL, '1', '1', '00FF00', 'BruceWayne@verdnatura.es', NULL, '1989-08-11 12:31:22', '10', '1', NULL, '1', '1'); + (442, 'WAY', 'Wayne Industries, Inc. operates as a warehouse for steel products. Wayne Industries, Inc. was founded in 1989 and is based in Wayne, Michigan.', '2', '1989-11-19', NULL, NULL, '1', '1', '00FF00', 'BruceWayne@verdnatura.es', NULL, '1989-08-11 12:31:22', '10', '1', NULL, '1', '1'); INSERT INTO `salix`.`Ticket`(`id`, `agencyFk`, `employeeFk`, `date`, `hour`, `clientFk`, `addressFk`) VALUES diff --git a/services/db/testing_fixtures.js b/services/db/testing_fixtures.js new file mode 100644 index 000000000..b4da5cbe5 --- /dev/null +++ b/services/db/testing_fixtures.js @@ -0,0 +1,57 @@ +// 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; + +export function restoreFixtures() { + // connection.connect(); + // connection.query('CALL truncateDatabase'); calls the MySQL procedure + console.log('fixtures restored'); +} diff --git a/services/loopback/server/datasources.test.json b/services/loopback/server/datasources.test.json index 5f988ebf1..49407698d 100644 --- a/services/loopback/server/datasources.test.json +++ b/services/loopback/server/datasources.test.json @@ -23,5 +23,4 @@ "connectTimeout": 20000, "acquireTimeout": 20000 } -} - +} \ No newline at end of file diff --git a/services/mailer/application/mail.js b/services/mailer/application/mail.js index 2d3a2c626..2cc8c7465 100644 --- a/services/mailer/application/mail.js +++ b/services/mailer/application/mail.js @@ -63,7 +63,7 @@ module.exports = { console.log('Mail sent ' + info.messageId + ' [' + info.response + ']'); cb(); - } catch(e) { + } catch (e) { throw e; } }); @@ -85,7 +85,7 @@ module.exports = { params.attachments.forEach(function(attachment) { result.attachments.push(attachment); }); - + this.send(result.recipient, result.subject, result.body, result.attachments, params, error => { if (error) return cb(error); diff --git a/services/print/application/config.js b/services/print/application/config.js index c46f236f8..53a157937 100644 --- a/services/print/application/config.js +++ b/services/print/application/config.js @@ -7,7 +7,7 @@ function getFile(fileName) { try { let envFile = 'datasources.development.json'; - + if (process.env.NODE_ENV === 'test') envFile = 'datasources.test.json'; diff --git a/services_tests.js b/services_tests.js index 3aed20116..1fb70fdb5 100644 --- a/services_tests.js +++ b/services_tests.js @@ -1,5 +1,7 @@ require('babel-core/register')({presets: ['es2015']}); +process.env.NODE_ENV = 'test'; + process.on('warning', warning => { console.log(warning.name); console.log(warning.message);