Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2473-restore_ticket
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2020-10-13 15:41:04 +02:00
commit 2045e35170
10 changed files with 84 additions and 70 deletions

2
Jenkinsfile vendored
View File

@ -72,7 +72,7 @@ pipeline {
/* stage('Backend') {
steps {
nodejs('node-lts') {
sh 'gulp backTestOnce --ci'
sh 'gulp launchBackTest --ci'
}
}
} */

View File

@ -40,7 +40,7 @@ module.exports = class Docker {
let runChown = process.platform != 'linux';
const container = await this.execP(`docker run --env RUN_CHOWN=${runChown} -d ${dockerArgs} salix-db`);
this.id = container.stdout;
this.id = container.stdout.trim();
try {
if (this.isRandom) {
@ -177,7 +177,7 @@ module.exports = class Docker {
}
rm() {
return this.execP(`docker rm -fv ${this.id}`);
return this.execP(`docker stop ${this.id} && docker rm -v ${this.id}`);
}
/**

View File

@ -67,9 +67,9 @@ back.description = `Starts backend and database service`;
const defaultTask = gulp.parallel(front, back);
defaultTask.description = `Starts all application services`;
// Backend tests
// Backend tests - Private method
async function backTestOnce(done) {
async function launchBackTest(done) {
let err;
let dataSources = require('./loopback/server/datasources.json');
@ -126,14 +126,16 @@ async function backTestOnce(done) {
if (err)
throw err;
}
backTestOnce.description = `Runs the backend tests once using a random container, can receive --ci arg to save reports on a xml file`;
launchBackTest.description = `Runs the backend tests once using a random container, can receive --ci arg to save reports on a xml file`;
// Backend tests
function backTest(done) {
const nodemon = require('gulp-nodemon');
nodemon({
exec: ['node --tls-min-v1.0 ./node_modules/gulp/bin/gulp.js'],
args: ['backTestOnce'],
args: ['launchBackTest'],
watch: backSources,
done: done
});
@ -404,7 +406,7 @@ module.exports = {
backOnly,
backWatch,
backTest,
backTestOnce,
launchBackTest,
e2e,
i,
install,

View File

@ -29,18 +29,18 @@ describe('Update Claim', () => {
it(`should throw an error as the user doesn't have rights`, async() => {
const forbiddenState = 3;
const salesPersonId = 18;
let data = {
claimStateFk: forbiddenState,
observation: 'valid observation'
};
let ctx = {
req: {
accessToken: {
userId: salesPersonId
}
},
args: {
claimStateFk: forbiddenState,
observation: 'valid observation'
}
};
await app.models.Claim.updateClaim(ctx, newInstance.id, data)
await app.models.Claim.updateClaim(ctx, newInstance.id)
.catch(e => {
error = e;
});
@ -51,23 +51,23 @@ describe('Update Claim', () => {
it(`should success to update the claim within privileges `, async() => {
const correctState = 4;
const salesPersonId = 18;
let data = {
observation: 'valid observation',
claimStateFk: correctState,
hasToPickUp: false
};
let ctx = {
req: {
accessToken: {
userId: salesPersonId
}
},
args: {
observation: 'valid observation',
claimStateFk: correctState,
hasToPickUp: false
}
};
await app.models.Claim.updateClaim(ctx, newInstance.id, data);
await app.models.Claim.updateClaim(ctx, newInstance.id);
let claimUpdated = await app.models.Claim.findById(newInstance.id);
expect(claimUpdated.observation).toEqual(data.observation);
expect(claimUpdated.observation).toEqual(ctx.args.observation);
});
it('should change some sensible fields as salesAssistant', async() => {
@ -75,28 +75,28 @@ describe('Update Claim', () => {
spyOn(chatModel, 'sendCheckingPresence').and.callThrough();
const salesAssistantId = 21;
let data = {
claimStateFk: 3,
workerFk: 5,
observation: 'another valid observation',
hasToPickUp: true
};
const ctx = {
req: {
accessToken: {userId: salesAssistantId},
headers: {origin: 'http://localhost'}
},
args: {
claimStateFk: 3,
workerFk: 5,
observation: 'another valid observation',
hasToPickUp: true
}
};
ctx.req.__ = (value, params) => {
return params.nickname;
};
await app.models.Claim.updateClaim(ctx, newInstance.id, data);
await app.models.Claim.updateClaim(ctx, newInstance.id);
let claimUpdated = await app.models.Claim.findById(newInstance.id);
expect(claimUpdated.observation).toEqual(data.observation);
expect(claimUpdated.claimStateFk).toEqual(data.claimStateFk);
expect(claimUpdated.workerFk).toEqual(data.workerFk);
expect(claimUpdated.observation).toEqual(ctx.args.observation);
expect(claimUpdated.claimStateFk).toEqual(ctx.args.claimStateFk);
expect(claimUpdated.workerFk).toEqual(ctx.args.workerFk);
expect(chatModel.sendCheckingPresence).toHaveBeenCalled();
});
});

View File

@ -1,35 +1,47 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('updateClaim', {
Self.remoteMethod('updateClaim', {
description: 'Update a claim with privileges',
accessType: 'WRITE',
accepts: [{
arg: 'ctx',
type: 'Object',
http: {source: 'context'}
}, {
arg: 'id',
type: 'number',
required: true,
type: 'Number',
description: 'Claim id',
http: {source: 'path'}
}, {
arg: 'data',
type: 'object',
required: true,
description: 'Data to update on the model',
http: {source: 'body'}
},
{
arg: 'workerFk',
type: 'Number'
},
{
arg: 'claimStateFk',
type: 'Number'
},
{
arg: 'observation',
type: 'String'
},
{
arg: 'hasToPickUp',
type: 'boolean'
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/:id/updateClaim`,
verb: 'post'
verb: 'patch',
path: `/updateClaim/:id`
}
});
Self.updateClaim = async(ctx, id, data) => {
Self.updateClaim = async(ctx, id) => {
const models = Self.app.models;
const userId = ctx.req.accessToken.userId;
const args = ctx.args;
const $t = ctx.req.__; // $translate
const claim = await models.Claim.findById(id, {
include: {
@ -41,17 +53,20 @@ module.exports = Self => {
}
}
});
let changedHasToPickUp = false;
if (args.hasToPickUp)
changedHasToPickUp = true;
const canUpdate = await canChangeState(ctx, claim.claimStateFk);
const hasRights = await canChangeState(ctx, data.claimStateFk);
const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant');
const changedHasToPickUp = claim.hasToPickUp != data.hasToPickUp;
if (!canUpdate || !hasRights || changedHasToPickUp && !isSalesAssistant)
throw new UserError(`You don't have enough privileges to change that field`);
const updatedClaim = await claim.updateAttributes(data);
if (args.claimStateFk) {
const canUpdate = await canChangeState(ctx, claim.claimStateFk);
const hasRights = await canChangeState(ctx, args.claimStateFk);
const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant');
if (!canUpdate || !hasRights || changedHasToPickUp && !isSalesAssistant)
throw new UserError(`You don't have enough privileges to change that field`);
}
delete args.ctx;
const updatedClaim = await claim.updateAttributes(args);
// Get sales person from claim client
const salesPerson = claim.client().salesPersonUser();
if (salesPerson && changedHasToPickUp && updatedClaim.hasToPickUp) {

View File

@ -1,8 +1,7 @@
<vn-watcher
vn-id="watcher"
url="Claims/{{$ctrl.$params.id}}/updateClaim"
url="Claims/updateClaim"
data="$ctrl.claim"
insert-mode="true"
form="form">
</vn-watcher>
<vn-crud-model

View File

@ -1,11 +1,9 @@
<mg-ajax path="Entries/{{patch.params.id}}" options="vnPatch"></mg-ajax>
<vn-watcher
vn-id="watcher"
url="Entries"
id-field="id"
data="$ctrl.entry"
params="$ctrl.entry"
save="patch"
form="form">
form="form"
save="patch">
</vn-watcher>
<form name="form" ng-submit="watcher.submit()" class="vn-w-md">
<vn-card class="vn-pa-lg">

View File

@ -1,6 +1,6 @@
const app = require('vn-loopback/server/server');
xdescribe('item getWasteDetail()', () => {
describe('item getWasteDetail()', () => {
it('should check for the waste breakdown for every worker', async() => {
let result = await app.models.Item.getWasteDetail();
@ -14,10 +14,10 @@ xdescribe('item getWasteDetail()', () => {
expect(result.length).toEqual(3);
expect(firstBuyer).toEqual('CharlesXavier');
expect(firstBuyerLines.length).toEqual(4);
expect(secondBuyer).toEqual('DavidCharlesHaller');
expect(secondBuyer).toEqual('HankPym');
expect(secondBuyerLines.length).toEqual(3);
expect(thirdBuyer).toEqual('HankPym');
expect(thirdBuyer).toEqual('DavidCharlesHaller');
expect(thirdBuyerLines.length).toEqual(3);
});
});

View File

@ -31,10 +31,10 @@
model="model">
</vn-multi-check>
</vn-th>
<vn-th>Order</vn-th>
<vn-th shrink>Order</vn-th>
<vn-th number>Ticket</vn-th>
<vn-th expand>Client</vn-th>
<vn-th number>Packages</vn-th>
<vn-th shrink>Packages</vn-th>
<vn-th number></vn-th>
<vn-th>Warehouse</vn-th>
<vn-th>Postcode</vn-th>
@ -50,7 +50,7 @@
ng-model="ticket.checked">
</vn-check>
</vn-td>
<vn-td number>
<vn-td shrink>
<vn-input-number
on-change="$ctrl.setPriority(ticket.id, ticket.priority)"
ng-model="ticket.priority"
@ -65,15 +65,15 @@
{{ticket.id}}
</span>
</vn-td>
<vn-td>
<vn-td expand>
<span
ng-click="clientDescriptor.show($event, ticket.clientFk)"
class="link">
{{ticket.nickname}}
</span>
</vn-td>
<vn-td number>{{ticket.packages}}</vn-td>
<vn-td number>{{ticket.volume}}</vn-td>
<vn-td shrink>{{ticket.packages}}</vn-td>
<vn-td number>{{::ticket.volume | number:1}}</vn-td>
<vn-td expand>{{ticket.warehouse.name}}</vn-td>
<vn-td>{{ticket.address.postalCode}}</vn-td>
<vn-td expand title="{{ticket.address.street}}">{{ticket.address.street}}</vn-td>

View File

@ -386,7 +386,7 @@ class Controller extends Section {
* Updates the sale quantity for existing instance
*/
changeQuantity(sale) {
if (!sale.itemFk || !sale.quantity) return;
if (!sale.itemFk || sale.quantity == null) return;
if (!sale.id)
return this.addSale(sale);