Run view tests

This commit is contained in:
Adria Navarro 2024-10-02 12:26:03 +02:00
parent b88e63d490
commit e08c3b8574
2 changed files with 2772 additions and 2734 deletions

View File

@ -28,6 +28,7 @@ import {
RowSearchParams, RowSearchParams,
SearchFilters, SearchFilters,
SearchResponse, SearchResponse,
SearchRowRequest,
SortOrder, SortOrder,
SortType, SortType,
Table, Table,
@ -64,7 +65,7 @@ describe.each([
let envCleanup: (() => void) | undefined let envCleanup: (() => void) | undefined
let datasource: Datasource | undefined let datasource: Datasource | undefined
let client: Knex | undefined let client: Knex | undefined
let sourceId: string let tableOrViewId: string
let rows: Row[] let rows: Row[]
async function basicRelationshipTables(type: RelationshipType) { async function basicRelationshipTables(type: RelationshipType) {
@ -145,24 +146,48 @@ describe.each([
async function createRows(arr: Record<string, any>[]) { async function createRows(arr: Record<string, any>[]) {
// Shuffling to avoid false positives given a fixed order // Shuffling to avoid false positives given a fixed order
await config.api.row.bulkImport(sourceId, { for (const row of _.shuffle(arr)) {
rows: _.shuffle(arr), await config.api.row.save(tableOrViewId, row)
}) }
rows = await config.api.row.fetch(sourceId) rows = await config.api.row.fetch(tableOrViewId)
} }
describe.each([
["table", createTable],
// [
// "view",
// async (schema: TableSchema, name?: string) => {
// const tableId = await createTable(schema, name)
// const view = await config.api.viewV2.create({
// tableId: tableId,
// name: generator.guid(),
// schema: Object.keys(schema).reduce<Record<string, ViewFieldMetadata>>(
// (viewSchema, fieldName) => {
// const field = schema[fieldName]
// viewSchema[fieldName] = {
// visible: field.visible ?? true,
// readonly: false,
// }
// return viewSchema
// },
// {}
// ),
// })
// return view.id
// },
// ],
])("from %s", (__, createSource) => {
class SearchAssertion { class SearchAssertion {
constructor(private readonly query: RowSearchParams) {} constructor(private readonly query: SearchRowRequest) {}
private async performSearch(): Promise<SearchResponse<Row>> { private async performSearch(): Promise<SearchResponse<Row>> {
if (isInMemory) { if (isInMemory) {
return dataFilters.search(_.cloneDeep(rows), this.query) return dataFilters.search(_.cloneDeep(rows), {
...this.query,
tableId: tableOrViewId,
})
} else { } else {
const sourceId = this.query.viewId || this.query.tableId return config.api.row.search(tableOrViewId, this.query)
if (!sourceId) {
throw new Error("No source ID provided")
}
return config.api.row.search(sourceId, this.query)
} }
} }
@ -332,8 +357,8 @@ describe.each([
} }
} }
function expectSearch(query: Omit<RowSearchParams, "tableId">) { function expectSearch(query: SearchRowRequest) {
return new SearchAssertion({ ...query, tableId: sourceId }) return new SearchAssertion(query)
} }
function expectQuery(query: SearchFilters) { function expectQuery(query: SearchFilters) {
@ -342,7 +367,7 @@ describe.each([
describe("boolean", () => { describe("boolean", () => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
isTrue: { name: "isTrue", type: FieldType.BOOLEAN }, isTrue: { name: "isTrue", type: FieldType.BOOLEAN },
}) })
await createRows([{ isTrue: true }, { isTrue: false }]) await createRows([{ isTrue: true }, { isTrue: false }])
@ -430,38 +455,35 @@ describe.each([
{ name: "serverDate", appointment: serverTime.toISOString() }, { name: "serverDate", appointment: serverTime.toISOString() },
{ {
name: "single user, session user", name: "single user, session user",
single_user: JSON.stringify(currentUser), single_user: currentUser,
}, },
{ {
name: "single user", name: "single user",
single_user: JSON.stringify(globalUsers[0]), single_user: globalUsers[0],
}, },
{ {
name: "deprecated single user, session user", name: "deprecated single user, session user",
deprecated_single_user: JSON.stringify([currentUser]), deprecated_single_user: [currentUser],
}, },
{ {
name: "deprecated single user", name: "deprecated single user",
deprecated_single_user: JSON.stringify([globalUsers[0]]), deprecated_single_user: [globalUsers[0]],
}, },
{ {
name: "multi user", name: "multi user",
multi_user: JSON.stringify(globalUsers), multi_user: globalUsers,
}, },
{ {
name: "multi user with session user", name: "multi user with session user",
multi_user: JSON.stringify([...globalUsers, currentUser]), multi_user: [...globalUsers, currentUser],
}, },
{ {
name: "deprecated multi user", name: "deprecated multi user",
deprecated_multi_user: JSON.stringify(globalUsers), deprecated_multi_user: globalUsers,
}, },
{ {
name: "deprecated multi user with session user", name: "deprecated multi user with session user",
deprecated_multi_user: JSON.stringify([ deprecated_multi_user: [...globalUsers, currentUser],
...globalUsers,
currentUser,
]),
}, },
] ]
} }
@ -483,7 +505,7 @@ describe.each([
}) })
) )
sourceId = await createTable({ tableOrViewId = await createSource({
name: { name: "name", type: FieldType.STRING }, name: { name: "name", type: FieldType.STRING },
appointment: { name: "appointment", type: FieldType.DATETIME }, appointment: { name: "appointment", type: FieldType.DATETIME },
single_user: { single_user: {
@ -633,9 +655,11 @@ describe.each([
}) })
it("should match the session user id in a multi user field", async () => { it("should match the session user id in a multi user field", async () => {
const allUsers = [...globalUsers, config.getUser()].map((user: any) => { const allUsers = [...globalUsers, config.getUser()].map(
(user: any) => {
return { _id: user._id } return { _id: user._id }
}) }
)
await expectQuery({ await expectQuery({
contains: { multi_user: ["{{ [user]._id }}"] }, contains: { multi_user: ["{{ [user]._id }}"] },
@ -648,9 +672,11 @@ describe.each([
}) })
it("should match the session user id in a deprecated multi user field", async () => { it("should match the session user id in a deprecated multi user field", async () => {
const allUsers = [...globalUsers, config.getUser()].map((user: any) => { const allUsers = [...globalUsers, config.getUser()].map(
(user: any) => {
return { _id: user._id } return { _id: user._id }
}) }
)
await expectQuery({ await expectQuery({
contains: { deprecated_multi_user: ["{{ [user]._id }}"] }, contains: { deprecated_multi_user: ["{{ [user]._id }}"] },
@ -765,7 +791,7 @@ describe.each([
describe.each([FieldType.STRING, FieldType.LONGFORM])("%s", () => { describe.each([FieldType.STRING, FieldType.LONGFORM])("%s", () => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
name: { name: "name", type: FieldType.STRING }, name: { name: "name", type: FieldType.STRING },
}) })
await createRows([{ name: "foo" }, { name: "bar" }]) await createRows([{ name: "foo" }, { name: "bar" }])
@ -1056,7 +1082,7 @@ describe.each([
datasourceId: datasource!._id!, datasourceId: datasource!._id!,
}) })
sourceId = resp.datasource.entities![tableName]._id! tableOrViewId = resp.datasource.entities![tableName]._id!
await createRows([{ name: "foo" }, { name: "bar" }]) await createRows([{ name: "foo" }, { name: "bar" }])
}) })
@ -1080,7 +1106,7 @@ describe.each([
describe("numbers", () => { describe("numbers", () => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
age: { name: "age", type: FieldType.NUMBER }, age: { name: "age", type: FieldType.NUMBER },
}) })
await createRows([{ age: 1 }, { age: 10 }]) await createRows([{ age: 1 }, { age: 10 }])
@ -1088,7 +1114,9 @@ describe.each([
describe("equal", () => { describe("equal", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ equal: { age: 1 } }).toContainExactly([{ age: 1 }]) await expectQuery({ equal: { age: 1 } }).toContainExactly([
{ age: 1 },
])
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
@ -1253,7 +1281,7 @@ describe.each([
const JAN_10TH = "2020-01-10T00:00:00.000Z" const JAN_10TH = "2020-01-10T00:00:00.000Z"
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
dob: { name: "dob", type: FieldType.DATETIME }, dob: { name: "dob", type: FieldType.DATETIME },
}) })
@ -1325,25 +1353,33 @@ describe.each([
it("greater than equal to", async () => { it("greater than equal to", async () => {
await expectQuery({ await expectQuery({
range: { dob: { low: JAN_10TH, high: MAX_VALID_DATE.toISOString() } }, range: {
dob: { low: JAN_10TH, high: MAX_VALID_DATE.toISOString() },
},
}).toContainExactly([{ dob: JAN_10TH }]) }).toContainExactly([{ dob: JAN_10TH }])
}) })
it("greater than", async () => { it("greater than", async () => {
await expectQuery({ await expectQuery({
range: { dob: { low: JAN_5TH, high: MAX_VALID_DATE.toISOString() } }, range: {
dob: { low: JAN_5TH, high: MAX_VALID_DATE.toISOString() },
},
}).toContainExactly([{ dob: JAN_10TH }]) }).toContainExactly([{ dob: JAN_10TH }])
}) })
it("less than equal to", async () => { it("less than equal to", async () => {
await expectQuery({ await expectQuery({
range: { dob: { high: JAN_1ST, low: MIN_VALID_DATE.toISOString() } }, range: {
dob: { high: JAN_1ST, low: MIN_VALID_DATE.toISOString() },
},
}).toContainExactly([{ dob: JAN_1ST }]) }).toContainExactly([{ dob: JAN_1ST }])
}) })
it("less than", async () => { it("less than", async () => {
await expectQuery({ await expectQuery({
range: { dob: { high: JAN_5TH, low: MIN_VALID_DATE.toISOString() } }, range: {
dob: { high: JAN_5TH, low: MIN_VALID_DATE.toISOString() },
},
}).toContainExactly([{ dob: JAN_1ST }]) }).toContainExactly([{ dob: JAN_1ST }])
}) })
}) })
@ -1400,7 +1436,7 @@ describe.each([
const NULL_TIME__ID = `null_time__id` const NULL_TIME__ID = `null_time__id`
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
timeid: { name: "timeid", type: FieldType.STRING }, timeid: { name: "timeid", type: FieldType.STRING },
time: { name: "time", type: FieldType.DATETIME, timeOnly: true }, time: { name: "time", type: FieldType.DATETIME, timeOnly: true },
}) })
@ -1561,7 +1597,7 @@ describe.each([
describe.each([FieldType.ARRAY, FieldType.OPTIONS])("%s", () => { describe.each([FieldType.ARRAY, FieldType.OPTIONS])("%s", () => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
numbers: { numbers: {
name: "numbers", name: "numbers",
type: FieldType.ARRAY, type: FieldType.ARRAY,
@ -1576,9 +1612,9 @@ describe.each([
describe("contains", () => { describe("contains", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ contains: { numbers: ["one"] } }).toContainExactly([ await expectQuery({
{ numbers: ["one", "two"] }, contains: { numbers: ["one"] },
]) }).toContainExactly([{ numbers: ["one", "two"] }])
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
@ -1658,7 +1694,7 @@ describe.each([
let BIG = "9223372036854775807" let BIG = "9223372036854775807"
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
num: { name: "num", type: FieldType.BIGINT }, num: { name: "num", type: FieldType.BIGINT },
}) })
await createRows([{ num: SMALL }, { num: MEDIUM }, { num: BIG }]) await createRows([{ num: SMALL }, { num: MEDIUM }, { num: BIG }])
@ -1763,7 +1799,7 @@ describe.each([
isInternal && isInternal &&
describe("auto", () => { describe("auto", () => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
auto: { auto: {
name: "auto", name: "auto",
type: FieldType.AUTO, type: FieldType.AUTO,
@ -1913,18 +1949,21 @@ describe.each([
// be stable or pagination will break. We don't want the user to need // be stable or pagination will break. We don't want the user to need
// to specify an order for pagination to work. // to specify an order for pagination to work.
it("is stable without a sort specified", async () => { it("is stable without a sort specified", async () => {
let { rows: fullRowList } = await config.api.row.search(sourceId, { let { rows: fullRowList } = await config.api.row.search(
tableId: sourceId, tableOrViewId,
{
tableId: tableOrViewId,
query: {}, query: {},
}) }
)
// repeat the search many times to check the first row is always the same // repeat the search many times to check the first row is always the same
let bookmark: string | number | undefined, let bookmark: string | number | undefined,
hasNextPage: boolean | undefined = true, hasNextPage: boolean | undefined = true,
rowCount: number = 0 rowCount: number = 0
do { do {
const response = await config.api.row.search(sourceId, { const response = await config.api.row.search(tableOrViewId, {
tableId: sourceId, tableId: tableOrViewId,
limit: 1, limit: 1,
paginate: true, paginate: true,
query: {}, query: {},
@ -1947,8 +1986,8 @@ describe.each([
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
while (true) { while (true) {
const response = await config.api.row.search(sourceId, { const response = await config.api.row.search(tableOrViewId, {
tableId: sourceId, tableId: tableOrViewId,
limit: 3, limit: 3,
query: {}, query: {},
bookmark, bookmark,
@ -1971,7 +2010,7 @@ describe.each([
describe("field name 1:name", () => { describe("field name 1:name", () => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
"1:name": { name: "1:name", type: FieldType.STRING }, "1:name": { name: "1:name", type: FieldType.STRING },
}) })
await createRows([{ "1:name": "bar" }, { "1:name": "foo" }]) await createRows([{ "1:name": "bar" }, { "1:name": "foo" }])
@ -1991,7 +2030,7 @@ describe.each([
isSql && isSql &&
describe("related formulas", () => { describe("related formulas", () => {
beforeAll(async () => { beforeAll(async () => {
const arrayTable = await createTable( const arrayTable = await createSource(
{ {
name: { name: "name", type: FieldType.STRING }, name: { name: "name", type: FieldType.STRING },
array: { array: {
@ -2005,7 +2044,7 @@ describe.each([
}, },
"array" "array"
) )
sourceId = await createTable( tableOrViewId = await createSource(
{ {
relationship: { relationship: {
type: FieldType.LINK, type: FieldType.LINK,
@ -2038,7 +2077,7 @@ describe.each([
}), }),
]) ])
await Promise.all([ await Promise.all([
config.api.row.save(sourceId, { config.api.row.save(tableOrViewId, {
relationship: [arrayRows[0]._id, arrayRows[1]._id], relationship: [arrayRows[0]._id, arrayRows[1]._id],
}), }),
]) ])
@ -2057,7 +2096,7 @@ describe.each([
user1 = await config.createUser({ _id: `us_${utils.newid()}` }) user1 = await config.createUser({ _id: `us_${utils.newid()}` })
user2 = await config.createUser({ _id: `us_${utils.newid()}` }) user2 = await config.createUser({ _id: `us_${utils.newid()}` })
sourceId = await createTable({ tableOrViewId = await createSource({
user: { user: {
name: "user", name: "user",
type: FieldType.BB_REFERENCE_SINGLE, type: FieldType.BB_REFERENCE_SINGLE,
@ -2065,11 +2104,7 @@ describe.each([
}, },
}) })
await createRows([ await createRows([{ user: user1 }, { user: user2 }, { user: null }])
{ user: JSON.stringify(user1) },
{ user: JSON.stringify(user2) },
{ user: null },
])
}) })
describe("equal", () => { describe("equal", () => {
@ -2086,18 +2121,15 @@ describe.each([
describe("notEqual", () => { describe("notEqual", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ notEqual: { user: user1._id } }).toContainExactly([ await expectQuery({ notEqual: { user: user1._id } }).toContainExactly(
{ user: { _id: user2._id } }, [{ user: { _id: user2._id } }, {}]
{}, )
])
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
await expectQuery({ notEqual: { user: "us_none" } }).toContainExactly([ await expectQuery({ notEqual: { user: "us_none" } }).toContainExactly(
{ user: { _id: user1._id } }, [{ user: { _id: user1._id } }, { user: { _id: user2._id } }, {}]
{ user: { _id: user2._id } }, )
{},
])
}) })
}) })
@ -2137,7 +2169,7 @@ describe.each([
user1 = await config.createUser({ _id: `us_${utils.newid()}` }) user1 = await config.createUser({ _id: `us_${utils.newid()}` })
user2 = await config.createUser({ _id: `us_${utils.newid()}` }) user2 = await config.createUser({ _id: `us_${utils.newid()}` })
sourceId = await createTable({ tableOrViewId = await createSource({
users: { users: {
name: "users", name: "users",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
@ -2151,10 +2183,10 @@ describe.each([
}) })
await createRows([ await createRows([
{ number: 1, users: JSON.stringify([user1]) }, { number: 1, users: [user1] },
{ number: 2, users: JSON.stringify([user2]) }, { number: 2, users: [user2] },
{ number: 3, users: JSON.stringify([user1, user2]) }, { number: 3, users: [user1, user2] },
{ number: 4, users: JSON.stringify([]) }, { number: 4, users: [] },
]) ])
}) })
@ -2180,7 +2212,9 @@ describe.each([
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
await expectQuery({ contains: { users: ["us_none"] } }).toFindNothing() await expectQuery({
contains: { users: ["us_none"] },
}).toFindNothing()
}) })
}) })
@ -2250,7 +2284,7 @@ describe.each([
const { relatedTable, tableId } = await basicRelationshipTables( const { relatedTable, tableId } = await basicRelationshipTables(
RelationshipType.ONE_TO_MANY RelationshipType.ONE_TO_MANY
) )
sourceId = tableId tableOrViewId = tableId
productCategoryTable = relatedTable productCategoryTable = relatedTable
productCatRows = await Promise.all([ productCatRows = await Promise.all([
@ -2259,15 +2293,15 @@ describe.each([
]) ])
await Promise.all([ await Promise.all([
config.api.row.save(sourceId, { config.api.row.save(tableOrViewId, {
name: "foo", name: "foo",
productCat: [productCatRows[0]._id], productCat: [productCatRows[0]._id],
}), }),
config.api.row.save(sourceId, { config.api.row.save(tableOrViewId, {
name: "bar", name: "bar",
productCat: [productCatRows[1]._id], productCat: [productCatRows[1]._id],
}), }),
config.api.row.save(sourceId, { config.api.row.save(tableOrViewId, {
name: "baz", name: "baz",
productCat: [], productCat: [],
}), }),
@ -2303,8 +2337,8 @@ describe.each([
const { relatedTable, tableId } = await basicRelationshipTables( const { relatedTable, tableId } = await basicRelationshipTables(
RelationshipType.MANY_TO_ONE RelationshipType.MANY_TO_ONE
) )
sourceId = tableId tableOrViewId = tableId
const mainRow = await config.api.row.save(sourceId, { const mainRow = await config.api.row.save(tableOrViewId, {
name: "foo", name: "foo",
}) })
for (let i = 0; i < 11; i++) { for (let i = 0; i < 11; i++) {
@ -2332,13 +2366,13 @@ describe.each([
let relatedTable: string, relatedRows: Row[] let relatedTable: string, relatedRows: Row[]
beforeAll(async () => { beforeAll(async () => {
relatedTable = await createTable( relatedTable = await createSource(
{ {
name: { name: "name", type: FieldType.STRING }, name: { name: "name", type: FieldType.STRING },
}, },
"productCategory" "productCategory"
) )
sourceId = await createTable({ tableOrViewId = await createSource({
name: { name: "name", type: FieldType.STRING }, name: { name: "name", type: FieldType.STRING },
related1: { related1: {
type: FieldType.LINK, type: FieldType.LINK,
@ -2362,12 +2396,12 @@ describe.each([
config.api.row.save(relatedTable, { name: "boo" }), config.api.row.save(relatedTable, { name: "boo" }),
]) ])
await Promise.all([ await Promise.all([
config.api.row.save(sourceId, { config.api.row.save(tableOrViewId, {
name: "test", name: "test",
related1: [relatedRows[0]._id!], related1: [relatedRows[0]._id!],
related2: [relatedRows[1]._id!], related2: [relatedRows[1]._id!],
}), }),
config.api.row.save(sourceId, { config.api.row.save(tableOrViewId, {
name: "test2", name: "test2",
related1: [relatedRows[2]._id!], related1: [relatedRows[2]._id!],
related2: [relatedRows[3]._id!], related2: [relatedRows[3]._id!],
@ -2430,7 +2464,7 @@ describe.each([
isInternal && isInternal &&
describe("no column error backwards compat", () => { describe("no column error backwards compat", () => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
name: { name: {
name: "name", name: "name",
type: FieldType.STRING, type: FieldType.STRING,
@ -2453,7 +2487,7 @@ describe.each([
!isLucene && !isLucene &&
describe("row counting", () => { describe("row counting", () => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
name: { name: {
name: "name", name: "name",
type: FieldType.STRING, type: FieldType.STRING,
@ -2488,7 +2522,7 @@ describe.each([
describe("Invalid column definitions", () => { describe("Invalid column definitions", () => {
beforeAll(async () => { beforeAll(async () => {
// need to create an invalid table - means ignoring typescript // need to create an invalid table - means ignoring typescript
sourceId = await createTable({ tableOrViewId = await createSource({
// @ts-ignore // @ts-ignore
invalid: { invalid: {
type: FieldType.STRING, type: FieldType.STRING,
@ -2518,7 +2552,7 @@ describe.each([
"special (%s) case", "special (%s) case",
column => { column => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
[column]: { [column]: {
name: column, name: column,
type: FieldType.STRING, type: FieldType.STRING,
@ -2543,8 +2577,8 @@ describe.each([
describe("sample data", () => { describe("sample data", () => {
beforeAll(async () => { beforeAll(async () => {
await config.api.application.addSampleData(config.appId!) await config.api.application.addSampleData(config.appId!)
sourceId = DEFAULT_EMPLOYEE_TABLE_SCHEMA._id! tableOrViewId = DEFAULT_EMPLOYEE_TABLE_SCHEMA._id!
rows = await config.api.row.fetch(sourceId) rows = await config.api.row.fetch(tableOrViewId)
}) })
it("should be able to search sample data", async () => { it("should be able to search sample data", async () => {
@ -2567,7 +2601,7 @@ describe.each([
const earlyDate = "2024-07-03T10:00:00.000Z", const earlyDate = "2024-07-03T10:00:00.000Z",
laterDate = "2024-07-03T11:00:00.000Z" laterDate = "2024-07-03T11:00:00.000Z"
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
date: { date: {
name: "date", name: "date",
type: FieldType.DATETIME, type: FieldType.DATETIME,
@ -2610,7 +2644,7 @@ describe.each([
"ชื่อผู้ใช้", // Thai for "username" "ชื่อผู้ใช้", // Thai for "username"
])("non-ascii column name: %s", name => { ])("non-ascii column name: %s", name => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
[name]: { [name]: {
name, name,
type: FieldType.STRING, type: FieldType.STRING,
@ -2637,7 +2671,7 @@ describe.each([
isInternal && isInternal &&
describe("space at end of column name", () => { describe("space at end of column name", () => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
"name ": { "name ": {
name: "name ", name: "name ",
type: FieldType.STRING, type: FieldType.STRING,
@ -2672,7 +2706,7 @@ describe.each([
;(isSqs || isInMemory) && ;(isSqs || isInMemory) &&
describe("space at start of column name", () => { describe("space at start of column name", () => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
" name": { " name": {
name: " name", name: " name",
type: FieldType.STRING, type: FieldType.STRING,
@ -2705,7 +2739,7 @@ describe.each([
isSqs && isSqs &&
describe("duplicate columns", () => { describe("duplicate columns", () => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
name: { name: {
name: "name", name: "name",
type: FieldType.STRING, type: FieldType.STRING,
@ -2713,7 +2747,7 @@ describe.each([
}) })
await context.doInAppContext(config.getAppId(), async () => { await context.doInAppContext(config.getAppId(), async () => {
const db = context.getAppDB() const db = context.getAppDB()
const tableDoc = await db.get<Table>(sourceId) const tableDoc = await db.get<Table>(tableOrViewId)
tableDoc.schema.Name = { tableDoc.schema.Name = {
name: "Name", name: "Name",
type: FieldType.STRING, type: FieldType.STRING,
@ -2741,13 +2775,13 @@ describe.each([
let row: Row let row: Row
beforeAll(async () => { beforeAll(async () => {
const toRelateTable = await createTable({ const toRelateTable = await createSource({
name: { name: {
name: "name", name: "name",
type: FieldType.STRING, type: FieldType.STRING,
}, },
}) })
sourceId = await createTable({ tableOrViewId = await createSource({
name: { name: {
name: "name", name: "name",
type: FieldType.STRING, type: FieldType.STRING,
@ -2764,7 +2798,7 @@ describe.each([
config.api.row.save(toRelateTable, { name: "tag 1" }), config.api.row.save(toRelateTable, { name: "tag 1" }),
config.api.row.save(toRelateTable, { name: "tag 2" }), config.api.row.save(toRelateTable, { name: "tag 2" }),
]) ])
row = await config.api.row.save(sourceId, { row = await config.api.row.save(tableOrViewId, {
name: "product 1", name: "product 1",
rel: [row1._id, row2._id], rel: [row1._id, row2._id],
}) })
@ -2798,7 +2832,7 @@ describe.each([
primary: ["idColumn1", "idColumn2"], primary: ["idColumn1", "idColumn2"],
}) })
) )
sourceId = table._id! tableOrViewId = table._id!
await createRows([{ idColumn1: 1, idColumn2: 2 }]) await createRows([{ idColumn1: 1, idColumn2: 2 }])
}) })
@ -2820,7 +2854,7 @@ describe.each([
isSql && isSql &&
describe("primaryDisplay", () => { describe("primaryDisplay", () => {
beforeAll(async () => { beforeAll(async () => {
let toRelateTableId = await createTable({ let toRelateTableId = await createSource({
name: { name: {
name: "name", name: "name",
type: FieldType.STRING, type: FieldType.STRING,
@ -2843,7 +2877,7 @@ describe.each([
}, },
}) })
) )
sourceId = table._id! 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,
@ -2853,7 +2887,7 @@ describe.each([
config.api.row.save(toRelateTable._id!, { name: "test" }), config.api.row.save(toRelateTable._id!, { name: "test" }),
]) ])
await Promise.all([ await Promise.all([
config.api.row.save(sourceId, { config.api.row.save(tableOrViewId, {
name: "test", name: "test",
link: relatedRows.map(row => row._id), link: relatedRows.map(row => row._id),
}), }),
@ -2872,7 +2906,7 @@ describe.each([
!isLucene && !isLucene &&
describe("$and", () => { describe("$and", () => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
age: { name: "age", type: FieldType.NUMBER }, age: { name: "age", type: FieldType.NUMBER },
name: { name: "name", type: FieldType.STRING }, name: { name: "name", type: FieldType.STRING },
}) })
@ -2947,7 +2981,10 @@ describe.each([
await expect( await expect(
expectQuery({ expectQuery({
$and: { $and: {
conditions: [{ equal: { age: 10 } }, "invalidCondition" as any], conditions: [
{ equal: { age: 10 } },
"invalidCondition" as any,
],
}, },
}).toFindNothing() }).toFindNothing()
).rejects.toThrow( ).rejects.toThrow(
@ -3001,7 +3038,7 @@ describe.each([
!isLucene && !isLucene &&
describe("$or", () => { describe("$or", () => {
beforeAll(async () => { beforeAll(async () => {
sourceId = await createTable({ tableOrViewId = await createSource({
age: { name: "age", type: FieldType.NUMBER }, age: { name: "age", type: FieldType.NUMBER },
name: { name: "name", type: FieldType.STRING }, name: { name: "name", type: FieldType.STRING },
}) })
@ -3160,8 +3197,8 @@ describe.each([
relatedSchema[name] = { name, type: FieldType.NUMBER } relatedSchema[name] = { name, type: FieldType.NUMBER }
row[name] = i row[name] = i
} }
const relatedTable = await createTable(relatedSchema) const relatedTable = await createSource(relatedSchema)
sourceId = await createTable({ tableOrViewId = await createSource({
name: { name: "name", type: FieldType.STRING }, name: { name: "name", type: FieldType.STRING },
related1: { related1: {
type: FieldType.LINK, type: FieldType.LINK,
@ -3174,7 +3211,7 @@ describe.each([
relatedRows = await Promise.all([ relatedRows = await Promise.all([
config.api.row.save(relatedTable, row), config.api.row.save(relatedTable, row),
]) ])
await config.api.row.save(sourceId, { await config.api.row.save(tableOrViewId, {
name: "foo", name: "foo",
related1: [relatedRows[0]._id], related1: [relatedRows[0]._id],
}) })
@ -3190,3 +3227,4 @@ describe.each([
}) })
}) })
}) })
})

View File

@ -7,11 +7,11 @@ import {
BulkImportRequest, BulkImportRequest,
BulkImportResponse, BulkImportResponse,
SearchRowResponse, SearchRowResponse,
RowSearchParams,
DeleteRows, DeleteRows,
DeleteRow, DeleteRow,
PaginatedSearchRowResponse, PaginatedSearchRowResponse,
RowExportFormat, RowExportFormat,
SearchRowRequest,
} from "@budibase/types" } from "@budibase/types"
import { Expectations, TestAPI } from "./base" import { Expectations, TestAPI } from "./base"
@ -136,7 +136,7 @@ export class RowAPI extends TestAPI {
) )
} }
search = async <T extends RowSearchParams>( search = async <T extends SearchRowRequest>(
sourceId: string, sourceId: string,
params?: T, params?: T,
expectations?: Expectations expectations?: Expectations