Compare commits
11 Commits
dev
...
5160-backT
Author | SHA1 | Date |
---|---|---|
Alex Moreno | c46f379c8e | |
Alex Moreno | cfcfdc9d12 | |
Alex Moreno | dd16633b53 | |
Alex Moreno | 08ac3ab0a1 | |
Alex Moreno | 4bf4a263c4 | |
Alex Moreno | 20c308d228 | |
Alex Moreno | e4496cf062 | |
Alex Moreno | 964b92e497 | |
Alex Moreno | 84e0427d93 | |
Alex Moreno | a3488d44ae | |
Alex Moreno | 6ab6dbe51a |
|
@ -1,5 +1,7 @@
|
|||
const Docker = require('../db/docker.js');
|
||||
let dataSources = require('../loopback/server/datasources.json');
|
||||
const log = require('fancy-log');
|
||||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
process.on('warning', warning => {
|
||||
console.log(warning.name);
|
||||
|
@ -35,7 +37,25 @@ async function test() {
|
|||
err => err ? reject(err) : resolve());
|
||||
});
|
||||
// FIXME: Workaround to wait for loopback to be ready
|
||||
await app.models.Application.status();
|
||||
log('Waiting for backend is ready...');
|
||||
log('Application ready', await app.models.Application.status());
|
||||
|
||||
const params = {
|
||||
zoneFk: 1,
|
||||
geoFk: 20,
|
||||
isIncluded: false
|
||||
};
|
||||
log('Start upsert WITHOUT transaction');
|
||||
await models.ZoneIncluded.upsert(params);
|
||||
|
||||
log('Finish first upsert');
|
||||
log('Start transaction');
|
||||
const tx = await models.Zone.beginTransaction({});
|
||||
log('Start upsert WITH transaction');
|
||||
await models.ZoneIncluded.upsert(params, {transaction: tx});
|
||||
log('Finish second upsert');
|
||||
await tx.rollback();
|
||||
log('Finish rollback');
|
||||
|
||||
const Jasmine = require('jasmine');
|
||||
const jasmine = new Jasmine();
|
||||
|
@ -55,7 +75,7 @@ async function test() {
|
|||
const JunitReporter = require('jasmine-reporters');
|
||||
jasmine.addReporter(new JunitReporter.JUnitXmlReporter());
|
||||
|
||||
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;
|
||||
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
|
||||
jasmine.exitOnCompletion = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
const log = require('fancy-log');
|
||||
|
||||
describe('zone toggleIsIncluded()', () => {
|
||||
beforeAll(async() => {
|
||||
|
@ -16,17 +17,22 @@ describe('zone toggleIsIncluded()', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should return the created location with isIncluded true', async() => {
|
||||
fit('should return the created location with isIncluded true', async() => {
|
||||
log('transaction start');
|
||||
const tx = await models.Zone.beginTransaction({});
|
||||
log('transaction ready');
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
log('Zone.toggleIsIncluded start');
|
||||
let result = await models.Zone.toggleIsIncluded(1, 20, true, options);
|
||||
log('Zone.toggleIsIncluded finish');
|
||||
|
||||
expect(result.isIncluded).toBeTrue();
|
||||
|
||||
log('rollback start');
|
||||
await tx.rollback();
|
||||
log('rollback finish');
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const log = require('fancy-log');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('toggleIsIncluded', {
|
||||
description: 'Toggle include to delivery',
|
||||
|
@ -28,20 +30,30 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.toggleIsIncluded = async(id, geoId, isIncluded, options) => {
|
||||
log('Zone.toggleIsIncluded entry');
|
||||
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
if (typeof options == 'object') {
|
||||
log(`Don't use new transacction`);
|
||||
Object.assign(myOptions, options);
|
||||
}
|
||||
|
||||
if (isIncluded === undefined)
|
||||
return models.ZoneIncluded.destroyAll({zoneFk: id, geoFk: geoId}, myOptions);
|
||||
else {
|
||||
return models.ZoneIncluded.upsert({
|
||||
let data;
|
||||
if (isIncluded === undefined) {
|
||||
log('Zone.toggleIsIncluded destroyAll start');
|
||||
data = await models.ZoneIncluded.destroyAll({zoneFk: id, geoFk: geoId}, myOptions);
|
||||
} else {
|
||||
log('Zone.toggleIsIncluded upsert start');
|
||||
|
||||
data = await models.ZoneIncluded.upsert({
|
||||
zoneFk: id,
|
||||
geoFk: geoId,
|
||||
isIncluded: isIncluded
|
||||
}, myOptions);
|
||||
}
|
||||
log('Zone.toggleIsIncluded return');
|
||||
return data;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue