Fix viewV2.spec.ts for sqs
This commit is contained in:
parent
b93e6cb986
commit
0ef633b87a
|
@ -1653,7 +1653,7 @@ describe.each([
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("search", () => {
|
describe("search", () => {
|
||||||
it.only("returns empty rows from view when no schema is passed", async () => {
|
it("returns empty rows from view when no schema is passed", async () => {
|
||||||
const rows = await Promise.all(
|
const rows = await Promise.all(
|
||||||
Array.from({ length: 10 }, () => config.api.row.save(table._id!, {}))
|
Array.from({ length: 10 }, () => config.api.row.save(table._id!, {}))
|
||||||
)
|
)
|
||||||
|
@ -2197,28 +2197,6 @@ describe.each([
|
||||||
expect(response.rows).toHaveLength(0)
|
expect(response.rows).toHaveLength(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("queries the row api passing the view fields only", async () => {
|
|
||||||
const searchSpy = jest.spyOn(sdk.rows, "search")
|
|
||||||
|
|
||||||
const view = await config.api.viewV2.create({
|
|
||||||
tableId: table._id!,
|
|
||||||
name: generator.guid(),
|
|
||||||
schema: {
|
|
||||||
id: { visible: true },
|
|
||||||
one: { visible: false },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
await config.api.viewV2.search(view.id, { query: {} })
|
|
||||||
expect(searchSpy).toHaveBeenCalledTimes(1)
|
|
||||||
|
|
||||||
expect(searchSpy).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
fields: ["id"],
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("foreign relationship columns", () => {
|
describe("foreign relationship columns", () => {
|
||||||
let envCleanup: () => void
|
let envCleanup: () => void
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
|
|
|
@ -463,11 +463,13 @@ export async function search(
|
||||||
aggregations,
|
aggregations,
|
||||||
})
|
})
|
||||||
|
|
||||||
// check if we need to pick specific rows out
|
const visibleFields =
|
||||||
if (options.fields) {
|
options.fields ||
|
||||||
const fields = [...options.fields, ...PROTECTED_INTERNAL_COLUMNS]
|
Object.keys(source.schema || {}).filter(
|
||||||
finalRows = finalRows.map((r: any) => pick(r, fields))
|
key => source.schema?.[key].visible !== false
|
||||||
}
|
)
|
||||||
|
const allowedFields = [...visibleFields, ...PROTECTED_INTERNAL_COLUMNS]
|
||||||
|
finalRows = finalRows.map((r: any) => pick(r, allowedFields))
|
||||||
|
|
||||||
const response: SearchResponse<Row> = {
|
const response: SearchResponse<Row> = {
|
||||||
rows: finalRows,
|
rows: finalRows,
|
||||||
|
|
Loading…
Reference in New Issue