refactor: application dependency management (#2363)
This commit is contained in:
@@ -30,10 +30,10 @@ describe('online conflict handling', function () {
|
||||
await this.context.register()
|
||||
|
||||
this.sharedFinalAssertions = async function () {
|
||||
expect(this.application.syncService.isOutOfSync()).to.equal(false)
|
||||
const items = this.application.itemManager.items
|
||||
expect(this.application.sync.isOutOfSync()).to.equal(false)
|
||||
const items = this.application.items.items
|
||||
expect(items.length).to.equal(this.expectedItemCount)
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
expect(rawPayloads.length).to.equal(this.expectedItemCount)
|
||||
}
|
||||
})
|
||||
@@ -68,7 +68,7 @@ describe('online conflict handling', function () {
|
||||
|
||||
this.expectedItemCount++
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
/** First modify the item without saving so that our local contents digress from the server's */
|
||||
await this.application.mutator.changeItem(item, (mutator) => {
|
||||
@@ -85,7 +85,7 @@ describe('online conflict handling', function () {
|
||||
syncOptions,
|
||||
)
|
||||
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
|
||||
@@ -93,7 +93,7 @@ describe('online conflict handling', function () {
|
||||
const payload = createDirtyPayload(ContentType.TYPES.ItemsKey)
|
||||
const item = await this.application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
|
||||
this.expectedItemCount++
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
/** First modify the item without saving so that
|
||||
* our local contents digress from the server's */
|
||||
await this.application.mutator.changeItem(item, (mutator) => {
|
||||
@@ -110,7 +110,7 @@ describe('online conflict handling', function () {
|
||||
syncOptions,
|
||||
)
|
||||
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
|
||||
@@ -119,9 +119,9 @@ describe('online conflict handling', function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
this.expectedItemCount++
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
expect(rawPayloads.length).to.equal(this.expectedItemCount)
|
||||
|
||||
const originalValue = note.title
|
||||
@@ -141,27 +141,27 @@ describe('online conflict handling', function () {
|
||||
})
|
||||
|
||||
// Download all items from the server, which will include this note.
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.syncService.sync({
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
await this.application.sync.sync({
|
||||
...syncOptions,
|
||||
awaitAll: true,
|
||||
})
|
||||
|
||||
// We expect this item to be duplicated
|
||||
this.expectedItemCount++
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(2)
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(2)
|
||||
|
||||
const allItems = this.application.itemManager.items
|
||||
const allItems = this.application.items.items
|
||||
expect(allItems.length).to.equal(this.expectedItemCount)
|
||||
|
||||
const originalItem = this.application.itemManager.findItem(note.uuid)
|
||||
const originalItem = this.application.items.findItem(note.uuid)
|
||||
const duplicateItem = allItems.find((i) => i.content.conflict_of === note.uuid)
|
||||
|
||||
expect(originalItem.title).to.equal(dirtyValue)
|
||||
expect(duplicateItem.title).to.equal(originalValue)
|
||||
expect(originalItem.title).to.not.equal(duplicateItem.title)
|
||||
|
||||
const newRawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const newRawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
expect(newRawPayloads.length).to.equal(this.expectedItemCount)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
@@ -172,7 +172,7 @@ describe('online conflict handling', function () {
|
||||
await Factory.markDirtyAndSyncItem(this.application, note)
|
||||
this.expectedItemCount++
|
||||
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
expect(rawPayloads.length).to.equal(this.expectedItemCount)
|
||||
/** First modify the item without saving so that
|
||||
* our local contents digress from the server's */
|
||||
@@ -192,11 +192,11 @@ describe('online conflict handling', function () {
|
||||
|
||||
// We expect this item to be duplicated
|
||||
this.expectedItemCount++
|
||||
const allItems = this.application.itemManager.items
|
||||
const allItems = this.application.items.items
|
||||
expect(allItems.length).to.equal(this.expectedItemCount)
|
||||
|
||||
const note1 = this.application.itemManager.getDisplayableNotes()[0]
|
||||
const note2 = this.application.itemManager.getDisplayableNotes()[1]
|
||||
const note1 = this.application.items.getDisplayableNotes()[0]
|
||||
const note2 = this.application.items.getDisplayableNotes()[1]
|
||||
expect(note1.content.title).to.not.equal(note2.content.title)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
@@ -222,16 +222,16 @@ describe('online conflict handling', function () {
|
||||
)
|
||||
|
||||
this.expectedItemCount++
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
|
||||
// clear sync token, clear storage, download all items, and ensure none of them have error decrypting
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.diskStorageService.clearAllPayloads()
|
||||
await this.application.payloadManager.resetState()
|
||||
await this.application.itemManager.resetState()
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
await this.application.storage.clearAllPayloads()
|
||||
await this.application.payloads.resetState()
|
||||
await this.application.items.resetState()
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
|
||||
@@ -239,7 +239,7 @@ describe('online conflict handling', function () {
|
||||
let note = await Factory.createMappedNote(this.application)
|
||||
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
this.expectedItemCount++
|
||||
|
||||
@@ -263,15 +263,15 @@ describe('online conflict handling', function () {
|
||||
// We expect this item to be duplicated
|
||||
this.expectedItemCount++
|
||||
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
note = this.application.items.findItem(note.uuid)
|
||||
|
||||
// We expect the item title to be the new title, and not rolled back to original value
|
||||
expect(note.content.title).to.equal(newTitle)
|
||||
|
||||
const allItems = this.application.itemManager.items
|
||||
const allItems = this.application.items.items
|
||||
expect(allItems.length).to.equal(this.expectedItemCount)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
@@ -280,16 +280,16 @@ describe('online conflict handling', function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
this.expectedItemCount++
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
// keep item as is and set dirty
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
|
||||
// clear sync token so that all items are retrieved on next sync
|
||||
this.application.syncService.clearSyncPositionTokens()
|
||||
this.application.sync.clearSyncPositionTokens()
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
|
||||
@@ -310,7 +310,7 @@ describe('online conflict handling', function () {
|
||||
)
|
||||
|
||||
// client B
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
await this.application.mutator.changeItem(
|
||||
note,
|
||||
(mutator) => {
|
||||
@@ -323,7 +323,7 @@ describe('online conflict handling', function () {
|
||||
|
||||
// conflict_of is a key to ignore when comparing content, so item should
|
||||
// not be duplicated.
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
|
||||
@@ -348,7 +348,7 @@ describe('online conflict handling', function () {
|
||||
mutator.title = `${Math.random()}`
|
||||
})
|
||||
// client B
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
|
||||
await Factory.changePayloadTimeStampAndSync(
|
||||
this.application,
|
||||
@@ -370,17 +370,17 @@ describe('online conflict handling', function () {
|
||||
const originalPayload = note.payloadRepresentation()
|
||||
this.expectedItemCount++
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
|
||||
// client A
|
||||
await this.application.mutator.setItemToBeDeleted(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
this.expectedItemCount--
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
|
||||
// client B
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
// Add the item back and say it's not deleted
|
||||
const mutatedPayload = new DecryptedPayload({
|
||||
...originalPayload,
|
||||
@@ -388,13 +388,13 @@ describe('online conflict handling', function () {
|
||||
updated_at: Factory.yesterday(),
|
||||
})
|
||||
await this.application.mutator.emitItemsFromPayloads([mutatedPayload], PayloadEmitSource.LocalChanged)
|
||||
const resultNote = this.application.itemManager.findItem(note.uuid)
|
||||
const resultNote = this.application.items.findItem(note.uuid)
|
||||
expect(resultNote.uuid).to.equal(note.uuid)
|
||||
await this.application.mutator.setItemDirty(resultNote)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
// We expect that this item is now gone for good, and a duplicate has not been created.
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
|
||||
@@ -404,11 +404,11 @@ describe('online conflict handling', function () {
|
||||
this.expectedItemCount++
|
||||
|
||||
// client A
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
|
||||
// client B
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
|
||||
// This client says this item is deleted, but the server is saying its not deleted.
|
||||
// In this case, we want to keep the server copy.
|
||||
@@ -420,14 +420,14 @@ describe('online conflict handling', function () {
|
||||
)
|
||||
|
||||
// We expect that this item maintained.
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
|
||||
it('should create conflict if syncing an item that is stale', async function () {
|
||||
let note = await Factory.createMappedNote(this.application)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
note = this.application.items.findItem(note.uuid)
|
||||
expect(note.dirty).to.equal(false)
|
||||
this.expectedItemCount++
|
||||
@@ -452,7 +452,7 @@ describe('online conflict handling', function () {
|
||||
// We expect now that the item was conflicted
|
||||
this.expectedItemCount++
|
||||
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
expect(rawPayloads.length).to.equal(this.expectedItemCount)
|
||||
for (const payload of rawPayloads) {
|
||||
expect(payload.dirty).to.not.be.ok
|
||||
@@ -465,7 +465,7 @@ describe('online conflict handling', function () {
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
this.expectedItemCount++
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
await Factory.changePayloadTimeStampAndSync(
|
||||
this.application,
|
||||
@@ -475,7 +475,7 @@ describe('online conflict handling', function () {
|
||||
syncOptions,
|
||||
)
|
||||
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
|
||||
@@ -488,11 +488,11 @@ describe('online conflict handling', function () {
|
||||
await Factory.createManyMappedNotes(this.application, largeItemCount)
|
||||
|
||||
/** Upload */
|
||||
this.application.syncService.sync(syncOptions)
|
||||
this.application.sync.sync(syncOptions)
|
||||
await this.context.awaitNextSucessfulSync()
|
||||
|
||||
this.expectedItemCount += largeItemCount
|
||||
const items = this.application.itemManager.items
|
||||
const items = this.application.items.items
|
||||
expect(items.length).to.equal(this.expectedItemCount)
|
||||
|
||||
/**
|
||||
@@ -500,9 +500,9 @@ describe('online conflict handling', function () {
|
||||
* the server as dirty, with no sync token, so that the server also
|
||||
* gives us everything it has.
|
||||
*/
|
||||
this.application.syncService.lockSyncing()
|
||||
this.application.sync.lockSyncing()
|
||||
const yesterday = Factory.yesterday()
|
||||
for (const note of this.application.itemManager.getDisplayableNotes()) {
|
||||
for (const note of this.application.items.getDisplayableNotes()) {
|
||||
/** First modify the item without saving so that
|
||||
* our local contents digress from the server's */
|
||||
await this.application.mutator.changeItem(note, (mutator) => {
|
||||
@@ -516,13 +516,13 @@ describe('online conflict handling', function () {
|
||||
// We expect all the notes to be duplicated.
|
||||
this.expectedItemCount++
|
||||
}
|
||||
this.application.syncService.unlockSyncing()
|
||||
this.application.sync.unlockSyncing()
|
||||
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
this.application.sync.sync(syncOptions)
|
||||
await this.context.awaitNextSucessfulSync()
|
||||
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(largeItemCount * 2)
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(largeItemCount * 2)
|
||||
await this.sharedFinalAssertions()
|
||||
}).timeout(60000)
|
||||
|
||||
@@ -532,8 +532,8 @@ describe('online conflict handling', function () {
|
||||
this.expectedItemCount -= 1 /** auto-created user preferences */
|
||||
await this.application.mutator.emitItemsFromPayloads([payload1, payload2], PayloadEmitSource.LocalChanged)
|
||||
this.expectedItemCount += 2
|
||||
let tag = this.application.itemManager.getItems(ContentType.TYPES.Tag)[0]
|
||||
let userPrefs = this.application.itemManager.getItems(ContentType.TYPES.UserPrefs)[0]
|
||||
let tag = this.application.items.getItems(ContentType.TYPES.Tag)[0]
|
||||
let userPrefs = this.application.items.getItems(ContentType.TYPES.UserPrefs)[0]
|
||||
expect(tag).to.be.ok
|
||||
expect(userPrefs).to.be.ok
|
||||
|
||||
@@ -544,11 +544,11 @@ describe('online conflict handling', function () {
|
||||
await this.application.mutator.setItemDirty(userPrefs)
|
||||
userPrefs = this.application.items.findItem(userPrefs.uuid)
|
||||
|
||||
expect(this.application.itemManager.itemsReferencingItem(userPrefs).length).to.equal(1)
|
||||
expect(this.application.itemManager.itemsReferencingItem(userPrefs)).to.include(tag)
|
||||
expect(this.application.items.itemsReferencingItem(userPrefs).length).to.equal(1)
|
||||
expect(this.application.items.itemsReferencingItem(userPrefs)).to.include(tag)
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
|
||||
tag = await Factory.changePayloadTimeStamp(
|
||||
this.application,
|
||||
@@ -559,32 +559,32 @@ describe('online conflict handling', function () {
|
||||
},
|
||||
)
|
||||
|
||||
await this.application.syncService.sync({ ...syncOptions, awaitAll: true })
|
||||
await this.application.sync.sync({ ...syncOptions, awaitAll: true })
|
||||
|
||||
// fooItem should now be conflicted and a copy created
|
||||
this.expectedItemCount++
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
expect(rawPayloads.length).to.equal(this.expectedItemCount)
|
||||
|
||||
const fooItems = this.application.itemManager.getItems(ContentType.TYPES.Tag)
|
||||
const fooItems = this.application.items.getItems(ContentType.TYPES.Tag)
|
||||
const fooItem2 = fooItems[1]
|
||||
|
||||
expect(fooItem2.content.conflict_of).to.equal(tag.uuid)
|
||||
// Two items now link to this original object
|
||||
const referencingItems = this.application.itemManager.itemsReferencingItem(userPrefs)
|
||||
const referencingItems = this.application.items.itemsReferencingItem(userPrefs)
|
||||
expect(referencingItems.length).to.equal(2)
|
||||
expect(referencingItems[0]).to.not.equal(referencingItems[1])
|
||||
|
||||
expect(this.application.itemManager.itemsReferencingItem(tag).length).to.equal(0)
|
||||
expect(this.application.itemManager.itemsReferencingItem(fooItem2).length).to.equal(0)
|
||||
expect(this.application.items.itemsReferencingItem(tag).length).to.equal(0)
|
||||
expect(this.application.items.itemsReferencingItem(fooItem2).length).to.equal(0)
|
||||
|
||||
expect(tag.content.references.length).to.equal(1)
|
||||
expect(fooItem2.content.references.length).to.equal(1)
|
||||
expect(userPrefs.content.references.length).to.equal(0)
|
||||
|
||||
expect(this.application.itemManager.getDirtyItems().length).to.equal(0)
|
||||
for (const item of this.application.itemManager.items) {
|
||||
expect(this.application.items.getDirtyItems().length).to.equal(0)
|
||||
for (const item of this.application.items.items) {
|
||||
expect(item.dirty).to.not.be.ok
|
||||
}
|
||||
await this.sharedFinalAssertions()
|
||||
@@ -611,7 +611,7 @@ describe('online conflict handling', function () {
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
this.expectedItemCount += 2
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
// conflict the note
|
||||
const newText = `${Math.random()}`
|
||||
@@ -645,7 +645,7 @@ describe('online conflict handling', function () {
|
||||
* and not 2 (the note and tag)
|
||||
*/
|
||||
this.expectedItemCount += 1
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
expect(tag.content.references.length).to.equal(2)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
@@ -680,7 +680,7 @@ describe('online conflict handling', function () {
|
||||
await this.application.sync.sync()
|
||||
|
||||
/** Expect that no duplicates have been created, and that the note's title is now finalTitle */
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(1)
|
||||
const finalNote = this.application.items.findItem(note.uuid)
|
||||
expect(finalNote.title).to.equal(finalTitle)
|
||||
await this.sharedFinalAssertions()
|
||||
@@ -713,8 +713,8 @@ describe('online conflict handling', function () {
|
||||
/**
|
||||
* Retrieve this note from the server by clearing sync token
|
||||
*/
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.syncService.sync({
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
await this.application.sync.sync({
|
||||
...syncOptions,
|
||||
awaitAll: true,
|
||||
})
|
||||
@@ -724,7 +724,7 @@ describe('online conflict handling', function () {
|
||||
*/
|
||||
const resultNote = await this.application.items.findItem(note.uuid)
|
||||
expect(resultNote.errorDecrypting).to.not.be.ok
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(1)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
|
||||
@@ -748,8 +748,8 @@ describe('online conflict handling', function () {
|
||||
/** Create bulk data belonging to another account and sync */
|
||||
const largeItemCount = SyncUpDownLimit + 10
|
||||
await Factory.createManyMappedNotes(this.application, largeItemCount)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
const priorData = this.application.itemManager.items
|
||||
await this.application.sync.sync(syncOptions)
|
||||
const priorData = this.application.items.items
|
||||
|
||||
/** Register new account and import this same data */
|
||||
const newApp = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
@@ -759,9 +759,9 @@ describe('online conflict handling', function () {
|
||||
password: Utils.generateUuid(),
|
||||
})
|
||||
await newApp.mutator.emitItemsFromPayloads(priorData.map((i) => i.payload))
|
||||
await newApp.syncService.markAllItemsAsNeedingSyncAndPersist()
|
||||
await newApp.syncService.sync(syncOptions)
|
||||
expect(newApp.payloadManager.invalidPayloads.length).to.equal(0)
|
||||
await newApp.sync.markAllItemsAsNeedingSyncAndPersist()
|
||||
await newApp.sync.sync(syncOptions)
|
||||
expect(newApp.payloads.invalidPayloads.length).to.equal(0)
|
||||
await Factory.safeDeinit(newApp)
|
||||
},
|
||||
).timeout(80000)
|
||||
@@ -787,8 +787,8 @@ describe('online conflict handling', function () {
|
||||
})
|
||||
Factory.handlePasswordChallenges(newApp, password)
|
||||
await newApp.importData(backupFile, true)
|
||||
expect(newApp.itemManager.getDisplayableTags().length).to.equal(1)
|
||||
expect(newApp.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(newApp.items.getDisplayableTags().length).to.equal(1)
|
||||
expect(newApp.items.getDisplayableNotes().length).to.equal(1)
|
||||
await Factory.safeDeinit(newApp)
|
||||
}).timeout(10000)
|
||||
|
||||
@@ -799,7 +799,7 @@ describe('online conflict handling', function () {
|
||||
*/
|
||||
/** Create primary account and export data */
|
||||
await createSyncedNoteWithTag(this.application)
|
||||
const tag = this.application.itemManager.getDisplayableTags()[0]
|
||||
const tag = this.application.items.getDisplayableTags()[0]
|
||||
const note2 = await Factory.createMappedNote(this.application)
|
||||
await this.application.changeAndSaveItem(tag, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(note2)
|
||||
@@ -822,7 +822,7 @@ describe('online conflict handling', function () {
|
||||
})
|
||||
Factory.handlePasswordChallenges(newApp, password)
|
||||
await newApp.importData(backupFile, true)
|
||||
const newTag = newApp.itemManager.getDisplayableTags()[0]
|
||||
const newTag = newApp.items.getDisplayableTags()[0]
|
||||
const notes = newApp.items.referencesForItem(newTag)
|
||||
expect(notes.length).to.equal(2)
|
||||
await Factory.safeDeinit(newApp)
|
||||
@@ -857,7 +857,7 @@ describe('online conflict handling', function () {
|
||||
})
|
||||
await this.application.mutator.emitItemFromPayload(modified)
|
||||
await this.application.sync.sync()
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(1)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
|
||||
@@ -881,7 +881,7 @@ describe('online conflict handling', function () {
|
||||
this.expectedItemCount++
|
||||
await this.application.mutator.emitItemFromPayload(modified)
|
||||
await this.application.sync.sync()
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(2)
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(2)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
|
||||
@@ -913,7 +913,7 @@ describe('online conflict handling', function () {
|
||||
this.expectedItemCount++
|
||||
await this.application.mutator.emitItemFromPayload(modified)
|
||||
await this.application.sync.sync()
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(2)
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(2)
|
||||
await this.sharedFinalAssertions()
|
||||
})
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('sync integrity', () => {
|
||||
|
||||
const awaitSyncEventPromise = (application, targetEvent) => {
|
||||
return new Promise((resolve) => {
|
||||
application.syncService.addEventObserver((event) => {
|
||||
application.sync.addEventObserver((event) => {
|
||||
if (event === targetEvent) {
|
||||
resolve()
|
||||
}
|
||||
@@ -37,8 +37,8 @@ describe('sync integrity', () => {
|
||||
}
|
||||
|
||||
afterEach(async function () {
|
||||
expect(this.application.syncService.isOutOfSync()).to.equal(false)
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
expect(this.application.sync.isOutOfSync()).to.equal(false)
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
expect(rawPayloads.length).to.equal(this.expectedItemCount)
|
||||
await Factory.safeDeinit(this.application)
|
||||
})
|
||||
@@ -51,10 +51,10 @@ describe('sync integrity', () => {
|
||||
this.expectedItemCount++
|
||||
|
||||
const didEnterOutOfSync = awaitSyncEventPromise(this.application, SyncEvent.EnterOutOfSync)
|
||||
await this.application.syncService.sync({ checkIntegrity: true })
|
||||
await this.application.sync.sync({ checkIntegrity: true })
|
||||
|
||||
await this.application.itemManager.removeItemLocally(item)
|
||||
await this.application.syncService.sync({ checkIntegrity: true, awaitAll: true })
|
||||
await this.application.items.removeItemLocally(item)
|
||||
await this.application.sync.sync({ checkIntegrity: true, awaitAll: true })
|
||||
|
||||
await didEnterOutOfSync
|
||||
})
|
||||
@@ -69,11 +69,11 @@ describe('sync integrity', () => {
|
||||
const didEnterOutOfSync = awaitSyncEventPromise(this.application, SyncEvent.EnterOutOfSync)
|
||||
const didExitOutOfSync = awaitSyncEventPromise(this.application, SyncEvent.ExitOutOfSync)
|
||||
|
||||
await this.application.syncService.sync({ checkIntegrity: true })
|
||||
await this.application.itemManager.removeItemLocally(item)
|
||||
await this.application.syncService.sync({ checkIntegrity: true, awaitAll: true })
|
||||
await this.application.sync.sync({ checkIntegrity: true })
|
||||
await this.application.items.removeItemLocally(item)
|
||||
await this.application.sync.sync({ checkIntegrity: true, awaitAll: true })
|
||||
|
||||
await Promise.all([didEnterOutOfSync, didExitOutOfSync])
|
||||
expect(this.application.syncService.isOutOfSync()).to.equal(false)
|
||||
expect(this.application.sync.isOutOfSync()).to.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -34,12 +34,12 @@ describe('notes + tags syncing', function () {
|
||||
it('syncing an item then downloading it should include items_key_id', async function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.payloadManager.resetState()
|
||||
await this.application.itemManager.resetState()
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
const downloadedNote = this.application.itemManager.getDisplayableNotes()[0]
|
||||
await this.application.sync.sync(syncOptions)
|
||||
await this.application.payloads.resetState()
|
||||
await this.application.items.resetState()
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
await this.application.sync.sync(syncOptions)
|
||||
const downloadedNote = this.application.items.getDisplayableNotes()[0]
|
||||
expect(downloadedNote.items_key_id).to.not.be.ok
|
||||
// Allow time for waitingForKey
|
||||
await Factory.sleep(0.1)
|
||||
@@ -53,20 +53,20 @@ describe('notes + tags syncing', function () {
|
||||
const tagPayload = pair[1]
|
||||
|
||||
await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
|
||||
const note = this.application.itemManager.getItems([ContentType.TYPES.Note])[0]
|
||||
const tag = this.application.itemManager.getItems([ContentType.TYPES.Tag])[0]
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.itemManager.getDisplayableTags().length).to.equal(1)
|
||||
const note = this.application.items.getItems([ContentType.TYPES.Note])[0]
|
||||
const tag = this.application.items.getItems([ContentType.TYPES.Tag])[0]
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableTags().length).to.equal(1)
|
||||
|
||||
for (let i = 0; i < 9; i++) {
|
||||
await this.application.mutator.setItemsDirty([note, tag])
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.sync.sync(syncOptions)
|
||||
this.application.sync.clearSyncPositionTokens()
|
||||
expect(tag.content.references.length).to.equal(1)
|
||||
expect(this.application.itemManager.itemsReferencingItem(note).length).to.equal(1)
|
||||
expect(this.application.items.itemsReferencingItem(note).length).to.equal(1)
|
||||
expect(tag.noteCount).to.equal(1)
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.itemManager.getDisplayableTags().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableTags().length).to.equal(1)
|
||||
console.warn('Waiting 0.1s...')
|
||||
await Factory.sleep(0.1)
|
||||
}
|
||||
@@ -77,32 +77,32 @@ describe('notes + tags syncing', function () {
|
||||
const notePayload = pair[0]
|
||||
const tagPayload = pair[1]
|
||||
await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
|
||||
const originalNote = this.application.itemManager.getDisplayableNotes()[0]
|
||||
const originalTag = this.application.itemManager.getDisplayableTags()[0]
|
||||
const originalNote = this.application.items.getDisplayableNotes()[0]
|
||||
const originalTag = this.application.items.getDisplayableTags()[0]
|
||||
await this.application.mutator.setItemsDirty([originalNote, originalTag])
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
expect(originalTag.content.references.length).to.equal(1)
|
||||
expect(originalTag.noteCount).to.equal(1)
|
||||
expect(this.application.itemManager.itemsReferencingItem(originalNote).length).to.equal(1)
|
||||
expect(this.application.items.itemsReferencingItem(originalNote).length).to.equal(1)
|
||||
|
||||
// when signing in, all local items are cleared from storage (but kept in memory; to clear desktop logs),
|
||||
// then resaved with alternated uuids.
|
||||
await this.application.diskStorageService.clearAllPayloads()
|
||||
await this.application.syncService.markAllItemsAsNeedingSyncAndPersist()
|
||||
await this.application.storage.clearAllPayloads()
|
||||
await this.application.sync.markAllItemsAsNeedingSyncAndPersist()
|
||||
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.itemManager.getDisplayableTags().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableTags().length).to.equal(1)
|
||||
|
||||
const note = this.application.itemManager.getDisplayableNotes()[0]
|
||||
const tag = this.application.itemManager.getDisplayableTags()[0]
|
||||
const note = this.application.items.getDisplayableNotes()[0]
|
||||
const tag = this.application.items.getDisplayableTags()[0]
|
||||
|
||||
expect(tag.content.references.length).to.equal(1)
|
||||
expect(note.content.references.length).to.equal(0)
|
||||
|
||||
expect(tag.noteCount).to.equal(1)
|
||||
expect(this.application.itemManager.itemsReferencingItem(note).length).to.equal(1)
|
||||
expect(this.application.items.itemsReferencingItem(note).length).to.equal(1)
|
||||
})
|
||||
|
||||
it('duplicating a tag should maintian its relationships', async function () {
|
||||
@@ -110,22 +110,22 @@ describe('notes + tags syncing', function () {
|
||||
const notePayload = pair[0]
|
||||
const tagPayload = pair[1]
|
||||
await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
|
||||
let note = this.application.itemManager.getDisplayableNotes()[0]
|
||||
let tag = this.application.itemManager.getDisplayableTags()[0]
|
||||
expect(this.application.itemManager.itemsReferencingItem(note).length).to.equal(1)
|
||||
let note = this.application.items.getDisplayableNotes()[0]
|
||||
let tag = this.application.items.getDisplayableTags()[0]
|
||||
expect(this.application.items.itemsReferencingItem(note).length).to.equal(1)
|
||||
|
||||
await this.application.mutator.setItemsDirty([note, tag])
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.sync.sync(syncOptions)
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
|
||||
note = this.application.itemManager.findItem(note.uuid)
|
||||
tag = this.application.itemManager.findItem(tag.uuid)
|
||||
note = this.application.items.findItem(note.uuid)
|
||||
tag = this.application.items.findItem(tag.uuid)
|
||||
|
||||
expect(note.dirty).to.equal(false)
|
||||
expect(tag.dirty).to.equal(false)
|
||||
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.itemManager.getDisplayableTags().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableTags().length).to.equal(1)
|
||||
|
||||
await Factory.changePayloadTimeStampAndSync(
|
||||
this.application,
|
||||
@@ -137,13 +137,13 @@ describe('notes + tags syncing', function () {
|
||||
syncOptions,
|
||||
)
|
||||
|
||||
tag = this.application.itemManager.findItem(tag.uuid)
|
||||
tag = this.application.items.findItem(tag.uuid)
|
||||
|
||||
// tag should now be conflicted and a copy created
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.itemManager.getDisplayableTags().length).to.equal(2)
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableTags().length).to.equal(2)
|
||||
|
||||
const tags = this.application.itemManager.getDisplayableTags()
|
||||
const tags = this.application.items.getDisplayableTags()
|
||||
const conflictedTag = tags.find((tag) => {
|
||||
return !!tag.content.conflict_of
|
||||
})
|
||||
@@ -157,11 +157,11 @@ describe('notes + tags syncing', function () {
|
||||
expect(conflictedTag.content.conflict_of).to.equal(originalTag.uuid)
|
||||
expect(conflictedTag.noteCount).to.equal(originalTag.noteCount)
|
||||
|
||||
expect(this.application.itemManager.itemsReferencingItem(conflictedTag).length).to.equal(0)
|
||||
expect(this.application.itemManager.itemsReferencingItem(originalTag).length).to.equal(0)
|
||||
expect(this.application.items.itemsReferencingItem(conflictedTag).length).to.equal(0)
|
||||
expect(this.application.items.itemsReferencingItem(originalTag).length).to.equal(0)
|
||||
|
||||
// Two tags now link to this note
|
||||
const referencingItems = this.application.itemManager.itemsReferencingItem(note)
|
||||
const referencingItems = this.application.items.itemsReferencingItem(note)
|
||||
expect(referencingItems.length).to.equal(2)
|
||||
expect(referencingItems[0]).to.not.equal(referencingItems[1])
|
||||
}).timeout(10000)
|
||||
|
||||
@@ -19,7 +19,7 @@ describe('offline syncing', () => {
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
expect(this.application.syncService.isOutOfSync()).to.equal(false)
|
||||
expect(this.application.sync.isOutOfSync()).to.equal(false)
|
||||
await Factory.safeDeinit(this.application)
|
||||
})
|
||||
|
||||
@@ -38,19 +38,19 @@ describe('offline syncing', () => {
|
||||
await Factory.alternateUuidForItem(this.application, note.uuid)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
const notes = this.application.itemManager.getDisplayableNotes()
|
||||
const notes = this.application.items.getDisplayableNotes()
|
||||
expect(notes.length).to.equal(1)
|
||||
expect(notes[0].uuid).to.not.equal(note.uuid)
|
||||
|
||||
const items = this.application.itemManager.allTrackedItems()
|
||||
const items = this.application.items.allTrackedItems()
|
||||
expect(items.length).to.equal(this.expectedItemCount)
|
||||
})
|
||||
|
||||
it('should sync item with no passcode', async function () {
|
||||
let note = await Factory.createMappedNote(this.application)
|
||||
expect(Uuids(this.application.itemManager.getDirtyItems()).includes(note.uuid))
|
||||
expect(Uuids(this.application.items.getDirtyItems()).includes(note.uuid))
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
note = this.application.items.findItem(note.uuid)
|
||||
|
||||
@@ -59,9 +59,9 @@ describe('offline syncing', () => {
|
||||
|
||||
this.expectedItemCount++
|
||||
|
||||
expect(this.application.itemManager.getDirtyItems().length).to.equal(0)
|
||||
expect(this.application.items.getDirtyItems().length).to.equal(0)
|
||||
|
||||
const rawPayloads2 = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads2 = await this.application.storage.getAllRawPayloads()
|
||||
expect(rawPayloads2.length).to.equal(this.expectedItemCount)
|
||||
|
||||
const itemsKeyRaw = (await Factory.getStoragePayloadsOfType(this.application, ContentType.TYPES.ItemsKey))[0]
|
||||
@@ -77,26 +77,26 @@ describe('offline syncing', () => {
|
||||
it('should sync item encrypted with passcode', async function () {
|
||||
await this.application.addPasscode('foobar')
|
||||
await Factory.createMappedNote(this.application)
|
||||
expect(this.application.itemManager.getDirtyItems().length).to.equal(1)
|
||||
const rawPayloads1 = await this.application.diskStorageService.getAllRawPayloads()
|
||||
expect(this.application.items.getDirtyItems().length).to.equal(1)
|
||||
const rawPayloads1 = await this.application.storage.getAllRawPayloads()
|
||||
expect(rawPayloads1.length).to.equal(this.expectedItemCount)
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
this.expectedItemCount++
|
||||
|
||||
expect(this.application.itemManager.getDirtyItems().length).to.equal(0)
|
||||
const rawPayloads2 = await this.application.diskStorageService.getAllRawPayloads()
|
||||
expect(this.application.items.getDirtyItems().length).to.equal(0)
|
||||
const rawPayloads2 = await this.application.storage.getAllRawPayloads()
|
||||
expect(rawPayloads2.length).to.equal(this.expectedItemCount)
|
||||
|
||||
const payload = rawPayloads2[0]
|
||||
expect(typeof payload.content).to.equal('string')
|
||||
expect(payload.content.startsWith(this.application.encryptionService.getLatestVersion())).to.equal(true)
|
||||
expect(payload.content.startsWith(this.application.encryption.getLatestVersion())).to.equal(true)
|
||||
})
|
||||
|
||||
it('signing out while offline should succeed', async function () {
|
||||
await Factory.createMappedNote(this.application)
|
||||
this.expectedItemCount++
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
expect(this.application.noAccount()).to.equal(true)
|
||||
expect(this.application.getUser()).to.not.be.ok
|
||||
|
||||
@@ -42,12 +42,12 @@ describe('online syncing', function () {
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
expect(this.application.syncService.isOutOfSync()).to.equal(false)
|
||||
expect(this.application.sync.isOutOfSync()).to.equal(false)
|
||||
|
||||
const items = this.application.itemManager.allTrackedItems()
|
||||
const items = this.application.items.allTrackedItems()
|
||||
expect(items.length).to.equal(this.expectedItemCount)
|
||||
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
expect(rawPayloads.length).to.equal(this.expectedItemCount)
|
||||
await Factory.safeDeinit(this.application)
|
||||
localStorage.clear()
|
||||
@@ -60,11 +60,11 @@ describe('online syncing', function () {
|
||||
it('should register and sync basic model online', async function () {
|
||||
let note = await Factory.createSyncedNote(this.application)
|
||||
this.expectedItemCount++
|
||||
expect(this.application.itemManager.getDirtyItems().length).to.equal(0)
|
||||
expect(this.application.items.getDirtyItems().length).to.equal(0)
|
||||
note = this.application.items.findItem(note.uuid)
|
||||
expect(note.dirty).to.not.be.ok
|
||||
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
const notePayloads = noteObjectsFromObjects(rawPayloads)
|
||||
expect(notePayloads.length).to.equal(1)
|
||||
for (const rawNote of notePayloads) {
|
||||
@@ -83,7 +83,7 @@ describe('online syncing', function () {
|
||||
password: this.password,
|
||||
})
|
||||
|
||||
const notes = this.application.itemManager.getDisplayableNotes()
|
||||
const notes = this.application.items.getDisplayableNotes()
|
||||
expect(notes.length).to.equal(1)
|
||||
expect(notes[0].title).to.equal(note.title)
|
||||
})
|
||||
@@ -99,7 +99,7 @@ describe('online syncing', function () {
|
||||
|
||||
this.application = await this.context.signout()
|
||||
|
||||
expect(this.application.itemManager.items.length).to.equal(BaseItemCounts.DefaultItems)
|
||||
expect(this.application.items.items.length).to.equal(BaseItemCounts.DefaultItems)
|
||||
|
||||
const promise = Factory.loginToApplication({
|
||||
application: this.application,
|
||||
@@ -132,7 +132,7 @@ describe('online syncing', function () {
|
||||
mergeLocal: true,
|
||||
})
|
||||
|
||||
const notes = this.application.itemManager.getDisplayableNotes()
|
||||
const notes = this.application.items.getDisplayableNotes()
|
||||
expect(notes.length).to.equal(1)
|
||||
/** uuid should have been alternated */
|
||||
expect(notes[0].uuid).to.equal(note.uuid)
|
||||
@@ -143,8 +143,8 @@ describe('online syncing', function () {
|
||||
let successes = 0
|
||||
let events = 0
|
||||
|
||||
this.application.syncService.ut_beginLatencySimulator(250)
|
||||
this.application.syncService.addEventObserver((event, data) => {
|
||||
this.application.sync.ut_beginLatencySimulator(250)
|
||||
this.application.sync.addEventObserver((event, data) => {
|
||||
if (event === SyncEvent.SyncCompletedWithAllItemsUploaded) {
|
||||
events++
|
||||
}
|
||||
@@ -153,7 +153,7 @@ describe('online syncing', function () {
|
||||
const promises = []
|
||||
for (let i = 0; i < syncCount; i++) {
|
||||
promises.push(
|
||||
this.application.syncService
|
||||
this.application.sync
|
||||
.sync({
|
||||
queueStrategy: SyncQueueStrategy.ResolveOnNext,
|
||||
})
|
||||
@@ -169,7 +169,7 @@ describe('online syncing', function () {
|
||||
// We don't know how many will execute above.
|
||||
expect(events).to.be.at.least(1)
|
||||
|
||||
this.application.syncService.ut_endLatencySimulator()
|
||||
this.application.sync.ut_endLatencySimulator()
|
||||
// Since the syncs all happen after one another, extra syncs may be queued on that we are not awaiting.
|
||||
await Factory.sleep(0.5)
|
||||
})
|
||||
@@ -179,9 +179,9 @@ describe('online syncing', function () {
|
||||
let successes = 0
|
||||
let events = 0
|
||||
|
||||
this.application.syncService.ut_beginLatencySimulator(250)
|
||||
this.application.sync.ut_beginLatencySimulator(250)
|
||||
|
||||
this.application.syncService.addEventObserver((event, data) => {
|
||||
this.application.sync.addEventObserver((event, data) => {
|
||||
if (event === SyncEvent.SyncCompletedWithAllItemsUploaded) {
|
||||
events++
|
||||
}
|
||||
@@ -190,7 +190,7 @@ describe('online syncing', function () {
|
||||
const promises = []
|
||||
for (let i = 0; i < syncCount; i++) {
|
||||
promises.push(
|
||||
this.application.syncService
|
||||
this.application.sync
|
||||
.sync({
|
||||
queueStrategy: SyncQueueStrategy.ForceSpawnNew,
|
||||
})
|
||||
@@ -202,7 +202,7 @@ describe('online syncing', function () {
|
||||
await Promise.all(promises)
|
||||
expect(successes).to.equal(syncCount)
|
||||
expect(events).to.equal(syncCount)
|
||||
this.application.syncService.ut_endLatencySimulator()
|
||||
this.application.sync.ut_endLatencySimulator()
|
||||
})
|
||||
|
||||
it('retrieving new items should not mark them as dirty', async function () {
|
||||
@@ -211,7 +211,7 @@ describe('online syncing', function () {
|
||||
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
const promise = new Promise((resolve) => {
|
||||
this.application.syncService.addEventObserver(async (event) => {
|
||||
this.application.sync.addEventObserver(async (event) => {
|
||||
if (event === SyncEvent.PaginatedSyncRequestCompleted) {
|
||||
const note = this.application.items.findItem(originalNote.uuid)
|
||||
if (note) {
|
||||
@@ -226,22 +226,22 @@ describe('online syncing', function () {
|
||||
})
|
||||
|
||||
it('allows saving of data after sign out', async function () {
|
||||
expect(this.application.itemManager.getDisplayableItemsKeys().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableItemsKeys().length).to.equal(1)
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
expect(this.application.itemManager.getDisplayableItemsKeys().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableItemsKeys().length).to.equal(1)
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
this.expectedItemCount++
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
await this.application.sync.sync(syncOptions)
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
const notePayload = noteObjectsFromObjects(rawPayloads)
|
||||
expect(notePayload.length).to.equal(1)
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(1)
|
||||
|
||||
// set item to be merged for when sign in occurs
|
||||
await this.application.syncService.markAllItemsAsNeedingSyncAndPersist()
|
||||
expect(this.application.syncService.isOutOfSync()).to.equal(false)
|
||||
expect(this.application.itemManager.getDirtyItems().length).to.equal(BaseItemCounts.DefaultItems + 1)
|
||||
await this.application.sync.markAllItemsAsNeedingSyncAndPersist()
|
||||
expect(this.application.sync.isOutOfSync()).to.equal(false)
|
||||
expect(this.application.items.getDirtyItems().length).to.equal(BaseItemCounts.DefaultItems + 1)
|
||||
|
||||
// Sign back in for next tests
|
||||
await Factory.loginToApplication({
|
||||
@@ -250,16 +250,16 @@ describe('online syncing', function () {
|
||||
password: this.password,
|
||||
})
|
||||
|
||||
expect(this.application.itemManager.getDirtyItems().length).to.equal(0)
|
||||
expect(this.application.itemManager.getDisplayableItemsKeys().length).to.equal(1)
|
||||
expect(this.application.syncService.isOutOfSync()).to.equal(false)
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.items.getDirtyItems().length).to.equal(0)
|
||||
expect(this.application.items.getDisplayableItemsKeys().length).to.equal(1)
|
||||
expect(this.application.sync.isOutOfSync()).to.equal(false)
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(1)
|
||||
|
||||
for (const item of this.application.itemManager.getDisplayableNotes()) {
|
||||
for (const item of this.application.items.getDisplayableNotes()) {
|
||||
expect(item.content.title).to.be.ok
|
||||
}
|
||||
|
||||
const updatedRawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const updatedRawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
for (const payload of updatedRawPayloads) {
|
||||
// if an item comes back from the server, it is saved to disk immediately without a dirty value.
|
||||
expect(payload.dirty).to.not.be.ok
|
||||
@@ -274,10 +274,10 @@ describe('online syncing', function () {
|
||||
const originalTitle = note.content.title
|
||||
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
const encrypted = CreateEncryptedServerSyncPushPayload(
|
||||
await this.application.encryptionService.encryptSplitSingle({
|
||||
await this.application.encryption.encryptSplitSingle({
|
||||
usesItemsKeyWithKeyLookup: {
|
||||
items: [note.payloadRepresentation()],
|
||||
},
|
||||
@@ -291,11 +291,11 @@ describe('online syncing', function () {
|
||||
|
||||
const items = await this.application.mutator.emitItemsFromPayloads([errorred], PayloadEmitSource.LocalChanged)
|
||||
|
||||
const mappedItem = this.application.itemManager.findAnyItem(errorred.uuid)
|
||||
const mappedItem = this.application.items.findAnyItem(errorred.uuid)
|
||||
|
||||
expect(typeof mappedItem.content).to.equal('string')
|
||||
|
||||
const decryptedPayload = await this.application.encryptionService.decryptSplitSingle({
|
||||
const decryptedPayload = await this.application.encryption.decryptSplitSingle({
|
||||
usesItemsKeyWithKeyLookup: {
|
||||
items: [errorred],
|
||||
},
|
||||
@@ -319,7 +319,7 @@ describe('online syncing', function () {
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
await this.application.signIn(this.email, this.password, undefined, undefined, undefined, true)
|
||||
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
})
|
||||
|
||||
it('removes item from storage upon deletion', async function () {
|
||||
@@ -327,41 +327,41 @@ describe('online syncing', function () {
|
||||
this.expectedItemCount++
|
||||
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
note = this.application.items.findItem(note.uuid)
|
||||
expect(note.dirty).to.equal(false)
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
|
||||
await this.application.mutator.setItemToBeDeleted(note)
|
||||
note = this.application.items.findAnyItem(note.uuid)
|
||||
expect(note.dirty).to.equal(true)
|
||||
this.expectedItemCount--
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
note = this.application.items.findItem(note.uuid)
|
||||
expect(note).to.not.be.ok
|
||||
|
||||
// We expect that this item is now gone for good, and no duplicate has been created.
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
await Factory.sleep(0.5)
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
expect(rawPayloads.length).to.equal(this.expectedItemCount)
|
||||
})
|
||||
|
||||
it('retrieving item with no content should correctly map local state', async function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
const syncToken = await this.application.syncService.getLastSyncToken()
|
||||
const syncToken = await this.application.sync.getLastSyncToken()
|
||||
|
||||
this.expectedItemCount++
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
|
||||
// client A
|
||||
await this.application.mutator.setItemToBeDeleted(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
// Subtract 1
|
||||
this.expectedItemCount--
|
||||
@@ -369,10 +369,10 @@ describe('online syncing', function () {
|
||||
// client B
|
||||
// Clearing sync tokens wont work as server wont return deleted items.
|
||||
// Set saved sync token instead
|
||||
await this.application.syncService.setLastSyncToken(syncToken)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.setLastSyncToken(syncToken)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
})
|
||||
|
||||
it('changing an item while it is being synced should sync again', async function () {
|
||||
@@ -381,7 +381,7 @@ describe('online syncing', function () {
|
||||
this.expectedItemCount++
|
||||
|
||||
/** Begin syncing it with server but introduce latency so we can sneak in a delete */
|
||||
this.application.syncService.ut_beginLatencySimulator(500)
|
||||
this.application.sync.ut_beginLatencySimulator(500)
|
||||
|
||||
const sync = this.application.sync.sync()
|
||||
|
||||
@@ -395,11 +395,11 @@ describe('online syncing', function () {
|
||||
|
||||
await sync
|
||||
|
||||
this.application.syncService.ut_endLatencySimulator()
|
||||
this.application.sync.ut_endLatencySimulator()
|
||||
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
const latestNote = this.application.itemManager.findItem(note.uuid)
|
||||
const latestNote = this.application.items.findItem(note.uuid)
|
||||
expect(latestNote.title).to.equal('latest title')
|
||||
})
|
||||
|
||||
@@ -409,7 +409,7 @@ describe('online syncing', function () {
|
||||
this.expectedItemCount++
|
||||
|
||||
/** Begin syncing it with server but introduce latency so we can sneak in a delete */
|
||||
this.application.syncService.ut_beginLatencySimulator(500)
|
||||
this.application.sync.ut_beginLatencySimulator(500)
|
||||
|
||||
const sync = this.application.sync.sync()
|
||||
|
||||
@@ -423,12 +423,12 @@ describe('online syncing', function () {
|
||||
|
||||
await sync
|
||||
|
||||
this.application.syncService.ut_endLatencySimulator()
|
||||
this.application.sync.ut_endLatencySimulator()
|
||||
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
/** We expect that item has been deleted */
|
||||
const allItems = this.application.itemManager.items
|
||||
const allItems = this.application.items.items
|
||||
expect(allItems.length).to.equal(this.expectedItemCount)
|
||||
})
|
||||
|
||||
@@ -440,7 +440,7 @@ describe('online syncing', function () {
|
||||
let success = true
|
||||
let didCompleteRelevantSync = false
|
||||
let beginCheckingResponse = false
|
||||
this.application.syncService.addEventObserver((eventName, data) => {
|
||||
this.application.sync.addEventObserver((eventName, data) => {
|
||||
if (eventName === SyncEvent.DownloadFirstSyncCompleted) {
|
||||
beginCheckingResponse = true
|
||||
}
|
||||
@@ -456,7 +456,7 @@ describe('online syncing', function () {
|
||||
}
|
||||
}
|
||||
})
|
||||
await this.application.syncService.sync({ mode: SyncMode.DownloadFirst })
|
||||
await this.application.sync.sync({ mode: SyncMode.DownloadFirst })
|
||||
expect(didCompleteRelevantSync).to.equal(true)
|
||||
expect(success).to.equal(true)
|
||||
})
|
||||
@@ -469,7 +469,7 @@ describe('online syncing', function () {
|
||||
let success = true
|
||||
let didCompleteRelevantSync = false
|
||||
let beginCheckingResponse = false
|
||||
this.application.syncService.addEventObserver(async (eventName, data) => {
|
||||
this.application.sync.addEventObserver(async (eventName, data) => {
|
||||
if (eventName === SyncEvent.DownloadFirstSyncCompleted) {
|
||||
await this.application.mutator.setItemToBeDeleted(note)
|
||||
beginCheckingResponse = true
|
||||
@@ -486,7 +486,7 @@ describe('online syncing', function () {
|
||||
}
|
||||
}
|
||||
})
|
||||
await this.application.syncService.sync({ mode: SyncMode.DownloadFirst })
|
||||
await this.application.sync.sync({ mode: SyncMode.DownloadFirst })
|
||||
expect(didCompleteRelevantSync).to.equal(true)
|
||||
expect(success).to.equal(true)
|
||||
})
|
||||
@@ -496,16 +496,16 @@ describe('online syncing', function () {
|
||||
|
||||
this.expectedItemCount++
|
||||
|
||||
await this.application.syncService.markAllItemsAsNeedingSyncAndPersist()
|
||||
await this.application.sync.markAllItemsAsNeedingSyncAndPersist()
|
||||
|
||||
this.application.itemManager.resetState()
|
||||
this.application.payloadManager.resetState()
|
||||
this.application.items.resetState()
|
||||
this.application.payloads.resetState()
|
||||
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
|
||||
expect(this.application.itemManager.items.length).to.equal(0)
|
||||
expect(this.application.items.items.length).to.equal(0)
|
||||
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
|
||||
const encryptedPayloads = rawPayloads.map((rawPayload) => {
|
||||
return new EncryptedPayload(rawPayload)
|
||||
@@ -515,17 +515,17 @@ describe('online syncing', function () {
|
||||
|
||||
const keyedSplit = CreateDecryptionSplitWithKeyLookup(encryptionSplit)
|
||||
|
||||
const decryptionResults = await this.application.encryptionService.decryptSplit(keyedSplit)
|
||||
const decryptionResults = await this.application.encryption.decryptSplit(keyedSplit)
|
||||
|
||||
await this.application.mutator.emitItemsFromPayloads(decryptionResults, PayloadEmitSource.LocalChanged)
|
||||
|
||||
expect(this.application.itemManager.allTrackedItems().length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.allTrackedItems().length).to.equal(this.expectedItemCount)
|
||||
|
||||
const foundNote = this.application.itemManager.findAnyItem(note.uuid)
|
||||
const foundNote = this.application.items.findAnyItem(note.uuid)
|
||||
|
||||
expect(foundNote.dirty).to.equal(true)
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
})
|
||||
|
||||
/** Temporarily skipping due to long run time */
|
||||
@@ -538,8 +538,8 @@ describe('online syncing', function () {
|
||||
|
||||
this.expectedItemCount += largeItemCount
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
await this.application.sync.sync(syncOptions)
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
expect(rawPayloads.length).to.equal(this.expectedItemCount)
|
||||
}).timeout(15000)
|
||||
|
||||
@@ -551,32 +551,32 @@ describe('online syncing', function () {
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
}
|
||||
/** Upload */
|
||||
this.application.syncService.sync({ awaitAll: true, checkIntegrity: false })
|
||||
this.application.sync.sync({ awaitAll: true, checkIntegrity: false })
|
||||
await this.context.awaitNextSucessfulSync()
|
||||
this.expectedItemCount += largeItemCount
|
||||
|
||||
/** Clear local data */
|
||||
await this.application.payloadManager.resetState()
|
||||
await this.application.itemManager.resetState()
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.diskStorageService.clearAllPayloads()
|
||||
expect(this.application.itemManager.items.length).to.equal(0)
|
||||
await this.application.payloads.resetState()
|
||||
await this.application.items.resetState()
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
await this.application.storage.clearAllPayloads()
|
||||
expect(this.application.items.items.length).to.equal(0)
|
||||
|
||||
/** Download all data */
|
||||
this.application.syncService.sync(syncOptions)
|
||||
this.application.sync.sync(syncOptions)
|
||||
await this.context.awaitNextSucessfulSync()
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
expect(rawPayloads.length).to.equal(this.expectedItemCount)
|
||||
}).timeout(30000)
|
||||
|
||||
it('syncing an item should storage it encrypted', async function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
this.expectedItemCount++
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
const notePayload = rawPayloads.find((p) => p.content_type === ContentType.TYPES.Note)
|
||||
expect(typeof notePayload.content).to.equal('string')
|
||||
})
|
||||
@@ -587,12 +587,12 @@ describe('online syncing', function () {
|
||||
this.expectedItemCount++
|
||||
|
||||
/** Simulate database not loaded */
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
this.application.syncService.ut_setDatabaseLoaded(false)
|
||||
this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
this.application.sync.ut_setDatabaseLoaded(false)
|
||||
this.application.sync.sync(syncOptions)
|
||||
await Factory.sleep(0.3)
|
||||
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
const notePayload = rawPayloads.find((p) => p.content_type === ContentType.TYPES.Note)
|
||||
expect(typeof notePayload.content).to.equal('string')
|
||||
})
|
||||
@@ -610,18 +610,18 @@ describe('online syncing', function () {
|
||||
syncOptions,
|
||||
)
|
||||
this.expectedItemCount++
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
const notePayload = rawPayloads.find((p) => p.content_type === ContentType.TYPES.Note)
|
||||
expect(typeof notePayload.content).to.equal('string')
|
||||
expect(notePayload.content.length).to.be.above(text.length)
|
||||
})
|
||||
|
||||
it('syncing a new item before local data has loaded should still persist the item to disk', async function () {
|
||||
this.application.syncService.ut_setDatabaseLoaded(false)
|
||||
this.application.sync.ut_setDatabaseLoaded(false)
|
||||
/** You don't want to clear model manager state as we'll lose encrypting items key */
|
||||
// await this.application.payloadManager.resetState();
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
expect(this.application.itemManager.getDirtyItems().length).to.equal(0)
|
||||
// await this.application.payloads.resetState();
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
expect(this.application.items.getDirtyItems().length).to.equal(0)
|
||||
|
||||
let note = await Factory.createMappedNote(this.application)
|
||||
note = await this.application.mutator.changeItem(note, (mutator) => {
|
||||
@@ -629,15 +629,15 @@ describe('online syncing', function () {
|
||||
})
|
||||
/** This sync request should exit prematurely as we called ut_setDatabaseNotLoaded */
|
||||
/** Do not await. Sleep instead. */
|
||||
this.application.syncService.sync(syncOptions)
|
||||
this.application.sync.sync(syncOptions)
|
||||
await Factory.sleep(0.3)
|
||||
this.expectedItemCount++
|
||||
|
||||
/** Item should still be dirty */
|
||||
expect(note.dirty).to.equal(true)
|
||||
expect(this.application.itemManager.getDirtyItems().length).to.equal(1)
|
||||
expect(this.application.items.getDirtyItems().length).to.equal(1)
|
||||
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const rawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
expect(rawPayloads.length).to.equal(this.expectedItemCount)
|
||||
const rawPayload = rawPayloads.find((p) => p.uuid === note.uuid)
|
||||
expect(rawPayload.uuid).to.equal(note.uuid)
|
||||
@@ -645,16 +645,16 @@ describe('online syncing', function () {
|
||||
expect(typeof rawPayload.content).to.equal('string')
|
||||
|
||||
/** Clear state data and upload item from storage to server */
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.payloadManager.resetState()
|
||||
await this.application.itemManager.resetState()
|
||||
await this.application.syncService.loadDatabasePayloads()
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
await this.application.payloads.resetState()
|
||||
await this.application.items.resetState()
|
||||
await this.application.sync.loadDatabasePayloads()
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
const newRawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const newRawPayloads = await this.application.storage.getAllRawPayloads()
|
||||
expect(newRawPayloads.length).to.equal(this.expectedItemCount)
|
||||
|
||||
const currentItem = this.application.itemManager.findItem(note.uuid)
|
||||
const currentItem = this.application.items.findItem(note.uuid)
|
||||
expect(currentItem.content.text).to.equal(note.content.text)
|
||||
expect(currentItem.text).to.equal(note.text)
|
||||
expect(currentItem.dirty).to.not.be.ok
|
||||
@@ -680,16 +680,16 @@ describe('online syncing', function () {
|
||||
const largeItemCount = 50
|
||||
await Factory.createManyMappedNotes(this.application, largeItemCount)
|
||||
this.expectedItemCount += largeItemCount
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
await this.application.signIn(this.email, this.password, undefined, undefined, undefined, true)
|
||||
|
||||
this.application.syncService.ut_setDatabaseLoaded(false)
|
||||
await this.application.syncService.loadDatabasePayloads()
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
this.application.sync.ut_setDatabaseLoaded(false)
|
||||
await this.application.sync.loadDatabasePayloads()
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
const items = await this.application.itemManager.items
|
||||
const items = await this.application.items.items
|
||||
expect(items.length).to.equal(this.expectedItemCount)
|
||||
}).timeout(20000)
|
||||
|
||||
@@ -717,7 +717,7 @@ describe('online syncing', function () {
|
||||
it('syncing twice without waiting should only execute 1 online sync', async function () {
|
||||
const expectedEvents = 1
|
||||
let actualEvents = 0
|
||||
this.application.syncService.addEventObserver((event, data) => {
|
||||
this.application.sync.addEventObserver((event, data) => {
|
||||
if (event === SyncEvent.SyncCompletedWithAllItemsUploaded && data.source === SyncSource.External) {
|
||||
actualEvents++
|
||||
}
|
||||
@@ -742,8 +742,8 @@ describe('online syncing', function () {
|
||||
this.expectedItemCount++
|
||||
|
||||
// client A. Don't await, we want to do other stuff.
|
||||
this.application.syncService.ut_beginLatencySimulator(1500)
|
||||
const slowSync = this.application.syncService.sync(syncOptions)
|
||||
this.application.sync.ut_beginLatencySimulator(1500)
|
||||
const slowSync = this.application.sync.sync(syncOptions)
|
||||
await Factory.sleep(0.1)
|
||||
expect(note.dirty).to.equal(true)
|
||||
|
||||
@@ -758,8 +758,8 @@ describe('online syncing', function () {
|
||||
expect(note.payload.dirtyIndex).to.be.above(note.payload.globalDirtyIndexAtLastSync)
|
||||
|
||||
// Now do a regular sync with no latency.
|
||||
this.application.syncService.ut_endLatencySimulator()
|
||||
const midSync = this.application.syncService.sync(syncOptions)
|
||||
this.application.sync.ut_endLatencySimulator()
|
||||
const midSync = this.application.sync.sync(syncOptions)
|
||||
|
||||
await slowSync
|
||||
await midSync
|
||||
@@ -770,14 +770,14 @@ describe('online syncing', function () {
|
||||
expect(note.content.text).to.equal(text)
|
||||
|
||||
// client B
|
||||
await this.application.payloadManager.resetState()
|
||||
await this.application.itemManager.resetState()
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.payloads.resetState()
|
||||
await this.application.items.resetState()
|
||||
await this.application.sync.clearSyncPositionTokens()
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
// Expect that the server value and client value match, and no conflicts are created.
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
const foundItem = this.application.itemManager.findItem(note.uuid)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
const foundItem = this.application.items.findItem(note.uuid)
|
||||
expect(foundItem.content.text).to.equal(text)
|
||||
expect(foundItem.text).to.equal(text)
|
||||
})
|
||||
@@ -790,17 +790,17 @@ describe('online syncing', function () {
|
||||
/** Create an item and sync it */
|
||||
let note = await Factory.createMappedNote(this.application)
|
||||
|
||||
this.application.itemManager.addObserver(ContentType.TYPES.Note, ({ source }) => {
|
||||
this.application.items.addObserver(ContentType.TYPES.Note, ({ source }) => {
|
||||
if (source === PayloadEmitSource.RemoteSaved) {
|
||||
actualSaveCount++
|
||||
}
|
||||
})
|
||||
|
||||
this.expectedItemCount++
|
||||
this.application.syncService.ut_beginLatencySimulator(150)
|
||||
this.application.sync.ut_beginLatencySimulator(150)
|
||||
|
||||
/** Dont await */
|
||||
const syncRequest = this.application.syncService.sync(syncOptions)
|
||||
const syncRequest = this.application.sync.sync(syncOptions)
|
||||
|
||||
/** Dirty the item 100ms into 150ms request */
|
||||
const newText = `${Math.random()}`
|
||||
@@ -837,7 +837,7 @@ describe('online syncing', function () {
|
||||
/** Create an item and sync it */
|
||||
let note = await Factory.createMappedNote(this.application)
|
||||
|
||||
this.application.itemManager.addObserver(ContentType.TYPES.Note, ({ source }) => {
|
||||
this.application.items.addObserver(ContentType.TYPES.Note, ({ source }) => {
|
||||
if (source === PayloadEmitSource.RemoteSaved) {
|
||||
actualSaveCount++
|
||||
}
|
||||
@@ -845,13 +845,13 @@ describe('online syncing', function () {
|
||||
this.expectedItemCount++
|
||||
|
||||
/** Dont await */
|
||||
const syncRequest = this.application.syncService.sync(syncOptions)
|
||||
const syncRequest = this.application.sync.sync(syncOptions)
|
||||
|
||||
/** Dirty the item before lastSyncBegan is set */
|
||||
let didPerformMutatation = false
|
||||
const newText = `${Math.random()}`
|
||||
|
||||
this.application.syncService.addEventObserver(async (eventName) => {
|
||||
this.application.sync.addEventObserver(async (eventName) => {
|
||||
if (eventName === SyncEvent.SyncDidBeginProcessing && !didPerformMutatation) {
|
||||
didPerformMutatation = true
|
||||
await this.application.mutator.changeItem(note, (mutator) => {
|
||||
@@ -876,7 +876,7 @@ describe('online syncing', function () {
|
||||
let didPerformMutatation = false
|
||||
const newText = `${Math.random()}`
|
||||
|
||||
this.application.itemManager.addObserver(ContentType.TYPES.Note, async ({ changed, source }) => {
|
||||
this.application.items.addObserver(ContentType.TYPES.Note, async ({ changed, source }) => {
|
||||
if (source === PayloadEmitSource.RemoteSaved) {
|
||||
actualSaveCount++
|
||||
} else if (source === PayloadEmitSource.PreSyncSave && !didPerformMutatation) {
|
||||
@@ -895,7 +895,7 @@ describe('online syncing', function () {
|
||||
this.expectedItemCount++
|
||||
|
||||
/** Dont await */
|
||||
const syncRequest = this.application.syncService.sync(syncOptions)
|
||||
const syncRequest = this.application.sync.sync(syncOptions)
|
||||
await syncRequest
|
||||
expect(actualSaveCount).to.equal(expectedSaveCount)
|
||||
note = this.application.items.findItem(note.uuid)
|
||||
@@ -904,12 +904,12 @@ describe('online syncing', function () {
|
||||
|
||||
it('retreiving a remote deleted item should succeed', async function () {
|
||||
const note = await Factory.createSyncedNote(this.application)
|
||||
const preDeleteSyncToken = await this.application.syncService.getLastSyncToken()
|
||||
const preDeleteSyncToken = await this.application.sync.getLastSyncToken()
|
||||
await this.application.mutator.deleteItem(note)
|
||||
await this.application.sync.sync()
|
||||
await this.application.syncService.setLastSyncToken(preDeleteSyncToken)
|
||||
await this.application.sync.setLastSyncToken(preDeleteSyncToken)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
expect(this.application.items.items.length).to.equal(this.expectedItemCount)
|
||||
})
|
||||
|
||||
it('errored items should not be synced', async function () {
|
||||
@@ -918,7 +918,7 @@ describe('online syncing', function () {
|
||||
const lastSyncBegan = note.lastSyncBegan
|
||||
const lastSyncEnd = note.lastSyncEnd
|
||||
|
||||
const encrypted = await this.application.encryptionService.encryptSplitSingle({
|
||||
const encrypted = await this.application.encryption.encryptSplitSingle({
|
||||
usesItemsKeyWithKeyLookup: {
|
||||
items: [note.payload],
|
||||
},
|
||||
@@ -929,7 +929,7 @@ describe('online syncing', function () {
|
||||
dirty: true,
|
||||
})
|
||||
|
||||
await this.application.payloadManager.emitPayload(errored)
|
||||
await this.application.payloads.emitPayload(errored)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
const updatedNote = this.application.items.findAnyItem(note.uuid)
|
||||
@@ -957,10 +957,10 @@ describe('online syncing', function () {
|
||||
},
|
||||
})
|
||||
|
||||
await this.application.syncService.handleSuccessServerResponse({ payloadsSavedOrSaving: [], options: {} }, response)
|
||||
await this.application.sync.handleSuccessServerResponse({ payloadsSavedOrSaving: [], options: {} }, response)
|
||||
|
||||
expect(this.application.payloadManager.findOne(invalidPayload.uuid)).to.not.be.ok
|
||||
expect(this.application.payloadManager.findOne(validPayload.uuid)).to.be.ok
|
||||
expect(this.application.payloads.findOne(invalidPayload.uuid)).to.not.be.ok
|
||||
expect(this.application.payloads.findOne(validPayload.uuid)).to.be.ok
|
||||
})
|
||||
|
||||
it('retrieved items should have both updated_at and updated_at_timestamps', async function () {
|
||||
@@ -996,13 +996,13 @@ describe('online syncing', function () {
|
||||
|
||||
it('should call onPresyncSave before sync begins', async function () {
|
||||
const events = []
|
||||
this.application.syncService.addEventObserver((event) => {
|
||||
this.application.sync.addEventObserver((event) => {
|
||||
if (event === SyncEvent.SyncDidBeginProcessing) {
|
||||
events.push('sync-will-begin')
|
||||
}
|
||||
})
|
||||
|
||||
await this.application.syncService.sync({
|
||||
await this.application.sync.sync({
|
||||
onPresyncSave: () => {
|
||||
events.push('on-presync-save')
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user