From 777426aa055fbd6d88f4c571a16896cb8f7b018b Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 27 Jul 2023 07:58:55 +0200 Subject: [PATCH] refs #5561 add backTest --- .../back/methods/sale-tracking/delete.js | 2 +- .../ticket/back/methods/sale-tracking/new.js | 4 +- .../sale-tracking/specs/delete.spec.js | 30 ++++++++++++ .../sale-tracking/specs/filter.spec.js | 23 +++++++++ .../specs/listSaleTracking.spec.js | 2 +- .../methods/sale-tracking/specs/new.spec.js | 49 +++++++++++++++++++ 6 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 modules/ticket/back/methods/sale-tracking/specs/delete.spec.js create mode 100644 modules/ticket/back/methods/sale-tracking/specs/filter.spec.js create mode 100644 modules/ticket/back/methods/sale-tracking/specs/new.spec.js diff --git a/modules/ticket/back/methods/sale-tracking/delete.js b/modules/ticket/back/methods/sale-tracking/delete.js index b8754d48c..0b977e5d4 100644 --- a/modules/ticket/back/methods/sale-tracking/delete.js +++ b/modules/ticket/back/methods/sale-tracking/delete.js @@ -1,7 +1,7 @@ module.exports = Self => { Self.remoteMethod('delete', { - description: 'Elimina el registro (si se cumple la condiciĆ³n) y inserta uno nuevo', + description: 'Delete sale trackings and item shelving sales', accessType: 'READ', accepts: [ { diff --git a/modules/ticket/back/methods/sale-tracking/new.js b/modules/ticket/back/methods/sale-tracking/new.js index 2be5bd86e..6a99c299c 100644 --- a/modules/ticket/back/methods/sale-tracking/new.js +++ b/modules/ticket/back/methods/sale-tracking/new.js @@ -1,7 +1,7 @@ module.exports = Self => { Self.remoteMethodCtx('new', { - description: 'Remplaza el registro o lo crea si no existe', + description: `Replaces the record or creates it if it doesn't exist`, accessType: 'READ', accepts: [ { @@ -76,7 +76,7 @@ module.exports = Self => { isChecked: isChecked, originalQuantity: quantity, isScanned: null - }); + }, myOptions); } if (tx) await tx.commit(); diff --git a/modules/ticket/back/methods/sale-tracking/specs/delete.spec.js b/modules/ticket/back/methods/sale-tracking/specs/delete.spec.js new file mode 100644 index 000000000..a8bcf5692 --- /dev/null +++ b/modules/ticket/back/methods/sale-tracking/specs/delete.spec.js @@ -0,0 +1,30 @@ +const models = require('vn-loopback/server/server').models; + +describe('sale-tracking delete()', () => { + it('should delete a row of saleTracking and itemShelvingSale', async() => { + const tx = await models.SaleTracking.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const itemShelvingsBefore = await models.ItemShelvingSale.find(null, options); + const saleTrackingsBefore = await models.SaleTracking.find(null, options); + + const saleFk = 1; + const stateCode = 'PREPARED'; + const result = await models.SaleTracking.delete(saleFk, stateCode, options); + + const itemShelvingsAfter = await models.ItemShelvingSale.find(null, options); + const saleTrackingsAfter = await models.SaleTracking.find(null, options); + + expect(result).toEqual(true); + expect(saleTrackingsAfter.length).toBeLessThan(saleTrackingsBefore.length); + expect(itemShelvingsAfter.length).toBeLessThan(itemShelvingsBefore.length); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/ticket/back/methods/sale-tracking/specs/filter.spec.js b/modules/ticket/back/methods/sale-tracking/specs/filter.spec.js new file mode 100644 index 000000000..8a679f3a5 --- /dev/null +++ b/modules/ticket/back/methods/sale-tracking/specs/filter.spec.js @@ -0,0 +1,23 @@ +const app = require('vn-loopback/server/server'); + +describe('sale-tracking filter()', () => { + it('should return 1 result filtering by ticket id', async() => { + const tx = await app.models.Claim.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const id = 1; + const filter = {order: ['concept ASC', 'quantity DESC']}; + const result = await app.models.SaleTracking.filter(id, filter, options); + + expect(result.length).toEqual(4); + expect(result[0].ticketFk).toEqual(1); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/ticket/back/methods/sale-tracking/specs/listSaleTracking.spec.js b/modules/ticket/back/methods/sale-tracking/specs/listSaleTracking.spec.js index d51c56874..89f274c57 100644 --- a/modules/ticket/back/methods/sale-tracking/specs/listSaleTracking.spec.js +++ b/modules/ticket/back/methods/sale-tracking/specs/listSaleTracking.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -describe('ticket listSaleTracking()', () => { +describe('sale-tracking listSaleTracking()', () => { it('should call the listSaleTracking method and return the response', async() => { const tx = await models.SaleTracking.beginTransaction({}); diff --git a/modules/ticket/back/methods/sale-tracking/specs/new.spec.js b/modules/ticket/back/methods/sale-tracking/specs/new.spec.js new file mode 100644 index 000000000..fcd383582 --- /dev/null +++ b/modules/ticket/back/methods/sale-tracking/specs/new.spec.js @@ -0,0 +1,49 @@ +const models = require('vn-loopback/server/server').models; + +describe('sale-tracking new()', () => { + it('should update a saleTracking', async() => { + const tx = await models.SaleTracking.beginTransaction({}); + + try { + const options = {transaction: tx}; + const ctx = {req: {accessToken: {userId: 55}}}; + + const saleFk = 1; + const isChecked = true; + const quantity = 20; + const stateCode = 'PREPARED'; + const result = await models.SaleTracking.new(ctx, saleFk, isChecked, quantity, stateCode, options); + + expect(result.isChecked).toBe(true); + expect(result.originalQuantity).toBe(20); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should create a saleTracking', async() => { + const tx = await models.SaleTracking.beginTransaction({}); + + try { + const options = {transaction: tx}; + const ctx = {req: {accessToken: {userId: 1}}}; + + const saleFk = 1; + const isChecked = true; + const quantity = 20; + const stateCode = 'PREPARED'; + const result = await models.SaleTracking.new(ctx, saleFk, isChecked, quantity, stateCode, options); + + expect(result.isChecked).toBe(true); + expect(result.originalQuantity).toBe(20); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +});