budibase/packages/core/test/initialiseData.spec.js

87 lines
3.0 KiB
JavaScript
Raw Normal View History

import {
getMemoryTemplateApi,
basicAppHierarchyCreator_WithFields_AndIndexes,
} from "./specHelpers"
import { initialiseData } from "../src/appInitialise/initialiseData"
import { TRANSACTIONS_FOLDER } from "../src/transactions/transactionsCommon"
import {
AUTH_FOLDER,
USERS_LIST_FILE,
ACCESS_LEVELS_FILE,
} from "../src/authApi/authCommon"
2019-07-15 08:12:52 +02:00
describe("initialiseData", () => {
it("should create csv file for each index, when does not exist", async () => {
const { appDef, datastore } = getApplicationDefinition()
await initialiseData(datastore, appDef)
2019-07-15 08:12:52 +02:00
expect(await datastore.exists(`/customer_index/index.csv`)).toBeTruthy()
expect(await datastore.exists(`/customer_index`)).toBeTruthy()
expect(await datastore.exists(`/deceased/index.csv`)).toBeTruthy()
expect(await datastore.exists(`/deceased`)).toBeTruthy()
})
2019-07-15 08:12:52 +02:00
it("should create folder for collection", async () => {
const { appDef, datastore } = getApplicationDefinition()
await initialiseData(datastore, appDef)
expect(await datastore.exists(`/customers`)).toBeTruthy()
})
2019-07-15 08:12:52 +02:00
it("should create transactions folder", async () => {
const { appDef, datastore } = getApplicationDefinition()
await initialiseData(datastore, appDef)
expect(await datastore.exists(TRANSACTIONS_FOLDER)).toBeTruthy()
})
2019-07-15 08:12:52 +02:00
it("should create auth folder", async () => {
const { appDef, datastore } = getApplicationDefinition()
await initialiseData(datastore, appDef)
expect(await datastore.exists(AUTH_FOLDER)).toBeTruthy()
})
2019-07-15 08:12:52 +02:00
it("should create users list", async () => {
const { appDef, datastore } = getApplicationDefinition()
await initialiseData(datastore, appDef)
expect(await datastore.exists(USERS_LIST_FILE)).toBeTruthy()
})
2019-07-15 08:12:52 +02:00
it("should create access levels file", async () => {
const { appDef, datastore } = getApplicationDefinition()
await initialiseData(datastore, appDef)
expect(await datastore.exists(ACCESS_LEVELS_FILE)).toBeTruthy()
})
2019-07-15 08:12:52 +02:00
it("should create access levels file, with supplied object", async () => {
const { appDef, datastore } = getApplicationDefinition()
await initialiseData(datastore, appDef, {
version: 0,
levels: [
{
name: "owner",
permissions: [{ type: "create user" }],
},
],
})
const levels = await datastore.loadJson(ACCESS_LEVELS_FILE)
expect(levels.levels[0].name).toBe("owner")
})
2019-07-15 08:12:52 +02:00
it("should initialise 'single record' type nodes", async () => {
const { appDef, datastore } = getApplicationDefinition()
await initialiseData(datastore, appDef)
expect(await datastore.exists(`/settings`)).toBeTruthy()
const settings = await datastore.loadJson("/settings/record.json")
expect(settings.type).toBe("settings")
})
2019-11-03 12:26:21 +01:00
const getApplicationDefinition = () => {
2020-04-08 18:00:27 +02:00
const { templateApi, app } = await getMemoryTemplateApi()
const h = basicAppHierarchyCreator_WithFields_AndIndexes(templateApi)
return {
appDef: { hierarchy: h.root, actions: [], triggers: [] },
datastore: app.datastore,
h,
2019-07-15 08:12:52 +02:00
}
}
})