dev #1731

Merged
jgallego merged 105 commits from dev into test 2023-08-31 09:13:29 +00:00
6 changed files with 106 additions and 4 deletions
Showing only changes of commit 777426aa05 - Show all commits

View File

@ -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: [
{

View File

@ -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();

View File

@ -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;
}
});
});

View File

@ -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;
}
});
});

View File

@ -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({});

View File

@ -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;
}
});
});