test: fix postcode filter back test
gitea/salix/pipeline/pr-master There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2024-07-30 10:13:32 +02:00
parent dbe0f4497c
commit 2ac8760061
2 changed files with 20 additions and 44 deletions

View File

@ -12,11 +12,6 @@ module.exports = Self => {
type: 'object',
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
},
{
arg: 'search',
type: 'string',
description: 'Value to filter',
},
],
returns: {
type: ['object'],
@ -27,7 +22,7 @@ module.exports = Self => {
verb: 'GET',
},
});
Self.filter = async(filter = {}, search, options) => {
Self.filter = async(filter = {}, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -1,17 +1,14 @@
const {models} = require('vn-loopback/server/server');
describe('Postcode filter()', () => {
fdescribe('Postcode filter()', () => {
it('should retrieve with no filter', async() => {
const tx = await models.Postcode.beginTransaction({});
const options = {transaction: tx};
try {
const ctx = {
filter: {
},
const results = await models.Postcode.filter({
limit: 1
};
const results = await models.Postcode.filter(ctx, options);
}, options);
expect(results.length).toEqual(1);
await tx.rollback();
@ -26,14 +23,11 @@ describe('Postcode filter()', () => {
const options = {transaction: tx};
try {
const ctx = {
filter: {
where: {
search: 46,
}
},
};
const results = await models.Postcode.filter(ctx, options);
const results = await models.Postcode.filter({
where: {
search: 46,
}
}, options);
expect(results.length).toEqual(4);
await tx.rollback();
@ -48,14 +42,9 @@ describe('Postcode filter()', () => {
const options = {transaction: tx};
try {
const ctx = {
filter: {
where: {
search: 'Alz',
}
},
};
const results = await models.Postcode.filter(ctx, options);
const results = await models.Postcode.filter({where: {
search: 'Alz',
}}, options);
expect(results.length).toEqual(1);
await tx.rollback();
@ -70,14 +59,9 @@ describe('Postcode filter()', () => {
const options = {transaction: tx};
try {
const ctx = {
filter: {
where: {
search: 'one',
}
},
};
const results = await models.Postcode.filter(ctx, options);
const results = await models.Postcode.filter({where: {
search: 'one',
}}, options);
expect(results.length).toEqual(4);
await tx.rollback();
@ -92,14 +76,11 @@ describe('Postcode filter()', () => {
const options = {transaction: tx};
try {
const ctx = {
filter: {
where: {
search: 'Ec',
}
},
};
const results = await models.Postcode.filter(ctx, options);
const results = await models.Postcode.filter({
where: {
search: 'Ec',
}
}, options);
expect(results.length).toEqual(1);
await tx.rollback();