forked from tsai/budibase
27 changed files with 306 additions and 57 deletions
@ -1,15 +0,0 @@ |
|||||
module.exports = { |
|
||||
table: require("../../../controllers/table"), |
|
||||
row: require("../../../controllers/row"), |
|
||||
role: require("../../../controllers/role"), |
|
||||
perms: require("../../../controllers/permission"), |
|
||||
view: require("../../../controllers/view"), |
|
||||
app: require("../../../controllers/application"), |
|
||||
user: require("../../../controllers/user"), |
|
||||
automation: require("../../../controllers/automation"), |
|
||||
datasource: require("../../../controllers/datasource"), |
|
||||
query: require("../../../controllers/query"), |
|
||||
screen: require("../../../controllers/screen"), |
|
||||
webhook: require("../../../controllers/webhook"), |
|
||||
layout: require("../../../controllers/layout"), |
|
||||
} |
|
||||
@ -0,0 +1,57 @@ |
|||||
|
const usageQuota = require("../../utilities/usageQuota") |
||||
|
const env = require("../../environment") |
||||
|
const setup = require("./utilities") |
||||
|
|
||||
|
jest.mock("../../utilities/usageQuota") |
||||
|
|
||||
|
describe("test the create row action", () => { |
||||
|
let table, row |
||||
|
let config = setup.getConfig() |
||||
|
|
||||
|
beforeEach(async () => { |
||||
|
await config.init() |
||||
|
table = await config.createTable() |
||||
|
row = { |
||||
|
tableId: table._id, |
||||
|
name: "test", |
||||
|
description: "test", |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
afterAll(setup.afterAll) |
||||
|
|
||||
|
it("should be able to run the action", async () => { |
||||
|
const res = await setup.runStep(setup.actions.CREATE_ROW.stepId, { |
||||
|
row, |
||||
|
}) |
||||
|
expect(res.id).toBeDefined() |
||||
|
expect(res.revision).toBeDefined() |
||||
|
const gottenRow = await config.getRow(table._id, res.id) |
||||
|
expect(gottenRow.name).toEqual("test") |
||||
|
expect(gottenRow.description).toEqual("test") |
||||
|
}) |
||||
|
|
||||
|
it("should return an error (not throw) when bad info provided", async () => { |
||||
|
const res = await setup.runStep(setup.actions.CREATE_ROW.stepId, { |
||||
|
row: { |
||||
|
tableId: "invalid", |
||||
|
invalid: "invalid", |
||||
|
} |
||||
|
}) |
||||
|
expect(res.success).toEqual(false) |
||||
|
}) |
||||
|
|
||||
|
it("check usage quota attempts", async () => { |
||||
|
env.CLOUD = true |
||||
|
await setup.runStep(setup.actions.CREATE_ROW.stepId, { |
||||
|
row |
||||
|
}) |
||||
|
expect(usageQuota.update).toHaveBeenCalledWith(setup.apiKey, "rows", 1) |
||||
|
env.CLOUD = false |
||||
|
}) |
||||
|
|
||||
|
it("should check invalid inputs return an error", async () => { |
||||
|
const res = await setup.runStep(setup.actions.CREATE_ROW.stepId, {}) |
||||
|
expect(res.success).toEqual(false) |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,43 @@ |
|||||
|
const usageQuota = require("../../utilities/usageQuota") |
||||
|
const env = require("../../environment") |
||||
|
const setup = require("./utilities") |
||||
|
const { BUILTIN_ROLE_IDS } = require("../../utilities/security/roles") |
||||
|
const { ViewNames } = require("../../db/utils") |
||||
|
|
||||
|
jest.mock("../../utilities/usageQuota") |
||||
|
|
||||
|
describe("test the create user action", () => { |
||||
|
let config = setup.getConfig() |
||||
|
let user |
||||
|
|
||||
|
beforeEach(async () => { |
||||
|
await config.init() |
||||
|
user = { |
||||
|
email: "test@test.com", |
||||
|
password: "password", |
||||
|
roleId: BUILTIN_ROLE_IDS.POWER |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
afterAll(setup.afterAll) |
||||
|
|
||||
|
it("should be able to run the action", async () => { |
||||
|
const res = await setup.runStep(setup.actions.CREATE_USER.stepId, user) |
||||
|
expect(res.id).toBeDefined() |
||||
|
expect(res.revision).toBeDefined() |
||||
|
const userDoc = await config.getRow(ViewNames.USERS, res.id) |
||||
|
expect(userDoc.email).toEqual(user.email) |
||||
|
}) |
||||
|
|
||||
|
it("should return an error if no inputs provided", async () => { |
||||
|
const res = await setup.runStep(setup.actions.CREATE_USER.stepId, {}) |
||||
|
expect(res.success).toEqual(false) |
||||
|
}) |
||||
|
|
||||
|
it("check usage quota attempts", async () => { |
||||
|
env.CLOUD = true |
||||
|
await setup.runStep(setup.actions.CREATE_USER.stepId, user) |
||||
|
expect(usageQuota.update).toHaveBeenCalledWith(setup.apiKey, "users", 1) |
||||
|
env.CLOUD = false |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,12 @@ |
|||||
|
const setup = require("./utilities") |
||||
|
|
||||
|
describe("test the delay action", () => { |
||||
|
it("should be able to run the delay", async () => { |
||||
|
const time = 100 |
||||
|
const before = Date.now() |
||||
|
await setup.runStep(setup.logic.DELAY.stepId, { time: time }) |
||||
|
const now = Date.now() |
||||
|
// divide by two just so that test will always pass as long as there was some sort of delay
|
||||
|
expect(now - before).toBeGreaterThanOrEqual(time / 2) |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,48 @@ |
|||||
|
const setup = require("./utilities") |
||||
|
const { LogicConditions } = require("../steps/filter") |
||||
|
|
||||
|
describe("test the delay action", () => { |
||||
|
async function checkFilter(field, condition, value, pass = true) { |
||||
|
let res = await setup.runStep(setup.logic.FILTER.stepId, |
||||
|
{ field, condition, value } |
||||
|
) |
||||
|
expect(res.success).toEqual(pass) |
||||
|
} |
||||
|
|
||||
|
it("should be able test equality", async () => { |
||||
|
await checkFilter("hello", LogicConditions.EQUAL, "hello", true) |
||||
|
await checkFilter("hello", LogicConditions.EQUAL, "no", false) |
||||
|
}) |
||||
|
|
||||
|
it("should be able to test greater than", async () => { |
||||
|
await checkFilter(10, LogicConditions.GREATER_THAN, 5, true) |
||||
|
await checkFilter(10, LogicConditions.GREATER_THAN, 15, false) |
||||
|
}) |
||||
|
|
||||
|
it("should be able to test less than", async () => { |
||||
|
await checkFilter(5, LogicConditions.LESS_THAN, 10, true) |
||||
|
await checkFilter(15, LogicConditions.LESS_THAN, 10, false) |
||||
|
}) |
||||
|
|
||||
|
it("should be able to in-equality", async () => { |
||||
|
await checkFilter("hello", LogicConditions.NOT_EQUAL, "no", true) |
||||
|
await checkFilter(10, LogicConditions.NOT_EQUAL, 10, false) |
||||
|
}) |
||||
|
|
||||
|
it("check number coercion", async () => { |
||||
|
await checkFilter("10", LogicConditions.GREATER_THAN, "5", true) |
||||
|
}) |
||||
|
|
||||
|
it("check date coercion", async () => { |
||||
|
await checkFilter( |
||||
|
(new Date()).toISOString(), |
||||
|
LogicConditions.GREATER_THAN, |
||||
|
(new Date(-10000)).toISOString(), |
||||
|
true |
||||
|
) |
||||
|
}) |
||||
|
|
||||
|
it("check objects always false", async () => { |
||||
|
await checkFilter({}, LogicConditions.EQUAL, {}, false) |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,43 @@ |
|||||
|
const TestConfig = require("../../../tests/utilities/TestConfiguration") |
||||
|
const actions = require("../../actions") |
||||
|
const logic = require("../../logic") |
||||
|
const emitter = require("../../../events/index") |
||||
|
|
||||
|
let config |
||||
|
|
||||
|
exports.getConfig = () => { |
||||
|
if (!config) { |
||||
|
config = new TestConfig(false) |
||||
|
} |
||||
|
return config |
||||
|
} |
||||
|
|
||||
|
exports.afterAll = () => { |
||||
|
config.end() |
||||
|
} |
||||
|
|
||||
|
exports.runStep = async function runStep(stepId, inputs) { |
||||
|
let step |
||||
|
if ( |
||||
|
Object.values(exports.actions) |
||||
|
.map(action => action.stepId) |
||||
|
.includes(stepId) |
||||
|
) { |
||||
|
step = await actions.getAction(stepId) |
||||
|
} else { |
||||
|
step = logic.getLogic(stepId) |
||||
|
} |
||||
|
expect(step).toBeDefined() |
||||
|
return step({ |
||||
|
inputs, |
||||
|
appId: config ? config.getAppId() : null, |
||||
|
// don't really need an API key, mocked out usage quota, not being tested here
|
||||
|
apiKey: exports.apiKey, |
||||
|
emitter, |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
exports.apiKey = "test" |
||||
|
|
||||
|
exports.actions = actions.BUILTIN_DEFINITIONS |
||||
|
exports.logic = logic.BUILTIN_DEFINITIONS |
||||
@ -0,0 +1,26 @@ |
|||||
|
const selfhost = require("..") |
||||
|
const env = require("../../environment") |
||||
|
|
||||
|
describe("test the setup process", () => { |
||||
|
beforeAll(() => { |
||||
|
env.SELF_HOSTED = true |
||||
|
}) |
||||
|
|
||||
|
beforeEach(async () => { |
||||
|
await selfhost.init() |
||||
|
}) |
||||
|
|
||||
|
afterAll(() => { |
||||
|
env.SELF_HOSTED = false |
||||
|
}) |
||||
|
|
||||
|
it("getSelfHostInfo", async () => { |
||||
|
let info = await selfhost.getSelfHostInfo() |
||||
|
expect(info._id).toEqual("self-host-info") |
||||
|
}) |
||||
|
|
||||
|
it("getSelfHostAPIKey", async () => { |
||||
|
let apiKey = await selfhost.getSelfHostAPIKey() |
||||
|
expect(typeof apiKey).toEqual("string") |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,15 @@ |
|||||
|
module.exports = { |
||||
|
table: require("../../api/controllers/table"), |
||||
|
row: require("../../api/controllers/row"), |
||||
|
role: require("../../api/controllers/role"), |
||||
|
perms: require("../../api/controllers/permission"), |
||||
|
view: require("../../api/controllers/view"), |
||||
|
app: require("../../api/controllers/application"), |
||||
|
user: require("../../api/controllers/user"), |
||||
|
automation: require("../../api/controllers/automation"), |
||||
|
datasource: require("../../api/controllers/datasource"), |
||||
|
query: require("../../api/controllers/query"), |
||||
|
screen: require("../../api/controllers/screen"), |
||||
|
webhook: require("../../api/controllers/webhook"), |
||||
|
layout: require("../../api/controllers/layout"), |
||||
|
} |
||||
@ -1,9 +1,9 @@ |
|||||
const { BUILTIN_ROLE_IDS } = require("../../../../utilities/security/roles") |
const { BUILTIN_ROLE_IDS } = require("../../utilities/security/roles") |
||||
const { |
const { |
||||
BUILTIN_PERMISSION_IDS, |
BUILTIN_PERMISSION_IDS, |
||||
} = require("../../../../utilities/security/permissions") |
} = require("../../utilities/security/permissions") |
||||
const { createHomeScreen } = require("../../../../constants/screens") |
const { createHomeScreen } = require("../../constants/screens") |
||||
const { EMPTY_LAYOUT } = require("../../../../constants/layouts") |
const { EMPTY_LAYOUT } = require("../../constants/layouts") |
||||
const { cloneDeep } = require("lodash/fp") |
const { cloneDeep } = require("lodash/fp") |
||||
|
|
||||
exports.basicTable = () => { |
exports.basicTable = () => { |
||||
Loading…
Reference in new issue