diff --git a/back/methods/dms/uploadFile.js b/back/methods/dms/uploadFile.js index c3065c3cc..d6540cbc5 100644 --- a/back/methods/dms/uploadFile.js +++ b/back/methods/dms/uploadFile.js @@ -110,11 +110,10 @@ module.exports = Self => { async function createDms(ctx, file, myOptions) { const models = Self.app.models; const myUserId = ctx.req.accessToken.userId; - const myWorker = await models.Worker.findOne({where: {userFk: myUserId}}, myOptions); const args = ctx.args; const newDms = await Self.create({ - workerFk: myWorker.id, + workerFk: myUserId, dmsTypeFk: args.dmsTypeId, companyFk: args.companyId, warehouseFk: args.warehouseId, diff --git a/e2e/paths/02-client/14_balance.spec.js b/e2e/paths/02-client/14_balance.spec.js index 4917937fa..22d3f15ac 100644 --- a/e2e/paths/02-client/14_balance.spec.js +++ b/e2e/paths/02-client/14_balance.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors'; import getBrowser from '../../helpers/puppeteer'; -describe('Client balance path', () => { +fdescribe('Client balance path', () => { let browser; let page; beforeAll(async() => { @@ -86,7 +86,7 @@ describe('Client balance path', () => { await page.waitToClick(selectors.clientBalance.newPaymentButton); await page.write(selectors.clientBalance.newPaymentAmount, amountPaid); - await page.write(selectors.clientBalance.newDescription, 'Payment'); + await page.write(selectors.clientBalance.deliveredAmount, cashHanded); const refund = await page.waitToGetProperty(selectors.clientBalance.refundAmount, 'value'); await page.waitToClick(selectors.clientBalance.saveButton); diff --git a/modules/client/back/methods/client/specs/createReceipt.spec.js b/modules/client/back/methods/client/specs/createReceipt.spec.js index 3bd560cdd..8d35064a2 100644 --- a/modules/client/back/methods/client/specs/createReceipt.spec.js +++ b/modules/client/back/methods/client/specs/createReceipt.spec.js @@ -1,4 +1,5 @@ const app = require('vn-loopback/server/server'); +const LoopBackContext = require('loopback-context'); describe('Client createReceipt', () => { const clientFk = 108; @@ -6,18 +7,34 @@ describe('Client createReceipt', () => { const companyFk = 442; const amountPaid = 12.50; const description = 'Receipt description'; + const activeCtx = { + accessToken: {userId: 5}, + http: { + req: { + headers: {origin: 'http://localhost'} + } + } + }; + const ctx = {req: activeCtx}; + activeCtx.http.req.__ = value => { + return value; + }; + + beforeEach(() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + }); it('should create a new receipt', async() => { const bankFk = 1; - let ctx = { - args: { - clientFk: clientFk, - payed: payed, - companyFk: companyFk, - bankFk: bankFk, - amountPaid: amountPaid, - description: description - } + ctx.args = { + clientFk: clientFk, + payed: payed, + companyFk: companyFk, + bankFk: bankFk, + amountPaid: amountPaid, + description: description }; const receipt = await app.models.Client.createReceipt(ctx); @@ -40,15 +57,14 @@ describe('Client createReceipt', () => { it('should throw Compensation account is empty', async() => { const bankFk = 3; - let ctx = { - args: { - clientFk: clientFk, - payed: payed, - companyFk: companyFk, - bankFk: bankFk, - amountPaid: amountPaid, - description: description - } + + ctx.args = { + clientFk: clientFk, + payed: payed, + companyFk: companyFk, + bankFk: bankFk, + amountPaid: amountPaid, + description: description }; try { @@ -64,16 +80,14 @@ describe('Client createReceipt', () => { it('should throw Invalid account if compensationAccount does not belongs to a client nor a supplier', async() => { let error; const bankFk = 3; - const ctx = { - args: { - clientFk: clientFk, - payed: payed, - companyFk: companyFk, - bankFk: bankFk, - amountPaid: amountPaid, - description: description, - compensationAccount: 'non existing account' - } + ctx.args = { + clientFk: clientFk, + payed: payed, + companyFk: companyFk, + bankFk: bankFk, + amountPaid: amountPaid, + description: description, + compensationAccount: 'non existing account' }; try { @@ -88,16 +102,15 @@ describe('Client createReceipt', () => { it('should create a new receipt with a compensation for a client', async() => { const bankFk = 3; - const ctx = { - args: { - clientFk: clientFk, - payed: payed, - companyFk: companyFk, - bankFk: bankFk, - amountPaid: amountPaid, - description: description, - compensationAccount: '4300000001' - } + + ctx.args = { + clientFk: clientFk, + payed: payed, + companyFk: companyFk, + bankFk: bankFk, + amountPaid: amountPaid, + description: description, + compensationAccount: '4300000001' }; const receipt = await app.models.Client.createReceipt(ctx); const receiptCompensated = await app.models.Receipt.findOne({ @@ -127,16 +140,16 @@ describe('Client createReceipt', () => { }); it('should create a new receipt with a compensation for a supplier', async() => { - const ctx = { - args: { - clientFk: clientFk, - payed: payed, - companyFk: companyFk, - bankFk: 3, - amountPaid: amountPaid, - description: description, - compensationAccount: '4100000001' - } + const bankFk = 3; + + ctx.args = { + clientFk: clientFk, + payed: payed, + companyFk: companyFk, + bankFk: bankFk, + amountPaid: amountPaid, + description: description, + compensationAccount: '4100000001' }; const receipt = await app.models.Client.createReceipt(ctx); diff --git a/modules/client/back/models/receipt.js b/modules/client/back/models/receipt.js index 88b7bfb5b..03a05490e 100644 --- a/modules/client/back/models/receipt.js +++ b/modules/client/back/models/receipt.js @@ -1,3 +1,5 @@ +const LoopBackContext = require('loopback-context'); + module.exports = function(Self) { require('../methods/receipt/filter')(Self); @@ -23,13 +25,12 @@ module.exports = function(Self) { Self.observe('before save', async function(ctx) { if (ctx.isNewInstance) { - let token = ctx.options.accessToken; - let userId = token && token.userId; - - ctx.instance.workerFk = userId; - + const loopBackContext = LoopBackContext.getCurrentContext(); + console.log(loopBackContext); + ctx.instance.workerFk = loopBackContext.active.accessToken.userId; + console.log(ctx.instance.workerFk); await Self.app.models.Till.create({ - workerFk: userId, + workerFk: ctx.instance.workerFk, bankFk: ctx.instance.bankFk, in: ctx.instance.amountPaid, concept: ctx.instance.description,