Merge branch 'master' into new-datepicker
This commit is contained in:
commit
58dfd77baa
|
@ -64,10 +64,11 @@ jobs:
|
||||||
- run: yarn --frozen-lockfile
|
- run: yarn --frozen-lockfile
|
||||||
|
|
||||||
# Run build all the projects
|
# Run build all the projects
|
||||||
- name: Build
|
- name: Build OSS
|
||||||
run: |
|
run: yarn build:oss
|
||||||
yarn build:oss
|
- name: Build account portal
|
||||||
yarn build:account-portal
|
run: yarn build:account-portal
|
||||||
|
if: ${{ env.IS_OSS_CONTRIBUTOR == 'false' }}
|
||||||
# Check the types of the projects built via esbuild
|
# Check the types of the projects built via esbuild
|
||||||
- name: Check types
|
- name: Check types
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "2.23.3",
|
"version": "2.23.4",
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"packages": [
|
"packages": [
|
||||||
"packages/*",
|
"packages/*",
|
||||||
|
|
|
@ -6,10 +6,12 @@ import {
|
||||||
Datasource,
|
Datasource,
|
||||||
EmptyFilterOption,
|
EmptyFilterOption,
|
||||||
FieldType,
|
FieldType,
|
||||||
Row,
|
RowSearchParams,
|
||||||
SearchFilters,
|
SearchFilters,
|
||||||
Table,
|
Table,
|
||||||
|
TableSchema,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
import _ from "lodash"
|
||||||
|
|
||||||
jest.unmock("mssql")
|
jest.unmock("mssql")
|
||||||
|
|
||||||
|
@ -25,8 +27,8 @@ describe.each([
|
||||||
const config = setup.getConfig()
|
const config = setup.getConfig()
|
||||||
|
|
||||||
let envCleanup: (() => void) | undefined
|
let envCleanup: (() => void) | undefined
|
||||||
let table: Table
|
|
||||||
let datasource: Datasource | undefined
|
let datasource: Datasource | undefined
|
||||||
|
let table: Table
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
if (isSqs) {
|
if (isSqs) {
|
||||||
|
@ -47,231 +49,217 @@ describe.each([
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
async function createTable(schema: TableSchema) {
|
||||||
|
table = await config.api.table.save(
|
||||||
|
tableForDatasource(datasource, { schema })
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createRows(rows: Record<string, any>[]) {
|
||||||
|
await Promise.all(rows.map(r => config.api.row.save(table._id!, r)))
|
||||||
|
}
|
||||||
|
|
||||||
|
class SearchAssertion {
|
||||||
|
constructor(private readonly query: RowSearchParams) {}
|
||||||
|
|
||||||
|
async toFind(expectedRows: any[]) {
|
||||||
|
const { rows: foundRows } = await config.api.row.search(table._id!, {
|
||||||
|
...this.query,
|
||||||
|
tableId: table._id!,
|
||||||
|
})
|
||||||
|
|
||||||
|
// eslint-disable-next-line jest/no-standalone-expect
|
||||||
|
expect(foundRows).toHaveLength(expectedRows.length)
|
||||||
|
// eslint-disable-next-line jest/no-standalone-expect
|
||||||
|
expect(foundRows).toEqual(
|
||||||
|
expect.arrayContaining(
|
||||||
|
expectedRows.map((expectedRow: any) =>
|
||||||
|
expect.objectContaining(
|
||||||
|
foundRows.find(foundRow => _.isMatch(foundRow, expectedRow))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async toFindNothing() {
|
||||||
|
await this.toFind([])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function expectSearch(query: Omit<RowSearchParams, "tableId">) {
|
||||||
|
return new SearchAssertion({ ...query, tableId: table._id! })
|
||||||
|
}
|
||||||
|
|
||||||
|
function expectQuery(query: SearchFilters) {
|
||||||
|
return expectSearch({ query })
|
||||||
|
}
|
||||||
|
|
||||||
describe("strings", () => {
|
describe("strings", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
table = await config.api.table.save(
|
await createTable({
|
||||||
tableForDatasource(datasource, {
|
name: { name: "name", type: FieldType.STRING },
|
||||||
schema: {
|
|
||||||
name: {
|
|
||||||
name: "name",
|
|
||||||
type: FieldType.STRING,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
)
|
await createRows([{ name: "foo" }, { name: "bar" }])
|
||||||
})
|
})
|
||||||
|
|
||||||
const rows = [{ name: "foo" }, { name: "bar" }]
|
describe("misc", () => {
|
||||||
let savedRows: Row[]
|
it("should return all if no query is passed", () =>
|
||||||
|
expectSearch({} as RowSearchParams).toFind([
|
||||||
|
{ name: "foo" },
|
||||||
|
{ name: "bar" },
|
||||||
|
]))
|
||||||
|
|
||||||
|
it("should return all if empty query is passed", () =>
|
||||||
|
expectQuery({}).toFind([{ name: "foo" }, { name: "bar" }]))
|
||||||
|
|
||||||
|
it("should return all if onEmptyFilter is RETURN_ALL", () =>
|
||||||
|
expectQuery({
|
||||||
|
onEmptyFilter: EmptyFilterOption.RETURN_ALL,
|
||||||
|
}).toFind([{ name: "foo" }, { name: "bar" }]))
|
||||||
|
|
||||||
|
it("should return nothing if onEmptyFilter is RETURN_NONE", () =>
|
||||||
|
expectQuery({
|
||||||
|
onEmptyFilter: EmptyFilterOption.RETURN_NONE,
|
||||||
|
}).toFindNothing())
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("equal", () => {
|
||||||
|
it("successfully finds a row", () =>
|
||||||
|
expectQuery({ equal: { name: "foo" } }).toFind([{ name: "foo" }]))
|
||||||
|
|
||||||
|
it("fails to find nonexistent row", () =>
|
||||||
|
expectQuery({ equal: { name: "none" } }).toFindNothing())
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("notEqual", () => {
|
||||||
|
it("successfully finds a row", () =>
|
||||||
|
expectQuery({ notEqual: { name: "foo" } }).toFind([{ name: "bar" }]))
|
||||||
|
|
||||||
|
it("fails to find nonexistent row", () =>
|
||||||
|
expectQuery({ notEqual: { name: "bar" } }).toFind([{ name: "foo" }]))
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("oneOf", () => {
|
||||||
|
it("successfully finds a row", () =>
|
||||||
|
expectQuery({ oneOf: { name: ["foo"] } }).toFind([{ name: "foo" }]))
|
||||||
|
|
||||||
|
it("fails to find nonexistent row", () =>
|
||||||
|
expectQuery({ oneOf: { name: ["none"] } }).toFindNothing())
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("fuzzy", () => {
|
||||||
|
it("successfully finds a row", () =>
|
||||||
|
expectQuery({ fuzzy: { name: "oo" } }).toFind([{ name: "foo" }]))
|
||||||
|
|
||||||
|
it("fails to find nonexistent row", () =>
|
||||||
|
expectQuery({ fuzzy: { name: "none" } }).toFindNothing())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("numbers", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
savedRows = await Promise.all(
|
await createTable({
|
||||||
rows.map(r => config.api.row.save(table._id!, r))
|
age: { name: "age", type: FieldType.NUMBER },
|
||||||
)
|
})
|
||||||
|
await createRows([{ age: 1 }, { age: 10 }])
|
||||||
})
|
})
|
||||||
|
|
||||||
interface StringSearchTest {
|
describe("equal", () => {
|
||||||
query: SearchFilters
|
it("successfully finds a row", () =>
|
||||||
expected: (typeof rows)[number][]
|
expectQuery({ equal: { age: 1 } }).toFind([{ age: 1 }]))
|
||||||
}
|
|
||||||
|
|
||||||
const stringSearchTests: StringSearchTest[] = [
|
it("fails to find nonexistent row", () =>
|
||||||
// These three test cases are generic and don't really need
|
expectQuery({ equal: { age: 2 } }).toFindNothing())
|
||||||
// to be repeated for all data types, so we just do them here.
|
|
||||||
{ query: {}, expected: rows },
|
|
||||||
{
|
|
||||||
query: { onEmptyFilter: EmptyFilterOption.RETURN_ALL },
|
|
||||||
expected: rows,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
query: { onEmptyFilter: EmptyFilterOption.RETURN_NONE },
|
|
||||||
expected: [],
|
|
||||||
},
|
|
||||||
// The rest of these tests are specific to strings.
|
|
||||||
{ query: { string: { name: "foo" } }, expected: [rows[0]] },
|
|
||||||
{ query: { string: { name: "none" } }, expected: [] },
|
|
||||||
{ query: { fuzzy: { name: "oo" } }, expected: [rows[0]] },
|
|
||||||
{ query: { equal: { name: "foo" } }, expected: [rows[0]] },
|
|
||||||
{ query: { notEqual: { name: "foo" } }, expected: [rows[1]] },
|
|
||||||
{ query: { oneOf: { name: ["foo"] } }, expected: [rows[0]] },
|
|
||||||
]
|
|
||||||
|
|
||||||
it.each(stringSearchTests)(
|
|
||||||
`should be able to run query: $query`,
|
|
||||||
async ({ query, expected }) => {
|
|
||||||
const { rows: foundRows } = await config.api.row.search(table._id!, {
|
|
||||||
tableId: table._id!,
|
|
||||||
query,
|
|
||||||
})
|
|
||||||
expect(foundRows).toHaveLength(expected.length)
|
|
||||||
expect(foundRows).toEqual(
|
|
||||||
expect.arrayContaining(
|
|
||||||
expected.map(r =>
|
|
||||||
expect.objectContaining(savedRows.find(sr => sr.name === r.name)!)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("number", () => {
|
describe("notEqual", () => {
|
||||||
beforeAll(async () => {
|
it("successfully finds a row", () =>
|
||||||
table = await config.api.table.save(
|
expectQuery({ notEqual: { age: 1 } }).toFind([{ age: 10 }]))
|
||||||
tableForDatasource(datasource, {
|
|
||||||
schema: {
|
it("fails to find nonexistent row", () =>
|
||||||
age: {
|
expectQuery({ notEqual: { age: 10 } }).toFind([{ age: 1 }]))
|
||||||
name: "age",
|
|
||||||
type: FieldType.NUMBER,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const rows = [{ age: 1 }, { age: 10 }]
|
describe("oneOf", () => {
|
||||||
let savedRows: Row[]
|
it("successfully finds a row", () =>
|
||||||
|
expectQuery({ oneOf: { age: [1] } }).toFind([{ age: 1 }]))
|
||||||
|
|
||||||
beforeAll(async () => {
|
it("fails to find nonexistent row", () =>
|
||||||
savedRows = await Promise.all(
|
expectQuery({ oneOf: { age: [2] } }).toFindNothing())
|
||||||
rows.map(r => config.api.row.save(table._id!, r))
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
interface NumberSearchTest {
|
describe("range", () => {
|
||||||
query: SearchFilters
|
it("successfully finds a row", () =>
|
||||||
expected: (typeof rows)[number][]
|
expectQuery({
|
||||||
}
|
range: { age: { low: 1, high: 5 } },
|
||||||
|
}).toFind([{ age: 1 }]))
|
||||||
|
|
||||||
const numberSearchTests: NumberSearchTest[] = [
|
it("successfully finds multiple rows", () =>
|
||||||
{ query: { equal: { age: 1 } }, expected: [rows[0]] },
|
expectQuery({
|
||||||
{ query: { equal: { age: 2 } }, expected: [] },
|
range: { age: { low: 1, high: 10 } },
|
||||||
{ query: { notEqual: { age: 1 } }, expected: [rows[1]] },
|
}).toFind([{ age: 1 }, { age: 10 }]))
|
||||||
{ query: { oneOf: { age: [1] } }, expected: [rows[0]] },
|
|
||||||
{ query: { range: { age: { low: 1, high: 5 } } }, expected: [rows[0]] },
|
|
||||||
{ query: { range: { age: { low: 0, high: 1 } } }, expected: [rows[0]] },
|
|
||||||
{ query: { range: { age: { low: 3, high: 4 } } }, expected: [] },
|
|
||||||
{ query: { range: { age: { low: 0, high: 11 } } }, expected: rows },
|
|
||||||
]
|
|
||||||
|
|
||||||
it.each(numberSearchTests)(
|
it("successfully finds a row with a high bound", () =>
|
||||||
`should be able to run query: $query`,
|
expectQuery({
|
||||||
async ({ query, expected }) => {
|
range: { age: { low: 5, high: 10 } },
|
||||||
const { rows: foundRows } = await config.api.row.search(table._id!, {
|
}).toFind([{ age: 10 }]))
|
||||||
tableId: table._id!,
|
|
||||||
query,
|
|
||||||
})
|
})
|
||||||
expect(foundRows).toHaveLength(expected.length)
|
|
||||||
expect(foundRows).toEqual(
|
|
||||||
expect.arrayContaining(
|
|
||||||
expected.map(r =>
|
|
||||||
expect.objectContaining(savedRows.find(sr => sr.age === r.age)!)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("dates", () => {
|
describe("dates", () => {
|
||||||
beforeEach(async () => {
|
const JAN_1ST = "2020-01-01T00:00:00.000Z"
|
||||||
table = await config.api.table.save(
|
const JAN_2ND = "2020-01-02T00:00:00.000Z"
|
||||||
tableForDatasource(datasource, {
|
const JAN_5TH = "2020-01-05T00:00:00.000Z"
|
||||||
schema: {
|
const JAN_10TH = "2020-01-10T00:00:00.000Z"
|
||||||
dob: {
|
|
||||||
name: "dob",
|
beforeAll(async () => {
|
||||||
type: FieldType.DATETIME,
|
await createTable({
|
||||||
},
|
dob: { name: "dob", type: FieldType.DATETIME },
|
||||||
},
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const rows = [
|
await createRows([{ dob: JAN_1ST }, { dob: JAN_10TH }])
|
||||||
{ dob: new Date("2020-01-01").toISOString() },
|
|
||||||
{ dob: new Date("2020-01-10").toISOString() },
|
|
||||||
]
|
|
||||||
let savedRows: Row[]
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
savedRows = await Promise.all(
|
|
||||||
rows.map(r => config.api.row.save(table._id!, r))
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
interface DateSearchTest {
|
describe("equal", () => {
|
||||||
query: SearchFilters
|
it("successfully finds a row", () =>
|
||||||
expected: (typeof rows)[number][]
|
expectQuery({ equal: { dob: JAN_1ST } }).toFind([{ dob: JAN_1ST }]))
|
||||||
}
|
|
||||||
|
|
||||||
const dateSearchTests: DateSearchTest[] = [
|
it("fails to find nonexistent row", () =>
|
||||||
{
|
expectQuery({ equal: { dob: JAN_2ND } }).toFindNothing())
|
||||||
query: { equal: { dob: new Date("2020-01-01").toISOString() } },
|
})
|
||||||
expected: [rows[0]],
|
|
||||||
},
|
describe("notEqual", () => {
|
||||||
{
|
it("successfully finds a row", () =>
|
||||||
query: { equal: { dob: new Date("2020-01-02").toISOString() } },
|
expectQuery({ notEqual: { dob: JAN_1ST } }).toFind([{ dob: JAN_10TH }]))
|
||||||
expected: [],
|
|
||||||
},
|
it("fails to find nonexistent row", () =>
|
||||||
{
|
expectQuery({ notEqual: { dob: JAN_10TH } }).toFind([{ dob: JAN_1ST }]))
|
||||||
query: { notEqual: { dob: new Date("2020-01-01").toISOString() } },
|
})
|
||||||
expected: [rows[1]],
|
|
||||||
},
|
describe("oneOf", () => {
|
||||||
{
|
it("successfully finds a row", () =>
|
||||||
query: { oneOf: { dob: [new Date("2020-01-01").toISOString()] } },
|
expectQuery({ oneOf: { dob: [JAN_1ST] } }).toFind([{ dob: JAN_1ST }]))
|
||||||
expected: [rows[0]],
|
|
||||||
},
|
it("fails to find nonexistent row", () =>
|
||||||
{
|
expectQuery({ oneOf: { dob: [JAN_2ND] } }).toFindNothing())
|
||||||
query: {
|
})
|
||||||
range: {
|
|
||||||
dob: {
|
describe("range", () => {
|
||||||
low: new Date("2020-01-01").toISOString(),
|
it("successfully finds a row", () =>
|
||||||
high: new Date("2020-01-05").toISOString(),
|
expectQuery({
|
||||||
},
|
range: { dob: { low: JAN_1ST, high: JAN_5TH } },
|
||||||
},
|
}).toFind([{ dob: JAN_1ST }]))
|
||||||
},
|
|
||||||
expected: [rows[0]],
|
it("successfully finds multiple rows", () =>
|
||||||
},
|
expectQuery({
|
||||||
{
|
range: { dob: { low: JAN_1ST, high: JAN_10TH } },
|
||||||
query: {
|
}).toFind([{ dob: JAN_1ST }, { dob: JAN_10TH }]))
|
||||||
range: {
|
|
||||||
dob: {
|
it("successfully finds a row with a high bound", () =>
|
||||||
low: new Date("2020-01-01").toISOString(),
|
expectQuery({
|
||||||
high: new Date("2020-01-10").toISOString(),
|
range: { dob: { low: JAN_5TH, high: JAN_10TH } },
|
||||||
},
|
}).toFind([{ dob: JAN_10TH }]))
|
||||||
},
|
|
||||||
},
|
|
||||||
expected: rows,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
query: {
|
|
||||||
range: {
|
|
||||||
dob: {
|
|
||||||
low: new Date("2020-01-05").toISOString(),
|
|
||||||
high: new Date("2020-01-10").toISOString(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expected: [rows[1]],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
it.each(dateSearchTests)(
|
|
||||||
`should be able to run query: $query`,
|
|
||||||
async ({ query, expected }) => {
|
|
||||||
const { rows: foundRows } = await config.api.row.search(table._id!, {
|
|
||||||
tableId: table._id!,
|
|
||||||
query,
|
|
||||||
})
|
})
|
||||||
expect(foundRows).toHaveLength(expected.length)
|
|
||||||
expect(foundRows).toEqual(
|
|
||||||
expect.arrayContaining(
|
|
||||||
expected.map(r =>
|
|
||||||
expect.objectContaining(savedRows.find(sr => sr.dob === r.dob)!)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue