Budibase is an open-source low-code platform for creating internal apps in minutes. Supports PostgreSQL, MySQL, MSSQL, MongoDB, Rest API, Docker, K8s 🚀
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
1.9 KiB

import {
setupApphierarchy,
basicAppHierarchyCreator_WithFields,
stubEventHandler,
} from "./specHelpers"
import { canDeleteIndex } from "../src/templateApi/canDeleteIndex"
import { canDeleteRecord } from "../src/templateApi/canDeleteRecord"
describe("canDeleteIndex", () => {
it("should return no errors if deltion is valid", async () => {
const { appHierarchy } = await setupApphierarchy(
basicAppHierarchyCreator_WithFields
)
const partnerIndex = appHierarchy.root.indexes.find(i => i.name === "partner_index")
const result = canDeleteIndex(partnerIndex)
expect(result.canDelete).toBe(true)
expect(result.errors).toEqual([])
})
it("should return errors if index is a lookup for a reference field", async () => {
const { appHierarchy } = await setupApphierarchy(
basicAppHierarchyCreator_WithFields
)
const customerIndex = appHierarchy.root.indexes.find(i => i.name === "customer_index")
const result = canDeleteIndex(customerIndex)
expect(result.canDelete).toBe(false)
expect(result.errors.length).toBe(1)
})
it("should return errors if index is a manyToOne index for a reference field", async () => {
const { appHierarchy } = await setupApphierarchy(
basicAppHierarchyCreator_WithFields
)
const referredToCustomersIndex = appHierarchy.customerRecord.indexes.find(i => i.name === "referredToCustomers")
const result = canDeleteIndex(referredToCustomersIndex)
expect(result.canDelete).toBe(false)
expect(result.errors.length).toBe(1)
})
})
describe("canDeleteRecord", () => {
it("should return no errors when deletion is valid", () => {
const { appHierarchy } = await setupApphierarchy(
basicAppHierarchyCreator_WithFields
)
appHierarchy.root.
const result = canDeleteIndex(appHierarchy.customerRecord)
expect(result.canDelete).toBe(true)
expect(result.errors).toEqual([])
})
})