refactor: application dependency management (#2363)

This commit is contained in:
Mo
2023-07-23 15:54:31 -05:00
committed by GitHub
parent e698b1c990
commit a77535456c
299 changed files with 7415 additions and 4890 deletions

View File

@@ -30,8 +30,8 @@ describe('app models', () => {
await Factory.safeDeinit(this.application)
})
it('payloadManager should be defined', () => {
expect(sharedApplication.payloadManager).to.be.ok
it('payloads should be defined', () => {
expect(sharedApplication.payloads).to.be.ok
})
it('item should be defined', () => {
@@ -75,14 +75,14 @@ describe('app models', () => {
await this.application.mutator.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
await this.application.mutator.emitItemsFromPayloads([params2], PayloadEmitSource.LocalChanged)
const item1 = this.application.itemManager.findItem(params1.uuid)
const item2 = this.application.itemManager.findItem(params2.uuid)
const item1 = this.application.items.findItem(params1.uuid)
const item2 = this.application.items.findItem(params2.uuid)
expect(item1.content.references.length).to.equal(1)
expect(item2.content.references.length).to.equal(0)
expect(this.application.itemManager.itemsReferencingItem(item1).length).to.equal(0)
expect(this.application.itemManager.itemsReferencingItem(item2).length).to.equal(1)
expect(this.application.items.itemsReferencingItem(item1).length).to.equal(0)
expect(this.application.items.itemsReferencingItem(item2).length).to.equal(1)
})
it('mapping an item twice shouldnt cause problems', async function () {
@@ -103,7 +103,7 @@ describe('app models', () => {
item = items[0]
expect(item.content.foo).to.equal('bar')
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
expect(this.application.items.getDisplayableNotes().length).to.equal(1)
})
it('mapping item twice should preserve references', async function () {
@@ -117,7 +117,7 @@ describe('app models', () => {
mutator.e2ePendingRefactor_addItemAsRelationship(item1)
})
const refreshedItem = this.application.itemManager.findItem(item1.uuid)
const refreshedItem = this.application.items.findItem(item1.uuid)
expect(refreshedItem.content.references.length).to.equal(1)
})
@@ -132,8 +132,8 @@ describe('app models', () => {
mutator.e2ePendingRefactor_addItemAsRelationship(item1)
})
const refreshedItem1 = this.application.itemManager.findItem(item1.uuid)
const refreshedItem2 = this.application.itemManager.findItem(item2.uuid)
const refreshedItem1 = this.application.items.findItem(item1.uuid)
const refreshedItem2 = this.application.items.findItem(item2.uuid)
expect(refreshedItem1.content.references.length).to.equal(1)
expect(refreshedItem2.content.references.length).to.equal(1)
@@ -147,8 +147,8 @@ describe('app models', () => {
})
await this.application.mutator.emitItemsFromPayloads([damagedPayload], PayloadEmitSource.LocalChanged)
const refreshedItem1_2 = this.application.itemManager.findItem(item1.uuid)
const refreshedItem2_2 = this.application.itemManager.findItem(item2.uuid)
const refreshedItem1_2 = this.application.items.findItem(item1.uuid)
const refreshedItem2_2 = this.application.items.findItem(item2.uuid)
expect(refreshedItem1_2.content.references.length).to.equal(0)
expect(refreshedItem2_2.content.references.length).to.equal(1)
@@ -164,14 +164,14 @@ describe('app models', () => {
mutator.e2ePendingRefactor_addItemAsRelationship(item1)
})
const refreshedItem1 = this.application.itemManager.findItem(item1.uuid)
const refreshedItem2 = this.application.itemManager.findItem(item2.uuid)
const refreshedItem1 = this.application.items.findItem(item1.uuid)
const refreshedItem2 = this.application.items.findItem(item2.uuid)
expect(refreshedItem1.content.references.length).to.equal(1)
expect(refreshedItem2.content.references.length).to.equal(1)
expect(this.application.itemManager.itemsReferencingItem(item1)).to.include(refreshedItem2)
expect(this.application.itemManager.itemsReferencingItem(item2)).to.include(refreshedItem1)
expect(this.application.items.itemsReferencingItem(item1)).to.include(refreshedItem2)
expect(this.application.items.itemsReferencingItem(item2)).to.include(refreshedItem1)
await this.application.mutator.changeItem(item1, (mutator) => {
mutator.removeItemAsRelationship(item2)
@@ -180,14 +180,14 @@ describe('app models', () => {
mutator.removeItemAsRelationship(item1)
})
const refreshedItem1_2 = this.application.itemManager.findItem(item1.uuid)
const refreshedItem2_2 = this.application.itemManager.findItem(item2.uuid)
const refreshedItem1_2 = this.application.items.findItem(item1.uuid)
const refreshedItem2_2 = this.application.items.findItem(item2.uuid)
expect(refreshedItem1_2.content.references.length).to.equal(0)
expect(refreshedItem2_2.content.references.length).to.equal(0)
expect(this.application.itemManager.itemsReferencingItem(item1).length).to.equal(0)
expect(this.application.itemManager.itemsReferencingItem(item2).length).to.equal(0)
expect(this.application.items.itemsReferencingItem(item1).length).to.equal(0)
expect(this.application.items.itemsReferencingItem(item2).length).to.equal(0)
})
it('properly duplicates item with no relationships', async function () {
@@ -213,10 +213,10 @@ describe('app models', () => {
expect(duplicate.uuid).to.not.equal(item1.uuid)
expect(duplicate.content.references.length).to.equal(1)
expect(this.application.itemManager.itemsReferencingItem(item1).length).to.equal(0)
expect(this.application.itemManager.itemsReferencingItem(item2).length).to.equal(2)
expect(this.application.items.itemsReferencingItem(item1).length).to.equal(0)
expect(this.application.items.itemsReferencingItem(item2).length).to.equal(2)
const refreshedItem1_2 = this.application.itemManager.findItem(item1.uuid)
const refreshedItem1_2 = this.application.items.findItem(item1.uuid)
expect(refreshedItem1_2.isItemContentEqualWith(duplicate)).to.equal(true)
expect(refreshedItem1_2.created_at.toISOString()).to.equal(duplicate.created_at.toISOString())
expect(refreshedItem1_2.content_type).to.equal(duplicate.content_type)
@@ -240,8 +240,8 @@ describe('app models', () => {
PayloadEmitSource.LocalChanged,
)
expect(this.application.itemManager.itemsReferencingItem(item2).length).to.equal(0)
expect(this.application.itemManager.itemsReferencingItem(item1).length).to.equal(0)
expect(this.application.items.itemsReferencingItem(item2).length).to.equal(0)
expect(this.application.items.itemsReferencingItem(item1).length).to.equal(0)
expect(refreshedItem1_2.content.references.length).to.equal(0)
})
@@ -254,18 +254,18 @@ describe('app models', () => {
})
expect(refreshedItem1.content.references.length).to.equal(1)
expect(this.application.itemManager.itemsReferencingItem(item2).length).to.equal(1)
expect(this.application.items.itemsReferencingItem(item2).length).to.equal(1)
const alternatedItem = await Factory.alternateUuidForItem(this.application, item1.uuid)
const refreshedItem1_2 = this.application.itemManager.findItem(item1.uuid)
const refreshedItem1_2 = this.application.items.findItem(item1.uuid)
expect(refreshedItem1_2).to.not.be.ok
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(2)
expect(this.application.items.getDisplayableNotes().length).to.equal(2)
expect(alternatedItem.content.references.length).to.equal(1)
expect(this.application.itemManager.itemsReferencingItem(alternatedItem.uuid).length).to.equal(0)
expect(this.application.items.itemsReferencingItem(alternatedItem.uuid).length).to.equal(0)
expect(this.application.itemManager.itemsReferencingItem(item2).length).to.equal(1)
expect(this.application.items.itemsReferencingItem(item2).length).to.equal(1)
expect(alternatedItem.isReferencingItem(item2)).to.equal(true)
expect(alternatedItem.dirty).to.equal(true)
@@ -279,10 +279,10 @@ describe('app models', () => {
it('alterating itemskey uuid should update errored items encrypted with that key', async function () {
const item1 = await Factory.createMappedNote(this.application)
const itemsKey = this.application.itemManager.getDisplayableItemsKeys()[0]
const itemsKey = this.application.items.getDisplayableItemsKeys()[0]
/** Encrypt item1 and emit as errored so it persists with items_key_id */
const encrypted = await this.application.encryptionService.encryptSplitSingle({
const encrypted = await this.application.encryption.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [item1.payload],
},
@@ -292,17 +292,17 @@ describe('app models', () => {
waitingForKey: true,
})
await this.application.payloadManager.emitPayload(errored)
await this.application.payloads.emitPayload(errored)
expect(this.application.payloadManager.findOne(item1.uuid).errorDecrypting).to.equal(true)
expect(this.application.payloadManager.findOne(item1.uuid).items_key_id).to.equal(itemsKey.uuid)
expect(this.application.payloads.findOne(item1.uuid).errorDecrypting).to.equal(true)
expect(this.application.payloads.findOne(item1.uuid).items_key_id).to.equal(itemsKey.uuid)
sinon.stub(this.application.encryptionService.itemsEncryption, 'decryptErroredItemPayloads').callsFake(() => {
sinon.stub(this.application.encryption.itemsEncryption, 'decryptErroredItemPayloads').callsFake(() => {
// prevent auto decryption
})
const alternatedKey = await Factory.alternateUuidForItem(this.application, itemsKey.uuid)
const updatedPayload = this.application.payloadManager.findOne(item1.uuid)
const updatedPayload = this.application.payloads.findOne(item1.uuid)
expect(updatedPayload.items_key_id).to.equal(alternatedKey.uuid)
})
@@ -316,22 +316,22 @@ describe('app models', () => {
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
})
expect(this.application.itemManager.itemsReferencingItem(item2).length).to.equal(1)
expect(this.application.items.itemsReferencingItem(item2).length).to.equal(1)
const alternatedItem1 = await Factory.alternateUuidForItem(this.application, item1.uuid)
const alternatedItem2 = await Factory.alternateUuidForItem(this.application, item2.uuid)
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
expect(item1.uuid).to.not.equal(alternatedItem1.uuid)
expect(item2.uuid).to.not.equal(alternatedItem2.uuid)
const refreshedAltItem1 = this.application.itemManager.findItem(alternatedItem1.uuid)
const refreshedAltItem1 = this.application.items.findItem(alternatedItem1.uuid)
expect(refreshedAltItem1.content.references.length).to.equal(1)
expect(refreshedAltItem1.content.references[0].uuid).to.equal(alternatedItem2.uuid)
expect(alternatedItem2.content.references.length).to.equal(0)
expect(this.application.itemManager.itemsReferencingItem(alternatedItem2).length).to.equal(1)
expect(this.application.items.itemsReferencingItem(alternatedItem2).length).to.equal(1)
expect(refreshedAltItem1.isReferencingItem(alternatedItem2)).to.equal(true)
expect(alternatedItem2.isReferencingItem(refreshedAltItem1)).to.equal(false)
@@ -350,12 +350,12 @@ describe('app models', () => {
const noteCopy = await this.application.mutator.duplicateItem(note)
expect(note.uuid).to.not.equal(noteCopy.uuid)
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(2)
expect(this.application.itemManager.getDisplayableTags().length).to.equal(1)
expect(this.application.items.getDisplayableNotes().length).to.equal(2)
expect(this.application.items.getDisplayableTags().length).to.equal(1)
expect(note.content.references.length).to.equal(0)
expect(noteCopy.content.references.length).to.equal(0)
const refreshedTag_2 = this.application.itemManager.findItem(tag.uuid)
const refreshedTag_2 = this.application.items.findItem(tag.uuid)
expect(refreshedTag_2.content.references.length).to.equal(2)
})