budibase/packages/core/test/upgradeDataSetup.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-03-24 11:56:48 +01:00
import { getMemoryTemplateApi, appFromTempalteApi } from "./specHelpers"
import { getFlattenedHierarchy } from "../src/templateApi/hierarchy"
import { initialiseData } from "../src/appInitialise/initialiseData"
2020-03-27 17:58:32 +01:00
export const setup = async store => {
2020-03-24 11:56:48 +01:00
const { templateApi } = await getMemoryTemplateApi(store)
const root = templateApi.getNewRootLevel()
const contact = templateApi.getNewRecordTemplate(root, "contact", true)
contact.collectionName = "contacts"
const nameField = templateApi.getNewField("string")
nameField.name = "name"
const statusField = templateApi.getNewField("string")
statusField.name = "status"
templateApi.addField(contact, nameField)
templateApi.addField(contact, statusField)
const lead = templateApi.getNewRecordTemplate(root, "lead", true)
lead.collectionName = "leads"
const deal = templateApi.getNewRecordTemplate(contact, "deal", true)
deal.collectionName = "deals"
2020-03-27 17:58:32 +01:00
templateApi.addField(deal, { ...nameField })
templateApi.addField(deal, { ...statusField })
2020-03-24 11:56:48 +01:00
2020-03-27 17:58:32 +01:00
templateApi.addField(lead, { ...nameField })
2020-03-24 11:56:48 +01:00
getFlattenedHierarchy(root)
if (!store)
await initialiseData(templateApi._storeHandle, {
hierarchy: root,
actions: [],
triggers: [],
})
const app = await appFromTempalteApi(templateApi)
app.hierarchy = root
return {
2020-03-27 17:58:32 +01:00
root,
contact,
lead,
app,
deal,
templateApi,
store: templateApi._storeHandle,
2020-03-24 11:56:48 +01:00
all_contacts: root.indexes[0],
all_leads: root.indexes[1],
deals_for_contacts: contact.indexes[0],
}
2020-03-27 17:58:32 +01:00
}