Some minor updates to make search test cases pass.

This commit is contained in:
mike12345567 2021-03-26 14:11:24 +00:00
parent d9808b2fd7
commit 3916b9a29a
4 changed files with 25 additions and 16 deletions

View File

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

View File

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

View File

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

View File

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