1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00

Merge branch 'master' into chore/remove-pro-test-specific-pipeline

This commit is contained in:
Adria Navarro 2024-03-15 15:44:34 +01:00 committed by GitHub
commit 7a77bda734
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 308 additions and 248 deletions

View file

@ -16,7 +16,7 @@ import {
ViewV2, ViewV2,
} from "@budibase/types" } from "@budibase/types"
import * as setup from "./utilities" import * as setup from "./utilities"
import { mocks } from "@budibase/backend-core/tests" import { generator, mocks } from "@budibase/backend-core/tests"
const { basicRow } = setup.structures const { basicRow } = setup.structures
const { BUILTIN_ROLE_IDS } = roles const { BUILTIN_ROLE_IDS } = roles
@ -44,7 +44,10 @@ describe("/permission", () => {
table = (await config.createTable()) as typeof table table = (await config.createTable()) as typeof table
row = await config.createRow() row = await config.createRow()
view = await config.api.viewV2.create({ tableId: table._id }) view = await config.api.viewV2.create({
tableId: table._id!,
name: generator.guid(),
})
perms = await config.api.permission.add({ perms = await config.api.permission.add({
roleId: STD_ROLE_ID, roleId: STD_ROLE_ID,
resourceId: table._id, resourceId: table._id,

View file

@ -42,6 +42,7 @@ tk.freeze(timestamp)
jest.unmock("mysql2") jest.unmock("mysql2")
jest.unmock("mysql2/promise") jest.unmock("mysql2/promise")
jest.unmock("mssql") jest.unmock("mssql")
jest.unmock("pg")
describe.each([ describe.each([
["internal", undefined], ["internal", undefined],
@ -152,8 +153,8 @@ describe.each([
table = await config.api.table.save(defaultTable()) table = await config.api.table.save(defaultTable())
}) })
describe("save, load, update", () => { describe("create", () => {
it("returns a success message when the row is created", async () => { it("creates a new row successfully", async () => {
const rowUsage = await getRowUsage() const rowUsage = await getRowUsage()
const row = await config.api.row.save(table._id!, { const row = await config.api.row.save(table._id!, {
name: "Test Contact", name: "Test Contact",
@ -163,7 +164,44 @@ describe.each([
await assertRowUsage(rowUsage + 1) await assertRowUsage(rowUsage + 1)
}) })
it("Increment row autoId per create row request", async () => { it("fails to create a row for a table that does not exist", async () => {
const rowUsage = await getRowUsage()
await config.api.row.save("1234567", {}, { status: 404 })
await assertRowUsage(rowUsage)
})
it("fails to create a row if required fields are missing", async () => {
const rowUsage = await getRowUsage()
const table = await config.api.table.save(
saveTableRequest({
schema: {
required: {
type: FieldType.STRING,
name: "required",
constraints: {
type: "string",
presence: true,
},
},
},
})
)
await config.api.row.save(
table._id!,
{},
{
status: 500,
body: {
validationErrors: {
required: ["can't be blank"],
},
},
}
)
await assertRowUsage(rowUsage)
})
it("increment row autoId per create row request", async () => {
const rowUsage = await getRowUsage() const rowUsage = await getRowUsage()
const newTable = await config.api.table.save( const newTable = await config.api.table.save(
@ -198,52 +236,6 @@ describe.each([
await assertRowUsage(rowUsage + 10) await assertRowUsage(rowUsage + 10)
}) })
it("updates a row successfully", async () => {
const existing = await config.api.row.save(table._id!, {})
const rowUsage = await getRowUsage()
const res = await config.api.row.save(table._id!, {
_id: existing._id,
_rev: existing._rev,
name: "Updated Name",
})
expect(res.name).toEqual("Updated Name")
await assertRowUsage(rowUsage)
})
it("should load a row", async () => {
const existing = await config.api.row.save(table._id!, {})
const res = await config.api.row.get(table._id!, existing._id!)
expect(res).toEqual({
...existing,
...defaultRowFields,
})
})
it("should list all rows for given tableId", async () => {
const table = await config.api.table.save(defaultTable())
const rows = await Promise.all([
config.api.row.save(table._id!, {}),
config.api.row.save(table._id!, {}),
])
const res = await config.api.row.fetch(table._id!)
expect(res.map(r => r._id)).toEqual(
expect.arrayContaining(rows.map(r => r._id))
)
})
it("load should return 404 when row does not exist", async () => {
const table = await config.api.table.save(defaultTable())
await config.api.row.save(table._id!, {})
await config.api.row.get(table._id!, "1234567", {
status: 404,
})
})
isInternal && isInternal &&
it("row values are coerced", async () => { it("row values are coerced", async () => {
const str: FieldSchema = { const str: FieldSchema = {
@ -296,8 +288,6 @@ describe.each([
} }
const table = await config.api.table.save( const table = await config.api.table.save(
saveTableRequest({ saveTableRequest({
name: "TestTable2",
type: "table",
schema: { schema: {
name: str, name: str,
stringUndefined: str, stringUndefined: str,
@ -404,53 +394,60 @@ describe.each([
}) })
}) })
describe("view save", () => { describe("get", () => {
it("views have extra data trimmed", async () => { it("reads an existing row successfully", async () => {
const table = await config.api.table.save( const existing = await config.api.row.save(table._id!, {})
saveTableRequest({
name: "orders",
schema: {
Country: {
type: FieldType.STRING,
name: "Country",
},
Story: {
type: FieldType.STRING,
name: "Story",
},
},
})
)
const createViewResponse = await config.api.viewV2.create({ const res = await config.api.row.get(table._id!, existing._id!)
tableId: table._id!,
name: uuid.v4(),
schema: {
Country: {
visible: true,
},
},
})
const createRowResponse = await config.api.row.save( expect(res).toEqual({
createViewResponse.id, ...existing,
{
Country: "Aussy",
Story: "aaaaa",
}
)
const row = await config.api.row.get(table._id!, createRowResponse._id!)
expect(row.Story).toBeUndefined()
expect(row).toEqual({
...defaultRowFields, ...defaultRowFields,
Country: "Aussy",
id: createRowResponse.id,
_id: createRowResponse._id,
_rev: createRowResponse._rev,
tableId: table._id,
}) })
}) })
it("returns 404 when row does not exist", async () => {
const table = await config.api.table.save(defaultTable())
await config.api.row.save(table._id!, {})
await config.api.row.get(table._id!, "1234567", {
status: 404,
})
})
})
describe("fetch", () => {
it("fetches all rows for given tableId", async () => {
const table = await config.api.table.save(defaultTable())
const rows = await Promise.all([
config.api.row.save(table._id!, {}),
config.api.row.save(table._id!, {}),
])
const res = await config.api.row.fetch(table._id!)
expect(res.map(r => r._id)).toEqual(
expect.arrayContaining(rows.map(r => r._id))
)
})
it("returns 404 when table does not exist", async () => {
await config.api.row.fetch("1234567", { status: 404 })
})
})
describe("update", () => {
it("updates an existing row successfully", async () => {
const existing = await config.api.row.save(table._id!, {})
const rowUsage = await getRowUsage()
const res = await config.api.row.save(table._id!, {
_id: existing._id,
_rev: existing._rev,
name: "Updated Name",
})
expect(res.name).toEqual("Updated Name")
await assertRowUsage(rowUsage)
})
}) })
describe("patch", () => { describe("patch", () => {
@ -722,50 +719,7 @@ describe.each([
}) })
}) })
// Legacy views are not available for external describe("enrich", () => {
isInternal &&
describe("fetchView", () => {
beforeEach(async () => {
table = await config.api.table.save(defaultTable())
})
it("should be able to fetch tables contents via 'view'", async () => {
const row = await config.api.row.save(table._id!, {})
const rowUsage = await getRowUsage()
const rows = await config.api.legacyView.get(table._id!)
expect(rows.length).toEqual(1)
expect(rows[0]._id).toEqual(row._id)
await assertRowUsage(rowUsage)
})
it("should throw an error if view doesn't exist", async () => {
const rowUsage = await getRowUsage()
await config.api.legacyView.get("derp", undefined, { status: 404 })
await assertRowUsage(rowUsage)
})
it("should be able to run on a view", async () => {
const view = await config.createLegacyView({
tableId: table._id!,
name: "ViewTest",
filters: [],
schema: {},
})
const row = await config.api.row.save(table._id!, {})
const rowUsage = await getRowUsage()
const rows = await config.api.legacyView.get(view.name)
expect(rows.length).toEqual(1)
expect(rows[0]._id).toEqual(row._id)
await assertRowUsage(rowUsage)
})
})
describe("fetchEnrichedRows", () => {
beforeAll(async () => { beforeAll(async () => {
table = await config.api.table.save(defaultTable()) table = await config.api.table.save(defaultTable())
}) })
@ -827,10 +781,6 @@ describe.each([
isInternal && isInternal &&
describe("attachments", () => { describe("attachments", () => {
beforeAll(async () => {
table = await config.api.table.save(defaultTable())
})
it("should allow enriching attachment rows", async () => { it("should allow enriching attachment rows", async () => {
const table = await config.api.table.save( const table = await config.api.table.save(
defaultTable({ defaultTable({
@ -865,7 +815,7 @@ describe.each([
}) })
}) })
describe("exportData", () => { describe("exportRows", () => {
beforeAll(async () => { beforeAll(async () => {
table = await config.api.table.save(defaultTable()) table = await config.api.table.save(defaultTable())
}) })
@ -947,6 +897,7 @@ describe.each([
const table = await config.api.table.save(await userTable()) const table = await config.api.table.save(await userTable())
const view = await config.api.viewV2.create({ const view = await config.api.viewV2.create({
tableId: table._id!, tableId: table._id!,
name: generator.guid(),
schema: { schema: {
name: { visible: true }, name: { visible: true },
surname: { visible: true }, surname: { visible: true },
@ -984,6 +935,7 @@ describe.each([
const tableId = table._id! const tableId = table._id!
const view = await config.api.viewV2.create({ const view = await config.api.viewV2.create({
tableId: tableId, tableId: tableId,
name: generator.guid(),
schema: { schema: {
name: { visible: true }, name: { visible: true },
address: { visible: true }, address: { visible: true },
@ -1026,6 +978,7 @@ describe.each([
const tableId = table._id! const tableId = table._id!
const view = await config.api.viewV2.create({ const view = await config.api.viewV2.create({
tableId: tableId, tableId: tableId,
name: generator.guid(),
schema: { schema: {
name: { visible: true }, name: { visible: true },
address: { visible: true }, address: { visible: true },
@ -1049,6 +1002,7 @@ describe.each([
const tableId = table._id! const tableId = table._id!
const view = await config.api.viewV2.create({ const view = await config.api.viewV2.create({
tableId: tableId, tableId: tableId,
name: generator.guid(),
schema: { schema: {
name: { visible: true }, name: { visible: true },
address: { visible: true }, address: { visible: true },
@ -1109,6 +1063,7 @@ describe.each([
const createViewResponse = await config.api.viewV2.create({ const createViewResponse = await config.api.viewV2.create({
tableId: table._id!, tableId: table._id!,
name: generator.guid(),
}) })
const response = await config.api.viewV2.search(createViewResponse.id) const response = await config.api.viewV2.search(createViewResponse.id)
@ -1155,6 +1110,7 @@ describe.each([
const createViewResponse = await config.api.viewV2.create({ const createViewResponse = await config.api.viewV2.create({
tableId: table._id!, tableId: table._id!,
name: generator.guid(),
query: [ query: [
{ operator: SearchQueryOperators.EQUAL, field: "age", value: 40 }, { operator: SearchQueryOperators.EQUAL, field: "age", value: 40 },
], ],
@ -1279,6 +1235,7 @@ describe.each([
async (sortParams, expected) => { async (sortParams, expected) => {
const createViewResponse = await config.api.viewV2.create({ const createViewResponse = await config.api.viewV2.create({
tableId: table._id!, tableId: table._id!,
name: generator.guid(),
sort: sortParams, sort: sortParams,
schema: viewSchema, schema: viewSchema,
}) })
@ -1299,6 +1256,7 @@ describe.each([
async (sortParams, expected) => { async (sortParams, expected) => {
const createViewResponse = await config.api.viewV2.create({ const createViewResponse = await config.api.viewV2.create({
tableId: table._id!, tableId: table._id!,
name: generator.guid(),
sort: { sort: {
field: "name", field: "name",
order: SortOrder.ASCENDING, order: SortOrder.ASCENDING,
@ -1339,6 +1297,7 @@ describe.each([
const view = await config.api.viewV2.create({ const view = await config.api.viewV2.create({
tableId: table._id!, tableId: table._id!,
name: generator.guid(),
schema: { name: { visible: true } }, schema: { name: { visible: true } },
}) })
const response = await config.api.viewV2.search(view.id) const response = await config.api.viewV2.search(view.id)
@ -1361,6 +1320,7 @@ describe.each([
const table = await config.api.table.save(await userTable()) const table = await config.api.table.save(await userTable())
const createViewResponse = await config.api.viewV2.create({ const createViewResponse = await config.api.viewV2.create({
tableId: table._id!, tableId: table._id!,
name: generator.guid(),
}) })
const response = await config.api.viewV2.search(createViewResponse.id) const response = await config.api.viewV2.search(createViewResponse.id)
expect(response.rows).toHaveLength(0) expect(response.rows).toHaveLength(0)
@ -1376,6 +1336,7 @@ describe.each([
const createViewResponse = await config.api.viewV2.create({ const createViewResponse = await config.api.viewV2.create({
tableId: table._id!, tableId: table._id!,
name: generator.guid(),
}) })
const response = await config.api.viewV2.search(createViewResponse.id, { const response = await config.api.viewV2.search(createViewResponse.id, {
limit, limit,
@ -1392,6 +1353,7 @@ describe.each([
) )
const view = await config.api.viewV2.create({ const view = await config.api.viewV2.create({
tableId: table._id!, tableId: table._id!,
name: generator.guid(),
}) })
const rows = (await config.api.viewV2.search(view.id)).rows const rows = (await config.api.viewV2.search(view.id)).rows
@ -1466,6 +1428,7 @@ describe.each([
view = await config.api.viewV2.create({ view = await config.api.viewV2.create({
tableId: table._id!, tableId: table._id!,
name: generator.guid(),
}) })
}) })

View file

@ -20,7 +20,7 @@ import sdk from "../../../sdk"
import * as uuid from "uuid" import * as uuid from "uuid"
import tk from "timekeeper" import tk from "timekeeper"
import { mocks } from "@budibase/backend-core/tests" import { generator, mocks } from "@budibase/backend-core/tests"
import { TableToBuild } from "../../../tests/utilities/TestConfiguration" import { TableToBuild } from "../../../tests/utilities/TestConfiguration"
tk.freeze(mocks.date.MOCK_DATE) tk.freeze(mocks.date.MOCK_DATE)
@ -417,8 +417,8 @@ describe("/tables", () => {
it("should fetch views", async () => { it("should fetch views", async () => {
const tableId = config.table!._id! const tableId = config.table!._id!
const views = [ const views = [
await config.api.viewV2.create({ tableId }), await config.api.viewV2.create({ tableId, name: generator.guid() }),
await config.api.viewV2.create({ tableId }), await config.api.viewV2.create({ tableId, name: generator.guid() }),
] ]
const res = await request const res = await request
@ -455,7 +455,7 @@ describe("/tables", () => {
}, },
})) }))
await config.api.viewV2.create({ tableId }) await config.api.viewV2.create({ tableId, name: generator.guid() })
await config.createLegacyView() await config.createLegacyView()
const res = await config.api.table.fetch() const res = await config.api.table.fetch()

View file

@ -3,12 +3,15 @@ import * as setup from "./utilities"
import { import {
FieldType, FieldType,
INTERNAL_TABLE_SOURCE_ID, INTERNAL_TABLE_SOURCE_ID,
QuotaUsageType,
SaveTableRequest, SaveTableRequest,
StaticQuotaName,
Table, Table,
TableSourceType, TableSourceType,
View, View,
ViewCalculation, ViewCalculation,
} from "@budibase/types" } from "@budibase/types"
import { quotas } from "@budibase/pro"
const priceTable: SaveTableRequest = { const priceTable: SaveTableRequest = {
name: "table", name: "table",
@ -57,6 +60,18 @@ describe("/views", () => {
return config.api.legacyView.save(viewToSave) return config.api.legacyView.save(viewToSave)
} }
const getRowUsage = async () => {
const { total } = await config.doInContext(undefined, () =>
quotas.getCurrentUsageValues(QuotaUsageType.STATIC, StaticQuotaName.ROWS)
)
return total
}
const assertRowUsage = async (expected: number) => {
const usage = await getRowUsage()
expect(usage).toBe(expected)
}
describe("create", () => { describe("create", () => {
it("returns a success message when the view is successfully created", async () => { it("returns a success message when the view is successfully created", async () => {
const res = await saveView() const res = await saveView()
@ -265,6 +280,41 @@ describe("/views", () => {
expect(views.length).toBe(1) expect(views.length).toBe(1)
expect(views.find(({ name }) => name === "TestView")).toBeDefined() expect(views.find(({ name }) => name === "TestView")).toBeDefined()
}) })
it("should be able to fetch tables contents via 'view'", async () => {
const row = await config.api.row.save(table._id!, {})
const rowUsage = await getRowUsage()
const rows = await config.api.legacyView.get(table._id!)
expect(rows.length).toEqual(1)
expect(rows[0]._id).toEqual(row._id)
await assertRowUsage(rowUsage)
})
it("should throw an error if view doesn't exist", async () => {
const rowUsage = await getRowUsage()
await config.api.legacyView.get("derp", undefined, { status: 404 })
await assertRowUsage(rowUsage)
})
it("should be able to run on a view", async () => {
const view = await config.api.legacyView.save({
tableId: table._id!,
name: "ViewTest",
filters: [],
schema: {},
})
const row = await config.api.row.save(table._id!, {})
const rowUsage = await getRowUsage()
const rows = await config.api.legacyView.get(view.name!)
expect(rows.length).toEqual(1)
expect(rows[0]._id).toEqual(row._id)
await assertRowUsage(rowUsage)
})
}) })
describe("query", () => { describe("query", () => {

View file

@ -1,9 +1,11 @@
import * as setup from "./utilities" import * as setup from "./utilities"
import { import {
CreateViewRequest, CreateViewRequest,
Datasource,
FieldSchema, FieldSchema,
FieldType, FieldType,
INTERNAL_TABLE_SOURCE_ID, INTERNAL_TABLE_SOURCE_ID,
SaveTableRequest,
SearchQueryOperators, SearchQueryOperators,
SortOrder, SortOrder,
SortType, SortType,
@ -14,14 +16,54 @@ import {
ViewV2, ViewV2,
} from "@budibase/types" } from "@budibase/types"
import { generator } from "@budibase/backend-core/tests" import { generator } from "@budibase/backend-core/tests"
import { generateDatasourceID } from "../../../db/utils" import * as uuid from "uuid"
import { databaseTestProviders } from "../../../integrations/tests/utils"
import merge from "lodash/merge"
function priceTable(): Table { jest.unmock("mysql2")
return { jest.unmock("mysql2/promise")
name: "table", jest.unmock("mssql")
jest.unmock("pg")
describe.each([
["internal", undefined],
["postgres", databaseTestProviders.postgres],
["mysql", databaseTestProviders.mysql],
["mssql", databaseTestProviders.mssql],
["mariadb", databaseTestProviders.mariadb],
])("/v2/views (%s)", (_, dsProvider) => {
const config = setup.getConfig()
let table: Table
let datasource: Datasource
function saveTableRequest(
...overrides: Partial<SaveTableRequest>[]
): SaveTableRequest {
const req: SaveTableRequest = {
name: uuid.v4().substring(0, 16),
type: "table", type: "table",
sourceId: INTERNAL_TABLE_SOURCE_ID, sourceType: datasource
sourceType: TableSourceType.INTERNAL, ? TableSourceType.EXTERNAL
: TableSourceType.INTERNAL,
sourceId: datasource ? datasource._id! : INTERNAL_TABLE_SOURCE_ID,
primary: ["id"],
schema: {
id: {
type: FieldType.AUTO,
name: "id",
autocolumn: true,
constraints: {
presence: true,
},
},
},
}
return merge(req, ...overrides)
}
function priceTable(): SaveTableRequest {
return saveTableRequest({
schema: { schema: {
Price: { Price: {
type: FieldType.NUMBER, type: FieldType.NUMBER,
@ -36,44 +78,27 @@ function priceTable(): Table {
}, },
}, },
}, },
})
} }
}
const config = setup.getConfig()
beforeAll(async () => { beforeAll(async () => {
await config.init() await config.init()
if (dsProvider) {
datasource = await config.createDatasource({
datasource: await dsProvider.datasource(),
})
}
table = await config.api.table.save(priceTable())
}) })
describe.each([ afterAll(async () => {
["internal ds", () => config.createTable(priceTable())], if (dsProvider) {
[ await dsProvider.stop()
"external ds", }
async () => { setup.afterAll()
const datasource = await config.createDatasource({
datasource: {
...setup.structures.basicDatasource().datasource,
plus: true,
_id: generateDatasourceID({ plus: true }),
},
}) })
return config.createExternalTable({
...priceTable(),
sourceId: datasource._id,
sourceType: TableSourceType.EXTERNAL,
})
},
],
])("/v2/views (%s)", (_, tableBuilder) => {
let table: Table
beforeAll(async () => {
table = await tableBuilder()
})
afterAll(setup.afterAll)
describe("create", () => { describe("create", () => {
it("persist the view when the view is successfully created", async () => { it("persist the view when the view is successfully created", async () => {
const newView: CreateViewRequest = { const newView: CreateViewRequest = {
@ -186,9 +211,12 @@ describe.each([
let view: ViewV2 let view: ViewV2
beforeEach(async () => { beforeEach(async () => {
table = await tableBuilder() table = await config.api.table.save(priceTable())
view = await config.api.viewV2.create({ name: "View A" }) view = await config.api.viewV2.create({
tableId: table._id!,
name: "View A",
})
}) })
it("can update an existing view data", async () => { it("can update an existing view data", async () => {
@ -247,6 +275,9 @@ describe.each([
...updatedData, ...updatedData,
schema: { schema: {
...table.schema, ...table.schema,
id: expect.objectContaining({
visible: false,
}),
Category: expect.objectContaining({ Category: expect.objectContaining({
visible: false, visible: false,
}), }),
@ -320,23 +351,27 @@ describe.each([
}) })
it("cannot update views v1", async () => { it("cannot update views v1", async () => {
const viewV1 = await config.createLegacyView() const viewV1 = await config.api.legacyView.save({
await config.api.viewV2.update( tableId: table._id!,
{ name: generator.guid(),
...viewV1, filters: [],
}, schema: {},
{ })
await config.api.viewV2.update(viewV1 as unknown as ViewV2, {
status: 400, status: 400,
body: { body: {
message: "Only views V2 can be updated", message: "Only views V2 can be updated",
status: 400, status: 400,
}, },
} })
)
}) })
it("cannot update the a view with unmatching ids between url and body", async () => { it("cannot update the a view with unmatching ids between url and body", async () => {
const anotherView = await config.api.viewV2.create() const anotherView = await config.api.viewV2.create({
tableId: table._id!,
name: generator.guid(),
})
const result = await config const result = await config
.request!.put(`/api/v2/views/${anotherView.id}`) .request!.put(`/api/v2/views/${anotherView.id}`)
.send(view) .send(view)
@ -411,7 +446,10 @@ describe.each([
let view: ViewV2 let view: ViewV2
beforeAll(async () => { beforeAll(async () => {
view = await config.api.viewV2.create() view = await config.api.viewV2.create({
tableId: table._id!,
name: generator.guid(),
})
}) })
it("can delete an existing view", async () => { it("can delete an existing view", async () => {
@ -448,4 +486,43 @@ describe.each([
expect(viewSchema.Price?.visible).toEqual(false) expect(viewSchema.Price?.visible).toEqual(false)
}) })
}) })
describe("read", () => {
it("views have extra data trimmed", async () => {
const table = await config.api.table.save(
saveTableRequest({
name: "orders",
schema: {
Country: {
type: FieldType.STRING,
name: "Country",
},
Story: {
type: FieldType.STRING,
name: "Story",
},
},
})
)
const view = await config.api.viewV2.create({
tableId: table._id!,
name: uuid.v4(),
schema: {
Country: {
visible: true,
},
},
})
let row = await config.api.row.save(view.id, {
Country: "Aussy",
Story: "aaaaa",
})
row = await config.api.row.get(table._id!, row._id!)
expect(row.Story).toBeUndefined()
expect(row.Country).toEqual("Aussy")
})
})
}) })

View file

@ -1,21 +0,0 @@
import * as search from "../../app/rows/search"
describe("removeEmptyFilters", () => {
it("0 should not be removed", () => {
const filters = search.removeEmptyFilters({
equal: {
column: 0,
},
})
expect((filters.equal as any).column).toBe(0)
})
it("empty string should be removed", () => {
const filters = search.removeEmptyFilters({
equal: {
column: "",
},
})
expect(Object.values(filters.equal as any).length).toBe(0)
})
})

View file

@ -11,21 +11,9 @@ import sdk from "../../../sdk"
export class ViewV2API extends TestAPI { export class ViewV2API extends TestAPI {
create = async ( create = async (
viewData?: Partial<CreateViewRequest>, view: CreateViewRequest,
expectations?: Expectations expectations?: Expectations
): Promise<ViewV2> => { ): Promise<ViewV2> => {
let tableId = viewData?.tableId
if (!tableId && !this.config.table) {
throw "Test requires table to be configured."
}
tableId = tableId || this.config.table!._id!
const view = {
tableId,
name: generator.guid(),
...viewData,
}
const exp: Expectations = { const exp: Expectations = {
status: 201, status: 201,
...expectations, ...expectations,