Added unit test
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
4c88a46b63
commit
a30cfd2218
File diff suppressed because it is too large
Load Diff
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
|
@ -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');
|
||||||
|
});
|
||||||
|
});
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue