canDelete methods for index and record
This commit is contained in:
parent
f44deca6af
commit
c5ec3cfb13
|
@ -22,7 +22,6 @@ export const canDeleteRecord = recordNode => {
|
||||||
const belongsToAncestor = i =>
|
const belongsToAncestor = i =>
|
||||||
ancestors.includes(i.parent())
|
ancestors.includes(i.parent())
|
||||||
|
|
||||||
|
|
||||||
const errorsForNode = node => {
|
const errorsForNode = node => {
|
||||||
const errorsThisNode = $(flatHierarchy, [
|
const errorsThisNode = $(flatHierarchy, [
|
||||||
filter(i => isAncestorIndex(i)
|
filter(i => isAncestorIndex(i)
|
||||||
|
@ -40,5 +39,7 @@ export const canDeleteRecord = recordNode => {
|
||||||
return errorsThisNode
|
return errorsThisNode
|
||||||
}
|
}
|
||||||
|
|
||||||
return errorsForNode(recordNode)
|
const errors = errorsForNode(recordNode)
|
||||||
|
|
||||||
|
return { errors, canDelete: errors.length === 0 }
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@ import {
|
||||||
setupApphierarchy,
|
setupApphierarchy,
|
||||||
basicAppHierarchyCreator_WithFields,
|
basicAppHierarchyCreator_WithFields,
|
||||||
stubEventHandler,
|
stubEventHandler,
|
||||||
|
basicAppHierarchyCreator_WithFields_AndIndexes,
|
||||||
} from "./specHelpers"
|
} from "./specHelpers"
|
||||||
import { canDeleteIndex } from "../src/templateApi/canDeleteIndex"
|
import { canDeleteIndex } from "../src/templateApi/canDeleteIndex"
|
||||||
import { canDeleteRecord } from "../src/templateApi/canDeleteRecord"
|
import { canDeleteRecord } from "../src/templateApi/canDeleteRecord"
|
||||||
|
@ -49,15 +50,37 @@ describe("canDeleteIndex", () => {
|
||||||
|
|
||||||
|
|
||||||
describe("canDeleteRecord", () => {
|
describe("canDeleteRecord", () => {
|
||||||
it("should return no errors when deletion is valid", () => {
|
it("should return no errors when deletion is valid", async () => {
|
||||||
const { appHierarchy } = await setupApphierarchy(
|
const { appHierarchy } = await setupApphierarchy(
|
||||||
basicAppHierarchyCreator_WithFields
|
basicAppHierarchyCreator_WithFields
|
||||||
)
|
)
|
||||||
|
|
||||||
appHierarchy.root.
|
appHierarchy.root.indexes = appHierarchy.root.indexes.filter(i => !i.allowedRecordNodeIds.includes(appHierarchy.customerRecord.nodeId))
|
||||||
const result = canDeleteIndex(appHierarchy.customerRecord)
|
const result = canDeleteRecord(appHierarchy.customerRecord)
|
||||||
|
|
||||||
expect(result.canDelete).toBe(true)
|
expect(result.canDelete).toBe(true)
|
||||||
expect(result.errors).toEqual([])
|
expect(result.errors).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should return errors when record is referenced by hierarchal index", async () => {
|
||||||
|
const { appHierarchy } = await setupApphierarchy(
|
||||||
|
basicAppHierarchyCreator_WithFields
|
||||||
|
)
|
||||||
|
|
||||||
|
const result = canDeleteRecord(appHierarchy.customerRecord)
|
||||||
|
|
||||||
|
expect(result.canDelete).toBe(false)
|
||||||
|
expect(result.errors.some(e => e.includes("customer_index"))).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should return errors when record has a child which cannot be deleted", async () => {
|
||||||
|
const { appHierarchy } = await setupApphierarchy(
|
||||||
|
basicAppHierarchyCreator_WithFields_AndIndexes
|
||||||
|
)
|
||||||
|
|
||||||
|
const result = canDeleteRecord(appHierarchy.customerRecord)
|
||||||
|
|
||||||
|
expect(result.canDelete).toBe(false)
|
||||||
|
expect(result.errors.some(e => e.includes("Outstanding Invoices"))).toBe(true)
|
||||||
|
})
|
||||||
})
|
})
|
Loading…
Reference in New Issue