refs #6321 test: itemLack
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2024-04-01 13:59:35 +02:00
parent d62c55dc9f
commit d225821a41
2 changed files with 137 additions and 13 deletions

View File

@ -72,7 +72,8 @@ module.exports = Self => {
Object.assign(myOptions, options);
const conn = Self.dataSource.connector;
let where = {};
where = buildFilter(ctx.args, (param, value) => {
filter = Object.assign(ctx.args ?? {}, filter);
where = buildFilter(filter, (param, value) => {
switch (param) {
case 'id':
return {'i.id': value};
@ -85,9 +86,9 @@ module.exports = Self => {
case 'size':
return {'i.size': value};
case 'origen':
return {'w.name': value};
return {'w.id': value};
case 'lack':
return {'lack': value};
return {'sub.amount': value};
}
}) ?? {};

View File

@ -1,30 +1,153 @@
const models = require('vn-loopback/server/server').models;
describe('Item Lack', () => {
fdescribe('Item Lack', () => {
beforeAll(async() => {
ctx = {
req: {
accessToken: {},
headers: {origin: 'http://localhost'},
}
};
});
it('should return data with NO filters', async() => {
const tx = await models.Ticket.beginTransaction({});
const options = {transaction: tx};
const filter = {};
try {
const options = {transaction: tx};
const result = await models.Ticket.itemLack(ctx, filter, options);
const result = await models.Ticket.itemLack(3, options);
expect(result).toBeFalsy();
expect(result.length).toEqual(4);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should return data with filters', async() => {
it('should return data with filter.id', async() => {
const tx = await models.Ticket.beginTransaction({});
const options = {transaction: tx};
const filter = {
id: 1
};
try {
const options = {transaction: tx};
const result = await models.Ticket.itemLack(ctx, filter, options);
const result = await models.Ticket.isEmpty(8, options);
expect(result).toBeFalsy();
expect(result.length).toEqual(1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should return data with filter.longname', async() => {
const tx = await models.Ticket.beginTransaction({});
const options = {transaction: tx};
const filter = {
longname: 'Ranged weapon longbow 200cm'
};
try {
const result = await models.Ticket.itemLack(ctx, filter, options);
expect(result.length).toEqual(1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
xit('should return data with filter.name', async() => {
const tx = await models.Ticket.beginTransaction({});
const options = {transaction: tx};
const filter = {
name: 1
};
try {
const result = await models.Ticket.itemLack(ctx, filter, options);
expect(result.length).toEqual(1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should return data with filter.color', async() => {
const tx = await models.Ticket.beginTransaction({});
const options = {transaction: tx};
const filter = {
color: 'BRW'
};
try {
const result = await models.Ticket.itemLack(ctx, filter, options);
expect(result.length).toEqual(1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should return data with filter.origen', async() => {
const tx = await models.Ticket.beginTransaction({});
const options = {transaction: tx};
const filter = {
origen: 2
};
try {
const result = await models.Ticket.itemLack(ctx, filter, options);
expect(result.length).toEqual(3);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should return data with filter.size', async() => {
const tx = await models.Ticket.beginTransaction({});
const options = {transaction: tx};
const filter = {
size: '200'
};
try {
const result = await models.Ticket.itemLack(ctx, filter, options);
expect(result.length).toEqual(1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
fit('should return data with filter.lack', async() => {
const tx = await models.Ticket.beginTransaction({});
const options = {transaction: tx};
const filter = {
lack: '-100'
};
try {
const result = await models.Ticket.itemLack(ctx, filter, options);
expect(result.length).toEqual(1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});