2021-03-11 00:47:39 +13:00
|
|
|
const setup = require("./utilities")
|
2021-03-16 05:36:38 +13:00
|
|
|
const tableUtils = require("../../controllers/table/utils")
|
2021-03-11 00:47:39 +13:00
|
|
|
|
2021-03-16 05:36:38 +13:00
|
|
|
describe("run misc tests", () => {
|
2021-03-11 00:47:39 +13:00
|
|
|
let request = setup.getRequest()
|
|
|
|
let config = setup.getConfig()
|
|
|
|
|
|
|
|
afterAll(setup.afterAll)
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
await config.init()
|
|
|
|
})
|
|
|
|
|
2022-03-21 23:04:26 +13:00
|
|
|
describe("/bbtel", () => {
|
2021-03-16 05:36:38 +13:00
|
|
|
it("check if analytics enabled", async () => {
|
|
|
|
const res = await request
|
2022-03-21 23:04:26 +13:00
|
|
|
.get(`/api/bbtel`)
|
2021-03-16 05:36:38 +13:00
|
|
|
.set(config.defaultHeaders())
|
|
|
|
.expect("Content-Type", /json/)
|
|
|
|
.expect(200)
|
|
|
|
expect(typeof res.body.enabled).toEqual("boolean")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("/health", () => {
|
|
|
|
it("should confirm healthy", async () => {
|
|
|
|
await request.get("/health").expect(200)
|
2021-03-11 00:47:39 +13:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-03-16 05:36:38 +13:00
|
|
|
describe("/version", () => {
|
|
|
|
it("should confirm version", async () => {
|
|
|
|
const res = await request.get("/version").expect(200)
|
2021-07-23 22:38:17 +12:00
|
|
|
const text = res.text
|
|
|
|
if (text.includes("alpha")) {
|
|
|
|
expect(text.split(".").length).toEqual(4)
|
|
|
|
} else {
|
|
|
|
expect(text.split(".").length).toEqual(3)
|
|
|
|
}
|
|
|
|
|
2021-03-16 05:36:38 +13:00
|
|
|
})
|
2021-03-11 00:47:39 +13:00
|
|
|
})
|
|
|
|
|
2021-03-16 05:36:38 +13:00
|
|
|
describe("test table utilities", () => {
|
|
|
|
it("should be able to import a CSV", async () => {
|
2022-04-27 02:50:35 +12:00
|
|
|
return config.doInContext(null, async () => {
|
|
|
|
const table = await config.createTable({
|
|
|
|
name: "table",
|
|
|
|
type: "table",
|
|
|
|
key: "name",
|
|
|
|
schema: {
|
|
|
|
a: {
|
2021-06-08 01:08:49 +12:00
|
|
|
type: "string",
|
2022-04-27 02:50:35 +12:00
|
|
|
constraints: {
|
|
|
|
type: "string",
|
|
|
|
},
|
2021-06-08 01:08:49 +12:00
|
|
|
},
|
2022-04-27 02:50:35 +12:00
|
|
|
b: {
|
2021-06-08 01:08:49 +12:00
|
|
|
type: "string",
|
2022-04-27 02:50:35 +12:00
|
|
|
constraints: {
|
|
|
|
type: "string",
|
|
|
|
},
|
2021-06-08 01:08:49 +12:00
|
|
|
},
|
2022-04-27 02:50:35 +12:00
|
|
|
c: {
|
2021-06-08 01:08:49 +12:00
|
|
|
type: "string",
|
2022-04-27 02:50:35 +12:00
|
|
|
constraints: {
|
|
|
|
type: "string",
|
|
|
|
},
|
2021-06-08 01:08:49 +12:00
|
|
|
},
|
2022-04-27 02:50:35 +12:00
|
|
|
d: {
|
2021-06-08 01:08:49 +12:00
|
|
|
type: "string",
|
2022-04-27 02:50:35 +12:00
|
|
|
constraints: {
|
|
|
|
type: "string",
|
|
|
|
},
|
2021-06-08 01:08:49 +12:00
|
|
|
},
|
|
|
|
},
|
2022-04-27 02:50:35 +12:00
|
|
|
})
|
|
|
|
const dataImport = {
|
|
|
|
csvString: "a,b,c,d\n1,2,3,4",
|
|
|
|
schema: {},
|
|
|
|
}
|
|
|
|
for (let col of ["a", "b", "c", "d"]) {
|
|
|
|
dataImport.schema[col] = { type: "string" }
|
|
|
|
}
|
|
|
|
await tableUtils.handleDataImport(
|
|
|
|
{ userId: "test" },
|
|
|
|
table,
|
|
|
|
dataImport
|
|
|
|
)
|
|
|
|
const rows = await config.getRows()
|
|
|
|
expect(rows[0].a).toEqual("1")
|
|
|
|
expect(rows[0].b).toEqual("2")
|
|
|
|
expect(rows[0].c).toEqual("3")
|
2021-06-08 01:08:49 +12:00
|
|
|
})
|
2021-03-16 05:36:38 +13:00
|
|
|
})
|
2021-03-11 00:47:39 +13:00
|
|
|
})
|
|
|
|
})
|