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) => {
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
return
}
@ -824,6 +826,8 @@ describe.each([
}).toContainExactly([{ name: "foo" }, { name: "bar" }])
})
// onEmptyFilter cannot be sent to view searches
!isView &&
it("should return nothing if onEmptyFilter is RETURN_NONE", async () => {
await expectQuery({
onEmptyFilter: EmptyFilterOption.RETURN_NONE,
@ -924,6 +928,8 @@ describe.each([
}).toContainExactly([{ name: "foo" }, { name: "bar" }])
})
// onEmptyFilter cannot be sent to view searches
!isView &&
it("empty arrays returns all when onEmptyFilter is set to return 'none'", async () => {
await expectQuery({
onEmptyFilter: EmptyFilterOption.RETURN_NONE,
@ -2743,6 +2749,7 @@ describe.each([
})
isSqs &&
!isView &&
describe("duplicate columns", () => {
beforeAll(async () => {
tableOrViewId = await createTableOrView({
@ -2860,15 +2867,13 @@ describe.each([
isSql &&
describe("primaryDisplay", () => {
beforeAll(async () => {
let toRelateTableId = await createTableOrView({
let toRelateTableId = await createTable({
name: {
name: "name",
type: FieldType.STRING,
},
})
const table = await config.api.table.save(
tableForDatasource(datasource, {
schema: {
tableOrViewId = await createTableOrView({
name: {
name: "name",
type: FieldType.STRING,
@ -2880,31 +2885,27 @@ describe.each([
tableId: toRelateTableId,
fieldName: "link",
},
},
})
)
tableOrViewId = table._id!
const toRelateTable = await config.api.table.get(toRelateTableId)
await config.api.table.save({
...toRelateTable,
primaryDisplay: "link",
})
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, {
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 () => {
// 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
await expectQuery({}).toContain([
{ name: "test", link: [{ primaryDisplay: "test" }] },
{ name: "test", link: [{ primaryDisplay: "related" }] },
])
})
})
@ -3018,6 +3019,8 @@ describe.each([
)
})
// onEmptyFilter cannot be sent to view searches
!isView &&
it("returns no rows when onEmptyFilter set to none", async () => {
await expectSearch({
query: {
@ -3168,6 +3171,8 @@ describe.each([
}).toContainExactly([{ age: 1, name: "Jane" }])
})
// onEmptyFilter cannot be sent to view searches
!isView &&
it("returns no rows when onEmptyFilter set to none", async () => {
await expectSearch({
query: {

View File

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