fix: backTest
gitea/salix/pipeline/head This commit is unstable Details

This commit is contained in:
Vicent Llopis 2022-07-29 12:52:53 +02:00
parent 605da52286
commit 840e792d13
3 changed files with 54 additions and 37 deletions

View File

@ -9,7 +9,8 @@ describe('Buy editLatestsBuys()', () => {
const ctx = { const ctx = {
args: { args: {
search: 'Ranged weapon longbow 2m' search: 'Ranged weapon longbow 2m'
} },
req: {accessToken: {userId: 1}}
}; };
const [original] = await models.Buy.latestBuysFilter(ctx, null, options); const [original] = await models.Buy.latestBuysFilter(ctx, null, options);
@ -40,7 +41,8 @@ describe('Buy editLatestsBuys()', () => {
const ctx = { const ctx = {
args: { args: {
filter: filter filter: filter
} },
req: {accessToken: {userId: 1}}
}; };
const field = 'size'; const field = 'size';

View File

@ -9,13 +9,14 @@ describe('Entry latests buys filter()', () => {
const ctx = { const ctx = {
args: { args: {
search: 'Ranged weapon longbow 2m' search: 'Ranged weapon longbow 2m'
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);
const firstBuy = results[0]; const firstBuy = results[0];
expect(results.length).toEqual(3); expect(results.length).toEqual(1);
expect(firstBuy.size).toEqual(70); expect(firstBuy.size).toEqual(70);
await tx.rollback(); await tx.rollback();
@ -33,12 +34,13 @@ describe('Entry latests buys filter()', () => {
const ctx = { const ctx = {
args: { args: {
id: 1 id: 1
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);
expect(results.length).toEqual(3); expect(results.length).toEqual(1);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -57,12 +59,13 @@ describe('Entry latests buys filter()', () => {
tags: [ tags: [
{tagFk: 27, value: '2m'} {tagFk: 27, value: '2m'}
] ]
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);
expect(results.length).toBe(4); expect(results.length).toBe(2);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -79,12 +82,13 @@ describe('Entry latests buys filter()', () => {
const ctx = { const ctx = {
args: { args: {
categoryFk: 1 categoryFk: 1
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);
expect(results.length).toBe(7); expect(results.length).toBe(4);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -101,12 +105,13 @@ describe('Entry latests buys filter()', () => {
const ctx = { const ctx = {
args: { args: {
typeFk: 2 typeFk: 2
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);
expect(results.length).toBe(7); expect(results.length).toBe(4);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -123,12 +128,13 @@ describe('Entry latests buys filter()', () => {
const ctx = { const ctx = {
args: { args: {
active: true active: true
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);
expect(results.length).toBe(12); expect(results.length).toBe(6);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -145,7 +151,8 @@ describe('Entry latests buys filter()', () => {
const ctx = { const ctx = {
args: { args: {
active: false active: false
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);
@ -167,12 +174,13 @@ describe('Entry latests buys filter()', () => {
const ctx = { const ctx = {
args: { args: {
visible: true visible: true
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);
expect(results.length).toBe(11); expect(results.length).toBe(5);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -189,7 +197,8 @@ describe('Entry latests buys filter()', () => {
const ctx = { const ctx = {
args: { args: {
visible: false visible: false
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);
@ -211,7 +220,8 @@ describe('Entry latests buys filter()', () => {
const ctx = { const ctx = {
args: { args: {
floramondo: true floramondo: true
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);
@ -233,12 +243,13 @@ describe('Entry latests buys filter()', () => {
const ctx = { const ctx = {
args: { args: {
floramondo: false floramondo: false
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);
expect(results.length).toBe(11); expect(results.length).toBe(5);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -255,12 +266,13 @@ describe('Entry latests buys filter()', () => {
const ctx = { const ctx = {
args: { args: {
salesPersonFk: 35 salesPersonFk: 35
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);
expect(results.length).toBe(12); expect(results.length).toBe(6);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -277,12 +289,13 @@ describe('Entry latests buys filter()', () => {
const ctx = { const ctx = {
args: { args: {
description: 'Increases block' description: 'Increases block'
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);
expect(results.length).toBe(4); expect(results.length).toBe(1);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -299,7 +312,8 @@ describe('Entry latests buys filter()', () => {
const ctx = { const ctx = {
args: { args: {
supplierFk: 1 supplierFk: 1
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);
@ -328,7 +342,8 @@ describe('Entry latests buys filter()', () => {
args: { args: {
from: from, from: from,
to: to to: to
} },
req: {accessToken: {userId: 1}}
}; };
const results = await models.Buy.latestBuysFilter(ctx, options); const results = await models.Buy.latestBuysFilter(ctx, options);

View File

@ -1,16 +1,16 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
describe('item filter()', () => { describe('item filter()', () => {
it('should return 3 result filtering by id', async() => { it('should return 1 result filtering by id', async() => {
const tx = await models.Item.beginTransaction({}); const tx = await models.Item.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
try { try {
const filter = {}; const filter = {};
const ctx = {args: {filter: filter, search: 1}}; const ctx = {args: {filter: filter, search: 1}, req: {accessToken: {userId: 1}}};
const result = await models.Item.filter(ctx, filter, options); const result = await models.Item.filter(ctx, filter, options);
expect(result.length).toEqual(3); expect(result.length).toEqual(1);
expect(result[0].id).toEqual(1); expect(result[0].id).toEqual(1);
await tx.rollback(); await tx.rollback();
@ -20,16 +20,16 @@ describe('item filter()', () => {
} }
}); });
it('should return 2 result filtering by barcode', async() => { it('should return 1 result filtering by barcode', async() => {
const tx = await models.Item.beginTransaction({}); const tx = await models.Item.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
try { try {
const filter = {}; const filter = {};
const ctx = {args: {filter: filter, search: 4444444444}}; const ctx = {args: {filter: filter, search: 4444444444}, req: {accessToken: {userId: 1}}};
const result = await models.Item.filter(ctx, filter, options); const result = await models.Item.filter(ctx, filter, options);
expect(result.length).toEqual(2); expect(result.length).toEqual(1);
expect(result[0].id).toEqual(2); expect(result[0].id).toEqual(2);
await tx.rollback(); await tx.rollback();
@ -49,7 +49,7 @@ describe('item filter()', () => {
limit: 8 limit: 8
}; };
const tags = [{value: 'medical box', tagFk: 58}]; const tags = [{value: 'medical box', tagFk: 58}];
const ctx = {args: {filter: filter, typeFk: 5, tags: tags}}; const ctx = {args: {filter: filter, typeFk: 5, tags: tags}, req: {accessToken: {userId: 1}}};
const result = await models.Item.filter(ctx, filter, options); const result = await models.Item.filter(ctx, filter, options);
expect(result.length).toEqual(2); expect(result.length).toEqual(2);
@ -67,7 +67,7 @@ describe('item filter()', () => {
try { try {
const filter = {}; const filter = {};
const ctx = {args: {filter: filter, isFloramondo: true}}; const ctx = {args: {filter: filter, isFloramondo: true}, req: {accessToken: {userId: 1}}};
const result = await models.Item.filter(ctx, filter, options); const result = await models.Item.filter(ctx, filter, options);
expect(result.length).toEqual(3); expect(result.length).toEqual(3);
@ -86,7 +86,7 @@ describe('item filter()', () => {
try { try {
const filter = {}; const filter = {};
const ctx = {args: {filter: filter, buyerFk: 16}}; const ctx = {args: {filter: filter, buyerFk: 16}, req: {accessToken: {userId: 1}}};
const result = await models.Item.filter(ctx, filter, options); const result = await models.Item.filter(ctx, filter, options);
expect(result.length).toEqual(2); expect(result.length).toEqual(2);
@ -106,7 +106,7 @@ describe('item filter()', () => {
try { try {
const filter = {}; const filter = {};
const ctx = {args: {filter: filter, supplierFk: 1}}; const ctx = {args: {filter: filter, supplierFk: 1}, req: {accessToken: {userId: 1}}};
const result = await models.Item.filter(ctx, filter, options); const result = await models.Item.filter(ctx, filter, options);
expect(result.length).toEqual(2); expect(result.length).toEqual(2);