Add unit test and fix

This commit is contained in:
Mel O'Hagan 2022-10-04 16:28:29 +01:00
parent 91d00ecdb4
commit 3490996c5a
2 changed files with 24 additions and 2 deletions

View File

@ -145,7 +145,7 @@ class QueryBuilder {
* @param options The preprocess options
* @returns {string|*}
*/
preprocess(value, { escape, lowercase, wrap } = {}) {
preprocess(value, { escape, lowercase, wrap, type } = {}) {
const hasVersion = !!this.version
// Determine if type needs wrapped
const originalType = typeof value
@ -159,7 +159,7 @@ class QueryBuilder {
}
// Wrap in quotes
if (originalType === "string" && !isNaN(value) && !escape) {
if (originalType === "string" && !isNaN(value) && !type) {
value = `"${value}"`
} else if (hasVersion && wrap) {
value = originalType === "number" ? value : `"${value}"`
@ -256,6 +256,7 @@ class QueryBuilder {
value = builder.preprocess(value, {
escape: true,
lowercase: true,
type: "string",
})
return `${key}:${value}*`
})
@ -284,6 +285,7 @@ class QueryBuilder {
value = builder.preprocess(value, {
escape: true,
lowercase: true,
type: "fuzzy",
})
return `${key}:${value}~`
})

View File

@ -173,4 +173,24 @@ describe("internal search", () => {
}, PARAMS)
checkLucene(response, `*:* AND NOT column:(a AND b AND c)`, PARAMS)
})
it("test equal without version query", async () => {
PARAMS.version = null
const response = await search.paginatedSearch({
equal: {
"column": "1",
}
}, PARAMS)
const query = response.rows[0].query
const json = JSON.parse(query)
if (PARAMS.sort) {
expect(json.sort).toBe(`${PARAMS.sort}<${PARAMS.sortType}>`)
}
if (PARAMS.bookmark) {
expect(json.bookmark).toBe(PARAMS.bookmark)
}
expect(json.include_docs).toBe(true)
expect(json.q).toBe(`(*:* AND column:"1") AND tableId:${PARAMS.tableId}`)
})
})