Fix tests

This commit is contained in:
Adria Navarro 2024-10-02 16:50:50 +02:00
parent 0484b798fc
commit 521a14650d
2 changed files with 65 additions and 58 deletions

View File

@ -178,7 +178,9 @@ describe.each([
}, },
], ],
])("from %s", (tableOrView, createTableOrView) => { ])("from %s", (tableOrView, createTableOrView) => {
if (tableOrView === "view" && isLucene) { const isView = tableOrView === "view"
if (isView && isLucene) {
// Some tests don't have the expected result in views via lucene, and given that it is getting deprecated, we exclude them from the tests // Some tests don't have the expected result in views via lucene, and given that it is getting deprecated, we exclude them from the tests
return return
} }
@ -824,11 +826,13 @@ describe.each([
}).toContainExactly([{ name: "foo" }, { name: "bar" }]) }).toContainExactly([{ name: "foo" }, { name: "bar" }])
}) })
it("should return nothing if onEmptyFilter is RETURN_NONE", async () => { // onEmptyFilter cannot be sent to view searches
await expectQuery({ !isView &&
onEmptyFilter: EmptyFilterOption.RETURN_NONE, it("should return nothing if onEmptyFilter is RETURN_NONE", async () => {
}).toFindNothing() await expectQuery({
}) onEmptyFilter: EmptyFilterOption.RETURN_NONE,
}).toFindNothing()
})
it("should respect limit", async () => { it("should respect limit", async () => {
await expectSearch({ await expectSearch({
@ -924,12 +928,14 @@ describe.each([
}).toContainExactly([{ name: "foo" }, { name: "bar" }]) }).toContainExactly([{ name: "foo" }, { name: "bar" }])
}) })
it("empty arrays returns all when onEmptyFilter is set to return 'none'", async () => { // onEmptyFilter cannot be sent to view searches
await expectQuery({ !isView &&
onEmptyFilter: EmptyFilterOption.RETURN_NONE, it("empty arrays returns all when onEmptyFilter is set to return 'none'", async () => {
oneOf: { name: [] }, await expectQuery({
}).toContainExactly([]) onEmptyFilter: EmptyFilterOption.RETURN_NONE,
}) oneOf: { name: [] },
}).toContainExactly([])
})
}) })
describe("fuzzy", () => { describe("fuzzy", () => {
@ -2743,6 +2749,7 @@ describe.each([
}) })
isSqs && isSqs &&
!isView &&
describe("duplicate columns", () => { describe("duplicate columns", () => {
beforeAll(async () => { beforeAll(async () => {
tableOrViewId = await createTableOrView({ tableOrViewId = await createTableOrView({
@ -2860,51 +2867,45 @@ describe.each([
isSql && isSql &&
describe("primaryDisplay", () => { describe("primaryDisplay", () => {
beforeAll(async () => { beforeAll(async () => {
let toRelateTableId = await createTableOrView({ let toRelateTableId = await createTable({
name: { name: {
name: "name", name: "name",
type: FieldType.STRING, type: FieldType.STRING,
}, },
}) })
const table = await config.api.table.save( tableOrViewId = await createTableOrView({
tableForDatasource(datasource, { name: {
schema: { name: "name",
name: { type: FieldType.STRING,
name: "name", },
type: FieldType.STRING, link: {
}, name: "link",
link: { type: FieldType.LINK,
name: "link", relationshipType: RelationshipType.MANY_TO_ONE,
type: FieldType.LINK, tableId: toRelateTableId,
relationshipType: RelationshipType.MANY_TO_ONE, fieldName: "link",
tableId: toRelateTableId, },
fieldName: "link", })
},
},
})
)
tableOrViewId = table._id!
const toRelateTable = await config.api.table.get(toRelateTableId) const toRelateTable = await config.api.table.get(toRelateTableId)
await config.api.table.save({ await config.api.table.save({
...toRelateTable, ...toRelateTable,
primaryDisplay: "link", primaryDisplay: "link",
}) })
const relatedRows = await Promise.all([ const relatedRows = await Promise.all([
config.api.row.save(toRelateTable._id!, { name: "test" }), config.api.row.save(toRelateTable._id!, { name: "related" }),
])
await Promise.all([
config.api.row.save(tableOrViewId, {
name: "test",
link: relatedRows.map(row => row._id),
}),
]) ])
await config.api.row.save(tableOrViewId, {
name: "test",
link: relatedRows.map(row => row._id),
})
}) })
it("should be able to query, primary display on related table shouldn't be used", async () => { it("should be able to query, primary display on related table shouldn't be used", async () => {
// this test makes sure that if a relationship has been specified as the primary display on a table // this test makes sure that if a relationship has been specified as the primary display on a table
// it is ignored and another column is used instead // it is ignored and another column is used instead
await expectQuery({}).toContain([ await expectQuery({}).toContain([
{ name: "test", link: [{ primaryDisplay: "test" }] }, { name: "test", link: [{ primaryDisplay: "related" }] },
]) ])
}) })
}) })
@ -3018,16 +3019,18 @@ describe.each([
) )
}) })
it("returns no rows when onEmptyFilter set to none", async () => { // onEmptyFilter cannot be sent to view searches
await expectSearch({ !isView &&
query: { it("returns no rows when onEmptyFilter set to none", async () => {
onEmptyFilter: EmptyFilterOption.RETURN_NONE, await expectSearch({
$and: { query: {
conditions: [{ equal: { name: "" } }], onEmptyFilter: EmptyFilterOption.RETURN_NONE,
$and: {
conditions: [{ equal: { name: "" } }],
},
}, },
}, }).toFindNothing()
}).toFindNothing() })
})
it("returns all rows when onEmptyFilter set to all", async () => { it("returns all rows when onEmptyFilter set to all", async () => {
await expectSearch({ await expectSearch({
@ -3168,16 +3171,18 @@ describe.each([
}).toContainExactly([{ age: 1, name: "Jane" }]) }).toContainExactly([{ age: 1, name: "Jane" }])
}) })
it("returns no rows when onEmptyFilter set to none", async () => { // onEmptyFilter cannot be sent to view searches
await expectSearch({ !isView &&
query: { it("returns no rows when onEmptyFilter set to none", async () => {
onEmptyFilter: EmptyFilterOption.RETURN_NONE, await expectSearch({
$or: { query: {
conditions: [{ equal: { name: "" } }], onEmptyFilter: EmptyFilterOption.RETURN_NONE,
$or: {
conditions: [{ equal: { name: "" } }],
},
}, },
}, }).toFindNothing()
}).toFindNothing() })
})
it("returns all rows when onEmptyFilter set to all", async () => { it("returns all rows when onEmptyFilter set to all", async () => {
await expectSearch({ await expectSearch({

View File

@ -113,11 +113,13 @@ export async function search(
options.query = query options.query = query
} else { } else {
options.query = { options.query = {
onEmptyFilter: viewQuery.onEmptyFilter,
$and: { $and: {
conditions: [viewQuery, options.query], conditions: [viewQuery, options.query],
}, },
} }
if (viewQuery.onEmptyFilter) {
options.query.onEmptyFilter = viewQuery.onEmptyFilter
}
} }
} }