1
0
Fork 0
mirror of synced 2024-10-02 10:08:09 +13:00

bugfix: upgradeData - not upgrading child records

This commit is contained in:
Michael Shanks 2020-03-26 14:32:09 +00:00
parent 3f1fcfa50c
commit 8e322e314b
3 changed files with 51 additions and 3 deletions

View file

@ -1,7 +1,7 @@
import { isString, flatten, map, filter } from "lodash/fp"
import { initialiseChildCollections } from "../collectionApi/initialise"
import { _loadFromInfo } from "./load"
import { $ } from "../common"
import { $, joinKey } from "../common"
import {
getFlattenedHierarchy,
isRecord,
@ -11,6 +11,7 @@ import {
} from "../templateApi/hierarchy"
import { initialiseIndex } from "../indexing/initialiseIndex"
import { getRecordInfo } from "./recordInfo"
import { getAllIdsIterator } from "../indexing/allIds"
export const initialiseChildren = async (app, recordInfoOrKey) => {
const recordInfo = isString(recordInfoOrKey)
@ -29,7 +30,7 @@ export const initialiseChildrenForNode = async (app, recordNode) => {
return
}
const iterate = await getAllIdsIterator(app)(recordNode.parent().nodeKey())
const iterate = await getAllIdsIterator(app)(recordNode.parent().collectionNodeKey())
let iterateResult = await iterate()
while (!iterateResult.done) {
const { result } = iterateResult

View file

@ -193,5 +193,5 @@ const runInitialiseRoot = async (_, newApp) => {
}
const runInitialiseChildRecord = async (_, newApp, diff) => {
await initialiseChildrenForNode(newApp.datastore, diff.newNode)
await initialiseChildrenForNode(newApp, diff.newNode)
}

View file

@ -8,6 +8,7 @@ import { $, splitKey } from "../src/common"
import { keys, filter } from "lodash/fp"
import { _listItems } from "../src/indexApi/listItems"
import { _save } from "../src/recordApi/save"
import { _getNew } from "../src/recordApi/getNew"
describe("upgradeData", () => {
@ -191,6 +192,52 @@ describe("upgradeData", () => {
})
it("should initialise a new root record", async () => {
const { oldSetup, newSetup } = await configure()
const invoice = newSetup.templateApi.getNewRecordTemplate(newSetup.root, "invoice", true)
invoice.collectionName = "invoices"
const nameField = newSetup.templateApi.getNewField("string")
nameField.name = "name"
newSetup.templateApi.addField(invoice, nameField)
await upgradeData(oldSetup.app)(newSetup.root)
let itemsInNewIndex = await _listItems(newSetup.app, "/invoice_index")
expect(itemsInNewIndex.length).toBe(0)
const newInvoice = _getNew(invoice, "/invoices")
await _save(newSetup.app, newInvoice)
itemsInNewIndex = await _listItems(newSetup.app, "/invoice_index")
expect(itemsInNewIndex.length).toBe(1)
})
it("should initialise a new child record", async () => {
const { oldSetup, newSetup, records } = await configure()
const invoice = newSetup.templateApi.getNewRecordTemplate(newSetup.contact, "invoice", true)
invoice.collectionName = "invoices"
const nameField = newSetup.templateApi.getNewField("string")
nameField.name = "name"
newSetup.templateApi.addField(invoice, nameField)
await upgradeData(oldSetup.app)(newSetup.root)
let itemsInNewIndex = await _listItems(newSetup.app, `${records.contact1.key}/invoice_index`)
expect(itemsInNewIndex.length).toBe(0)
const newInvoice = _getNew(invoice, `${records.contact1.key}/invoices`)
await _save(newSetup.app, newInvoice)
itemsInNewIndex = await _listItems(newSetup.app, `${records.contact1.key}/invoice_index`)
expect(itemsInNewIndex.length).toBe(1)
})
})
const configure = async () => {