Some minor updates to make search test cases pass.

This commit is contained in:
mike12345567 2021-03-26 14:11:24 +00:00
parent 41d16442c7
commit 273855ed8c
4 changed files with 25 additions and 16 deletions

View File

@ -30,6 +30,17 @@ module.exports = async (url, opts) => {
},
404
)
} else if (url.includes("_search")) {
return json({
rows: [
{
doc: {
_id: "test",
},
},
],
bookmark: "test",
})
}
return fetch(url, opts)
}

View File

@ -272,7 +272,7 @@ exports.search = async function(ctx) {
}
let searchString
if (ctx.query.raw && ctx.query.raw !== "") {
if (ctx.query && ctx.query.raw && ctx.query.raw !== "") {
searchString = queryBuilder.complete(query["RAW"])
} else {
// make all strings a starts with operation rather than pure equality

View File

@ -34,7 +34,6 @@ class QueryBuilder {
fuzzy: {},
range: {},
equal: {},
meta: {},
...base,
}
this.limit = 50
@ -93,16 +92,18 @@ class QueryBuilder {
if (this.query.string) {
build(this.query.string, (key, value) => `${key}:${value}*`)
}
if (this.query.number) {
build(this.query.number, (key, value) =>
value.length == null
? `${key}:${value}`
: `${key}:[${value[0]} TO ${value[1]}]`
if (this.query.range) {
build(
this.query.range,
(key, value) => `${key}:[${value[0]} TO ${value[1]}]`
)
}
if (this.query.fuzzy) {
build(this.query.fuzzy, (key, value) => `${key}:${value}~`)
}
if (this.query.equal) {
build(this.query.equal, (key, value) => `${key}:${value}`)
}
if (rawQuery) {
output = output.length === 0 ? rawQuery : `&${rawQuery}`
}

View File

@ -2,6 +2,9 @@ const { outputProcessing } = require("../../../utilities/rowProcessor")
const setup = require("./utilities")
const { basicRow } = setup.structures
// mock the fetch for the search system
jest.mock("node-fetch")
describe("/rows", () => {
let request = setup.getRequest()
let config = setup.getConfig()
@ -303,25 +306,19 @@ describe("/rows", () => {
describe("search", () => {
it("should run a search on the table", async () => {
const row = await config.createRow()
// add another row that shouldn't be found
await config.createRow({
...basicRow(),
name: "Other Contact",
})
const res = await request
.post(`/api/${table._id}/rows/search`)
.send({
query: {
name: "Test",
},
pagination: { pageSize: 25, page: 0 }
pagination: { pageSize: 25 }
})
.set(config.defaultHeaders())
.expect('Content-Type', /json/)
.expect(200)
expect(res.body.length).toEqual(1)
expect(res.body[0]._id).toEqual(row._id)
expect(res.body.rows.length).toEqual(1)
expect(res.body.bookmark).toBeDefined()
})
})