Added unit test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-11-05 09:21:20 +01:00
parent 4c88a46b63
commit a30cfd2218
5 changed files with 124 additions and 33996 deletions

5148
front/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -34,18 +34,18 @@ module.exports = Self => {
stmt = new ParameterizedSQL( stmt = new ParameterizedSQL(
`SELECT value FROM ( `SELECT value FROM (
SELECT name AS value FROM ${tag.sourceTable}) v`); SELECT name AS value FROM ${tag.sourceTable}) v`);
const where = filter.where;
if (where && where.value) {
filter.order = `value LIKE '${where.value}' DESC,
value LIKE '${where.value}%' DESC`;
filter.where = {value: {like: `%${where.value}%`}};
}
} else } else
stmt = new ParameterizedSQL(`SELECT value FROM itemTag`); stmt = new ParameterizedSQL(`SELECT value FROM itemTag`);
stmt.merge(conn.makeSuffix(filter)); let where = filter.where;
if (where && where.value) {
stmt.merge(conn.makeWhere({value: {like: `%${where.value}%`}}));
stmt.merge(`
ORDER BY value LIKE '${where.value}' DESC,
value LIKE '${where.value}%' DESC`);
}
stmt.merge(conn.makeLimit(filter));
return conn.executeStmt(stmt); return conn.executeStmt(stmt);
}; };

View File

@ -0,0 +1,37 @@
const app = require('vn-loopback/server/server');
describe('tag filterValue()', () => {
const colorTagId = 1;
it('should return a list of color values', async() => {
const filter = {limit: 5};
const result = await app.models.Tag.filterValue(colorTagId, filter);
expect(result.length).toEqual(5);
});
it('should return the values matching color "Blue"', async() => {
const filter = {where: {value: 'Blue'}, limit: 5};
const result = await app.models.Tag.filterValue(colorTagId, filter);
expect(result.length).toEqual(2);
expect(result[0].value).toEqual('Blue');
expect(result[1].value).toEqual('Blue/Silver');
});
it('should return the values matching color "Blue/Silver"', async() => {
const filter = {where: {value: 'Blue/Silver'}, limit: 5};
const result = await app.models.Tag.filterValue(colorTagId, filter);
expect(result.length).toEqual(1);
expect(result[0].value).toEqual('Blue/Silver');
});
it('should return the values matching color "Silver"', async() => {
const filter = {where: {value: 'Silver'}, limit: 5};
const result = await app.models.Tag.filterValue(colorTagId, filter);
expect(result.length).toEqual(2);
expect(result[0].value).toEqual('Silver');
expect(result[1].value).toEqual('Blue/Silver');
});
});

27174
package-lock.json generated

File diff suppressed because it is too large Load Diff

1743
print/package-lock.json generated

File diff suppressed because it is too large Load Diff