Merge pull request #15687 from Budibase/migrate-js-to-ts-2
Migrate misc.spec.ts to TS.
This commit is contained in:
commit
526847d8d9
|
@ -1,11 +1,13 @@
|
||||||
const setup = require("./utilities")
|
import { handleDataImport } from "../../controllers/table/utils"
|
||||||
const tableUtils = require("../../controllers/table/utils")
|
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
|
import { AutoFieldSubType, FieldType, JsonFieldSubType } from "@budibase/types"
|
||||||
|
|
||||||
describe("run misc tests", () => {
|
describe("run misc tests", () => {
|
||||||
let request = setup.getRequest()
|
const config = new TestConfiguration()
|
||||||
let config = setup.getConfig()
|
|
||||||
|
|
||||||
afterAll(setup.afterAll)
|
afterAll(() => {
|
||||||
|
config.end()
|
||||||
|
})
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await config.init()
|
await config.init()
|
||||||
|
@ -13,69 +15,67 @@ describe("run misc tests", () => {
|
||||||
|
|
||||||
describe("/bbtel", () => {
|
describe("/bbtel", () => {
|
||||||
it("check if analytics enabled", async () => {
|
it("check if analytics enabled", async () => {
|
||||||
const res = await request
|
const { enabled } = await config.api.misc.bbtel()
|
||||||
.get(`/api/bbtel`)
|
expect(enabled).toEqual(true)
|
||||||
.set(config.defaultHeaders())
|
|
||||||
.expect("Content-Type", /json/)
|
|
||||||
.expect(200)
|
|
||||||
expect(typeof res.body.enabled).toEqual("boolean")
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("/health", () => {
|
describe("/health", () => {
|
||||||
it("should confirm healthy", async () => {
|
it("should confirm healthy", async () => {
|
||||||
await request.get("/health").expect(200)
|
await config.api.misc.health()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("/version", () => {
|
describe("/version", () => {
|
||||||
it("should confirm version", async () => {
|
it("should confirm version", async () => {
|
||||||
const res = await request.get("/version").expect(200)
|
const version = await config.api.misc.version()
|
||||||
const text = res.text
|
if (version.includes("alpha")) {
|
||||||
if (text.includes("alpha")) {
|
expect(version.split(".").length).toEqual(4)
|
||||||
expect(text.split(".").length).toEqual(4)
|
|
||||||
} else {
|
} else {
|
||||||
expect(text.split(".").length).toEqual(3)
|
expect(version.split(".").length).toEqual(3)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("test table utilities", () => {
|
describe("test table utilities", () => {
|
||||||
it("should be able to import data", async () => {
|
it("should be able to import data", async () => {
|
||||||
return config.doInContext(null, async () => {
|
return config.doInContext("", async () => {
|
||||||
const table = await config.createTable({
|
const table = await config.createTable({
|
||||||
name: "table",
|
name: "table",
|
||||||
type: "table",
|
type: "table",
|
||||||
key: "name",
|
|
||||||
schema: {
|
schema: {
|
||||||
a: {
|
a: {
|
||||||
type: "string",
|
type: FieldType.STRING,
|
||||||
|
name: "a",
|
||||||
constraints: {
|
constraints: {
|
||||||
type: "string",
|
type: "string",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
b: {
|
b: {
|
||||||
type: "string",
|
name: "b",
|
||||||
|
type: FieldType.STRING,
|
||||||
constraints: {
|
constraints: {
|
||||||
type: "string",
|
type: "string",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
c: {
|
c: {
|
||||||
type: "string",
|
name: "c",
|
||||||
|
type: FieldType.STRING,
|
||||||
constraints: {
|
constraints: {
|
||||||
type: "string",
|
type: "string",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
d: {
|
d: {
|
||||||
type: "string",
|
name: "d",
|
||||||
|
type: FieldType.STRING,
|
||||||
constraints: {
|
constraints: {
|
||||||
type: "string",
|
type: "string",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
e: {
|
e: {
|
||||||
name: "Auto ID",
|
name: "Auto ID",
|
||||||
type: "number",
|
type: FieldType.NUMBER,
|
||||||
subtype: "autoID",
|
subtype: AutoFieldSubType.AUTO_ID,
|
||||||
icon: "ri-magic-line",
|
icon: "ri-magic-line",
|
||||||
autocolumn: true,
|
autocolumn: true,
|
||||||
constraints: {
|
constraints: {
|
||||||
|
@ -88,9 +88,9 @@ describe("run misc tests", () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
f: {
|
f: {
|
||||||
type: "array",
|
type: FieldType.ARRAY,
|
||||||
constraints: {
|
constraints: {
|
||||||
type: "array",
|
type: JsonFieldSubType.ARRAY,
|
||||||
presence: {
|
presence: {
|
||||||
allowEmpty: true,
|
allowEmpty: true,
|
||||||
},
|
},
|
||||||
|
@ -100,7 +100,7 @@ describe("run misc tests", () => {
|
||||||
sortable: false,
|
sortable: false,
|
||||||
},
|
},
|
||||||
g: {
|
g: {
|
||||||
type: "options",
|
type: FieldType.OPTIONS,
|
||||||
constraints: {
|
constraints: {
|
||||||
type: "string",
|
type: "string",
|
||||||
presence: false,
|
presence: false,
|
||||||
|
@ -118,16 +118,18 @@ describe("run misc tests", () => {
|
||||||
{ a: "13", b: "14", c: "15", d: "16", g: "Omega" },
|
{ a: "13", b: "14", c: "15", d: "16", g: "Omega" },
|
||||||
]
|
]
|
||||||
// Shift specific row tests to the row spec
|
// Shift specific row tests to the row spec
|
||||||
await tableUtils.handleDataImport(table, {
|
await handleDataImport(table, { importRows, userId: "test" })
|
||||||
importRows,
|
|
||||||
user: { userId: "test" },
|
|
||||||
})
|
|
||||||
|
|
||||||
// 4 rows imported, the auto ID starts at 1
|
// 4 rows imported, the auto ID starts at 1
|
||||||
// We expect the handleDataImport function to update the lastID
|
// We expect the handleDataImport function to update the lastID
|
||||||
|
|
||||||
|
// @ts-expect-error - fields have type FieldSchema, not specific
|
||||||
|
// subtypes.
|
||||||
expect(table.schema.e.lastID).toEqual(4)
|
expect(table.schema.e.lastID).toEqual(4)
|
||||||
|
|
||||||
// Array/Multi - should have added a new value to the inclusion.
|
// Array/Multi - should have added a new value to the inclusion.
|
||||||
|
// @ts-expect-error - fields have type FieldSchema, not specific
|
||||||
|
// subtypes.
|
||||||
expect(table.schema.f.constraints.inclusion).toEqual([
|
expect(table.schema.f.constraints.inclusion).toEqual([
|
||||||
"Four",
|
"Four",
|
||||||
"One",
|
"One",
|
||||||
|
@ -136,6 +138,8 @@ describe("run misc tests", () => {
|
||||||
])
|
])
|
||||||
|
|
||||||
// Options - should have a new value in the inclusion
|
// Options - should have a new value in the inclusion
|
||||||
|
// @ts-expect-error - fields have type FieldSchema, not specific
|
||||||
|
// subtypes.
|
||||||
expect(table.schema.g.constraints.inclusion).toEqual([
|
expect(table.schema.g.constraints.inclusion).toEqual([
|
||||||
"Alpha",
|
"Alpha",
|
||||||
"Beta",
|
"Beta",
|
||||||
|
@ -143,25 +147,25 @@ describe("run misc tests", () => {
|
||||||
"Omega",
|
"Omega",
|
||||||
])
|
])
|
||||||
|
|
||||||
const rows = await config.getRows()
|
const rows = await config.api.row.fetch(table._id!)
|
||||||
expect(rows.length).toEqual(4)
|
expect(rows.length).toEqual(4)
|
||||||
|
|
||||||
const rowOne = rows.find(row => row.e === 1)
|
const rowOne = rows.find(row => row.e === 1)!
|
||||||
expect(rowOne.a).toEqual("1")
|
expect(rowOne.a).toEqual("1")
|
||||||
expect(rowOne.f).toEqual(["One"])
|
expect(rowOne.f).toEqual(["One"])
|
||||||
expect(rowOne.g).toEqual("Alpha")
|
expect(rowOne.g).toEqual("Alpha")
|
||||||
|
|
||||||
const rowTwo = rows.find(row => row.e === 2)
|
const rowTwo = rows.find(row => row.e === 2)!
|
||||||
expect(rowTwo.a).toEqual("5")
|
expect(rowTwo.a).toEqual("5")
|
||||||
expect(rowTwo.f).toEqual([])
|
expect(rowTwo.f).toEqual([])
|
||||||
expect(rowTwo.g).toEqual(undefined)
|
expect(rowTwo.g).toEqual(undefined)
|
||||||
|
|
||||||
const rowThree = rows.find(row => row.e === 3)
|
const rowThree = rows.find(row => row.e === 3)!
|
||||||
expect(rowThree.a).toEqual("9")
|
expect(rowThree.a).toEqual("9")
|
||||||
expect(rowThree.f).toEqual(["Two", "Four"])
|
expect(rowThree.f).toEqual(["Two", "Four"])
|
||||||
expect(rowThree.g).toEqual(undefined)
|
expect(rowThree.g).toEqual(undefined)
|
||||||
|
|
||||||
const rowFour = rows.find(row => row.e === 4)
|
const rowFour = rows.find(row => row.e === 4)!
|
||||||
expect(rowFour.a).toEqual("13")
|
expect(rowFour.a).toEqual("13")
|
||||||
expect(rowFour.f).toEqual(undefined)
|
expect(rowFour.f).toEqual(undefined)
|
||||||
expect(rowFour.g).toEqual("Omega")
|
expect(rowFour.g).toEqual("Omega")
|
|
@ -19,6 +19,7 @@ import { PluginAPI } from "./plugin"
|
||||||
import { WebhookAPI } from "./webhook"
|
import { WebhookAPI } from "./webhook"
|
||||||
import { EnvironmentAPI } from "./environment"
|
import { EnvironmentAPI } from "./environment"
|
||||||
import { UserPublicAPI } from "./public/user"
|
import { UserPublicAPI } from "./public/user"
|
||||||
|
import { MiscAPI } from "./misc"
|
||||||
|
|
||||||
export default class API {
|
export default class API {
|
||||||
application: ApplicationAPI
|
application: ApplicationAPI
|
||||||
|
@ -28,6 +29,7 @@ export default class API {
|
||||||
datasource: DatasourceAPI
|
datasource: DatasourceAPI
|
||||||
environment: EnvironmentAPI
|
environment: EnvironmentAPI
|
||||||
legacyView: LegacyViewAPI
|
legacyView: LegacyViewAPI
|
||||||
|
misc: MiscAPI
|
||||||
permission: PermissionAPI
|
permission: PermissionAPI
|
||||||
plugin: PluginAPI
|
plugin: PluginAPI
|
||||||
query: QueryAPI
|
query: QueryAPI
|
||||||
|
@ -53,6 +55,7 @@ export default class API {
|
||||||
this.datasource = new DatasourceAPI(config)
|
this.datasource = new DatasourceAPI(config)
|
||||||
this.environment = new EnvironmentAPI(config)
|
this.environment = new EnvironmentAPI(config)
|
||||||
this.legacyView = new LegacyViewAPI(config)
|
this.legacyView = new LegacyViewAPI(config)
|
||||||
|
this.misc = new MiscAPI(config)
|
||||||
this.permission = new PermissionAPI(config)
|
this.permission = new PermissionAPI(config)
|
||||||
this.plugin = new PluginAPI(config)
|
this.plugin = new PluginAPI(config)
|
||||||
this.query = new QueryAPI(config)
|
this.query = new QueryAPI(config)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { AnalyticsEnabledResponse } from "@budibase/types"
|
||||||
|
import { Expectations, TestAPI } from "./base"
|
||||||
|
|
||||||
|
export class MiscAPI extends TestAPI {
|
||||||
|
health = async (expectations?: Expectations) => {
|
||||||
|
return await this._get<void>("/health", { expectations })
|
||||||
|
}
|
||||||
|
|
||||||
|
version = async (expectations?: Expectations) => {
|
||||||
|
return (await this._requestRaw("get", "/version", { expectations })).text
|
||||||
|
}
|
||||||
|
|
||||||
|
bbtel = async (expectations?: Expectations) => {
|
||||||
|
return await this._get<AnalyticsEnabledResponse>("/api/bbtel", {
|
||||||
|
expectations,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue