internal: incomplete vault systems behind feature flag (#2340)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable no-undef */
|
||||
import { BaseItemCounts } from '../lib/Applications.js'
|
||||
import { BaseItemCounts } from '../lib/BaseItemCounts.js'
|
||||
import * as Factory from '../lib/factory.js'
|
||||
import { createSyncedNoteWithTag } from '../lib/Items.js'
|
||||
import * as Utils from '../lib/Utils.js'
|
||||
@@ -16,7 +16,7 @@ describe('online conflict handling', function () {
|
||||
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
this.expectedItemCount = BaseItemCounts.DefaultItems
|
||||
this.expectedItemCount = BaseItemCounts.DefaultItemsWithAccount
|
||||
|
||||
this.context = await Factory.createAppContextWithFakeCrypto('AppA')
|
||||
await this.context.launch()
|
||||
@@ -64,7 +64,7 @@ describe('online conflict handling', function () {
|
||||
it('components should not be duplicated under any circumstances', async function () {
|
||||
const payload = createDirtyPayload(ContentType.Component)
|
||||
|
||||
const item = await this.application.itemManager.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
|
||||
const item = await this.application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
|
||||
|
||||
this.expectedItemCount++
|
||||
|
||||
@@ -91,7 +91,7 @@ describe('online conflict handling', function () {
|
||||
|
||||
it('items keys should not be duplicated under any circumstances', async function () {
|
||||
const payload = createDirtyPayload(ContentType.ItemsKey)
|
||||
const item = await this.application.itemManager.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
|
||||
const item = await this.application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
|
||||
this.expectedItemCount++
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
/** First modify the item without saving so that
|
||||
@@ -118,7 +118,7 @@ describe('online conflict handling', function () {
|
||||
// create an item and sync it
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
this.expectedItemCount++
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
@@ -128,11 +128,11 @@ describe('online conflict handling', function () {
|
||||
const dirtyValue = `${Math.random()}`
|
||||
|
||||
/** Modify nonsense first to get around strategyWhenConflictingWithItem with previousRevision check */
|
||||
await this.application.itemManager.changeNote(note, (mutator) => {
|
||||
await this.application.mutator.changeNote(note, (mutator) => {
|
||||
mutator.title = 'any'
|
||||
})
|
||||
|
||||
await this.application.itemManager.changeNote(note, (mutator) => {
|
||||
await this.application.mutator.changeNote(note, (mutator) => {
|
||||
// modify this item locally to have differing contents from server
|
||||
mutator.title = dirtyValue
|
||||
// Intentionally don't change updated_at. We want to simulate a chaotic case where
|
||||
@@ -238,7 +238,7 @@ describe('online conflict handling', function () {
|
||||
it('should duplicate item if saving a modified item and clearing our sync token', async function () {
|
||||
let note = await Factory.createMappedNote(this.application)
|
||||
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
|
||||
this.expectedItemCount++
|
||||
@@ -279,11 +279,11 @@ describe('online conflict handling', function () {
|
||||
it('should handle sync conflicts by not duplicating same data', async function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
this.expectedItemCount++
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
|
||||
// keep item as is and set dirty
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
|
||||
// clear sync token so that all items are retrieved on next sync
|
||||
this.application.syncService.clearSyncPositionTokens()
|
||||
@@ -295,10 +295,10 @@ describe('online conflict handling', function () {
|
||||
|
||||
it('clearing conflict_of on two clients simultaneously should keep us in sync', async function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
this.expectedItemCount++
|
||||
|
||||
await this.application.mutator.changeAndSaveItem(
|
||||
await this.application.changeAndSaveItem(
|
||||
note,
|
||||
(mutator) => {
|
||||
// client A
|
||||
@@ -311,7 +311,7 @@ describe('online conflict handling', function () {
|
||||
|
||||
// client B
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
await this.application.itemManager.changeItem(
|
||||
await this.application.mutator.changeItem(
|
||||
note,
|
||||
(mutator) => {
|
||||
mutator.mutableContent.conflict_of = 'bar'
|
||||
@@ -329,10 +329,10 @@ describe('online conflict handling', function () {
|
||||
|
||||
it('setting property on two clients simultaneously should create conflict', async function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
this.expectedItemCount++
|
||||
|
||||
await this.application.mutator.changeAndSaveItem(
|
||||
await this.application.changeAndSaveItem(
|
||||
note,
|
||||
(mutator) => {
|
||||
// client A
|
||||
@@ -369,12 +369,12 @@ describe('online conflict handling', function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
const originalPayload = note.payloadRepresentation()
|
||||
this.expectedItemCount++
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
|
||||
// client A
|
||||
await this.application.itemManager.setItemToBeDeleted(note)
|
||||
await this.application.mutator.setItemToBeDeleted(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
this.expectedItemCount--
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
@@ -387,10 +387,10 @@ describe('online conflict handling', function () {
|
||||
deleted: false,
|
||||
updated_at: Factory.yesterday(),
|
||||
})
|
||||
await this.application.itemManager.emitItemsFromPayloads([mutatedPayload], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([mutatedPayload], PayloadEmitSource.LocalChanged)
|
||||
const resultNote = this.application.itemManager.findItem(note.uuid)
|
||||
expect(resultNote.uuid).to.equal(note.uuid)
|
||||
await this.application.itemManager.setItemDirty(resultNote)
|
||||
await this.application.mutator.setItemDirty(resultNote)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
|
||||
// We expect that this item is now gone for good, and a duplicate has not been created.
|
||||
@@ -400,7 +400,7 @@ describe('online conflict handling', function () {
|
||||
|
||||
it('if server says not deleted but client says deleted, keep server state', async function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
this.expectedItemCount++
|
||||
|
||||
// client A
|
||||
@@ -426,7 +426,7 @@ describe('online conflict handling', function () {
|
||||
|
||||
it('should create conflict if syncing an item that is stale', async function () {
|
||||
let note = await Factory.createMappedNote(this.application)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
note = this.application.items.findItem(note.uuid)
|
||||
expect(note.dirty).to.equal(false)
|
||||
@@ -462,7 +462,7 @@ describe('online conflict handling', function () {
|
||||
|
||||
it('creating conflict with exactly equal content should keep us in sync', async function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
this.expectedItemCount++
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
@@ -505,7 +505,7 @@ describe('online conflict handling', function () {
|
||||
for (const note of this.application.itemManager.getDisplayableNotes()) {
|
||||
/** First modify the item without saving so that
|
||||
* our local contents digress from the server's */
|
||||
await this.application.itemManager.changeItem(note, (mutator) => {
|
||||
await this.application.mutator.changeItem(note, (mutator) => {
|
||||
mutator.text = '1'
|
||||
})
|
||||
|
||||
@@ -530,18 +530,18 @@ describe('online conflict handling', function () {
|
||||
const payload1 = Factory.createStorageItemPayload(ContentType.Tag)
|
||||
const payload2 = Factory.createStorageItemPayload(ContentType.UserPrefs)
|
||||
this.expectedItemCount -= 1 /** auto-created user preferences */
|
||||
await this.application.itemManager.emitItemsFromPayloads([payload1, payload2], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([payload1, payload2], PayloadEmitSource.LocalChanged)
|
||||
this.expectedItemCount += 2
|
||||
let tag = this.application.itemManager.getItems(ContentType.Tag)[0]
|
||||
let userPrefs = this.application.itemManager.getItems(ContentType.UserPrefs)[0]
|
||||
expect(tag).to.be.ok
|
||||
expect(userPrefs).to.be.ok
|
||||
|
||||
tag = await this.application.itemManager.changeItem(tag, (mutator) => {
|
||||
tag = await this.application.mutator.changeItem(tag, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(userPrefs)
|
||||
})
|
||||
|
||||
await this.application.itemManager.setItemDirty(userPrefs)
|
||||
await this.application.mutator.setItemDirty(userPrefs)
|
||||
userPrefs = this.application.items.findItem(userPrefs.uuid)
|
||||
|
||||
expect(this.application.itemManager.itemsReferencingItem(userPrefs).length).to.equal(1)
|
||||
@@ -599,7 +599,7 @@ describe('online conflict handling', function () {
|
||||
*/
|
||||
let tag = await Factory.createMappedTag(this.application)
|
||||
let note = await Factory.createMappedNote(this.application)
|
||||
tag = await this.application.mutator.changeAndSaveItem(
|
||||
tag = await this.application.changeAndSaveItem(
|
||||
tag,
|
||||
(mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(note)
|
||||
@@ -608,7 +608,7 @@ describe('online conflict handling', function () {
|
||||
undefined,
|
||||
syncOptions,
|
||||
)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
this.expectedItemCount += 2
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
@@ -663,18 +663,18 @@ describe('online conflict handling', function () {
|
||||
|
||||
const baseTitle = 'base title'
|
||||
/** Change the note */
|
||||
const noteAfterChange = await this.application.itemManager.changeItem(note, (mutator) => {
|
||||
const noteAfterChange = await this.application.mutator.changeItem(note, (mutator) => {
|
||||
mutator.title = baseTitle
|
||||
})
|
||||
await this.application.sync.sync()
|
||||
|
||||
/** Simulate a dropped response by reverting the note back its post-change, pre-sync state */
|
||||
const retroNote = await this.application.itemManager.emitItemFromPayload(noteAfterChange.payload)
|
||||
const retroNote = await this.application.mutator.emitItemFromPayload(noteAfterChange.payload)
|
||||
expect(retroNote.serverUpdatedAt.getTime()).to.equal(noteAfterChange.serverUpdatedAt.getTime())
|
||||
|
||||
/** Change the item to its final title and sync */
|
||||
const finalTitle = 'final title'
|
||||
await this.application.itemManager.changeItem(note, (mutator) => {
|
||||
await this.application.mutator.changeItem(note, (mutator) => {
|
||||
mutator.title = finalTitle
|
||||
})
|
||||
await this.application.sync.sync()
|
||||
@@ -708,7 +708,7 @@ describe('online conflict handling', function () {
|
||||
errorDecrypting: true,
|
||||
dirty: true,
|
||||
})
|
||||
await this.application.itemManager.emitItemsFromPayloads([errorred], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([errorred], PayloadEmitSource.LocalChanged)
|
||||
|
||||
/**
|
||||
* Retrieve this note from the server by clearing sync token
|
||||
@@ -758,7 +758,7 @@ describe('online conflict handling', function () {
|
||||
email: Utils.generateUuid(),
|
||||
password: Utils.generateUuid(),
|
||||
})
|
||||
await newApp.itemManager.emitItemsFromPayloads(priorData.map((i) => i.payload))
|
||||
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)
|
||||
@@ -786,7 +786,7 @@ describe('online conflict handling', function () {
|
||||
password: password,
|
||||
})
|
||||
Factory.handlePasswordChallenges(newApp, password)
|
||||
await newApp.mutator.importData(backupFile, true)
|
||||
await newApp.importData(backupFile, true)
|
||||
expect(newApp.itemManager.getDisplayableTags().length).to.equal(1)
|
||||
expect(newApp.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
await Factory.safeDeinit(newApp)
|
||||
@@ -801,7 +801,7 @@ describe('online conflict handling', function () {
|
||||
await createSyncedNoteWithTag(this.application)
|
||||
const tag = this.application.itemManager.getDisplayableTags()[0]
|
||||
const note2 = await Factory.createMappedNote(this.application)
|
||||
await this.application.mutator.changeAndSaveItem(tag, (mutator) => {
|
||||
await this.application.changeAndSaveItem(tag, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(note2)
|
||||
})
|
||||
let backupFile = await this.application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
@@ -821,7 +821,7 @@ describe('online conflict handling', function () {
|
||||
password: password,
|
||||
})
|
||||
Factory.handlePasswordChallenges(newApp, password)
|
||||
await newApp.mutator.importData(backupFile, true)
|
||||
await newApp.importData(backupFile, true)
|
||||
const newTag = newApp.itemManager.getDisplayableTags()[0]
|
||||
const notes = newApp.items.referencesForItem(newTag)
|
||||
expect(notes.length).to.equal(2)
|
||||
@@ -855,7 +855,7 @@ describe('online conflict handling', function () {
|
||||
},
|
||||
dirty: true,
|
||||
})
|
||||
await this.application.itemManager.emitItemFromPayload(modified)
|
||||
await this.application.mutator.emitItemFromPayload(modified)
|
||||
await this.application.sync.sync()
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
await this.sharedFinalAssertions()
|
||||
@@ -879,7 +879,7 @@ describe('online conflict handling', function () {
|
||||
dirty: true,
|
||||
})
|
||||
this.expectedItemCount++
|
||||
await this.application.itemManager.emitItemFromPayload(modified)
|
||||
await this.application.mutator.emitItemFromPayload(modified)
|
||||
await this.application.sync.sync()
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(2)
|
||||
await this.sharedFinalAssertions()
|
||||
@@ -911,7 +911,7 @@ describe('online conflict handling', function () {
|
||||
dirty: true,
|
||||
})
|
||||
this.expectedItemCount++
|
||||
await this.application.itemManager.emitItemFromPayload(modified)
|
||||
await this.application.mutator.emitItemFromPayload(modified)
|
||||
await this.application.sync.sync()
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(2)
|
||||
await this.sharedFinalAssertions()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable no-unused-expressions */
|
||||
/* eslint-disable no-undef */
|
||||
import { BaseItemCounts } from '../lib/Applications.js'
|
||||
import { BaseItemCounts } from '../lib/BaseItemCounts.js'
|
||||
import * as Factory from '../lib/factory.js'
|
||||
chai.use(chaiAsPromised)
|
||||
const expect = chai.expect
|
||||
@@ -15,7 +15,7 @@ describe('sync integrity', () => {
|
||||
})
|
||||
|
||||
beforeEach(async function () {
|
||||
this.expectedItemCount = BaseItemCounts.DefaultItems
|
||||
this.expectedItemCount = BaseItemCounts.DefaultItemsWithAccount
|
||||
this.application = await Factory.createInitAppWithFakeCrypto()
|
||||
this.email = UuidGenerator.GenerateUuid()
|
||||
this.password = UuidGenerator.GenerateUuid()
|
||||
@@ -44,7 +44,7 @@ describe('sync integrity', () => {
|
||||
})
|
||||
|
||||
it('should detect when out of sync', async function () {
|
||||
const item = await this.application.itemManager.emitItemFromPayload(
|
||||
const item = await this.application.mutator.emitItemFromPayload(
|
||||
Factory.createNotePayload(),
|
||||
PayloadEmitSource.LocalChanged,
|
||||
)
|
||||
@@ -60,7 +60,7 @@ describe('sync integrity', () => {
|
||||
})
|
||||
|
||||
it('should self heal after out of sync', async function () {
|
||||
const item = await this.application.itemManager.emitItemFromPayload(
|
||||
const item = await this.application.mutator.emitItemFromPayload(
|
||||
Factory.createNotePayload(),
|
||||
PayloadEmitSource.LocalChanged,
|
||||
)
|
||||
|
||||
@@ -33,7 +33,7 @@ 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.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.payloadManager.resetState()
|
||||
await this.application.itemManager.resetState()
|
||||
@@ -52,14 +52,14 @@ describe('notes + tags syncing', function () {
|
||||
const notePayload = pair[0]
|
||||
const tagPayload = pair[1]
|
||||
|
||||
await this.application.itemManager.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
|
||||
const note = this.application.itemManager.getItems([ContentType.Note])[0]
|
||||
const tag = this.application.itemManager.getItems([ContentType.Tag])[0]
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.itemManager.getDisplayableTags().length).to.equal(1)
|
||||
|
||||
for (let i = 0; i < 9; i++) {
|
||||
await this.application.itemManager.setItemsDirty([note, tag])
|
||||
await this.application.mutator.setItemsDirty([note, tag])
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
this.application.syncService.clearSyncPositionTokens()
|
||||
expect(tag.content.references.length).to.equal(1)
|
||||
@@ -76,10 +76,10 @@ describe('notes + tags syncing', function () {
|
||||
const pair = createRelatedNoteTagPairPayload()
|
||||
const notePayload = pair[0]
|
||||
const tagPayload = pair[1]
|
||||
await this.application.itemManager.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
|
||||
const originalNote = this.application.itemManager.getDisplayableNotes()[0]
|
||||
const originalTag = this.application.itemManager.getDisplayableTags()[0]
|
||||
await this.application.itemManager.setItemsDirty([originalNote, originalTag])
|
||||
await this.application.mutator.setItemsDirty([originalNote, originalTag])
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
|
||||
@@ -109,12 +109,12 @@ describe('notes + tags syncing', function () {
|
||||
const pair = createRelatedNoteTagPairPayload()
|
||||
const notePayload = pair[0]
|
||||
const tagPayload = pair[1]
|
||||
await this.application.itemManager.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
|
||||
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)
|
||||
|
||||
await this.application.itemManager.setItemsDirty([note, tag])
|
||||
await this.application.mutator.setItemsDirty([note, tag])
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.syncService.clearSyncPositionTokens()
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable no-unused-expressions */
|
||||
/* eslint-disable no-undef */
|
||||
import { BaseItemCounts } from '../lib/Applications.js'
|
||||
import { BaseItemCounts } from '../lib/BaseItemCounts.js'
|
||||
import * as Factory from '../lib/factory.js'
|
||||
chai.use(chaiAsPromised)
|
||||
const expect = chai.expect
|
||||
@@ -31,6 +31,21 @@ describe('offline syncing', () => {
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
it('uuid alternation should delete original payload', async function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
this.expectedItemCount++
|
||||
|
||||
await Factory.alternateUuidForItem(this.application, note.uuid)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
const notes = this.application.itemManager.getDisplayableNotes()
|
||||
expect(notes.length).to.equal(1)
|
||||
expect(notes[0].uuid).to.not.equal(note.uuid)
|
||||
|
||||
const items = this.application.itemManager.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))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable no-undef */
|
||||
import { BaseItemCounts } from '../lib/Applications.js'
|
||||
import { BaseItemCounts } from '../lib/BaseItemCounts.js'
|
||||
import * as Factory from '../lib/factory.js'
|
||||
import * as Utils from '../lib/Utils.js'
|
||||
chai.use(chaiAsPromised)
|
||||
@@ -15,7 +15,7 @@ describe('online syncing', function () {
|
||||
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
this.expectedItemCount = BaseItemCounts.DefaultItems
|
||||
this.expectedItemCount = BaseItemCounts.DefaultItemsWithAccount
|
||||
|
||||
this.context = await Factory.createAppContext()
|
||||
await this.context.launch()
|
||||
@@ -43,8 +43,10 @@ describe('online syncing', function () {
|
||||
|
||||
afterEach(async function () {
|
||||
expect(this.application.syncService.isOutOfSync()).to.equal(false)
|
||||
|
||||
const items = this.application.itemManager.allTrackedItems()
|
||||
expect(items.length).to.equal(this.expectedItemCount)
|
||||
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
expect(rawPayloads.length).to.equal(this.expectedItemCount)
|
||||
await Factory.safeDeinit(this.application)
|
||||
@@ -119,18 +121,6 @@ describe('online syncing', function () {
|
||||
await Factory.sleep(0.5)
|
||||
}).timeout(20000)
|
||||
|
||||
it('uuid alternation should delete original payload', async function () {
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
this.expectedItemCount++
|
||||
await Factory.alternateUuidForItem(this.application, note.uuid)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
const notes = this.application.itemManager.getDisplayableNotes()
|
||||
expect(notes.length).to.equal(1)
|
||||
expect(notes[0].uuid).to.not.equal(note.uuid)
|
||||
})
|
||||
|
||||
it('having offline data then signing in should not alternate uuid and merge with account', async function () {
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
@@ -222,7 +212,7 @@ describe('online syncing', function () {
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
const promise = new Promise((resolve) => {
|
||||
this.application.syncService.addEventObserver(async (event) => {
|
||||
if (event === SyncEvent.SingleRoundTripSyncCompleted) {
|
||||
if (event === SyncEvent.PaginatedSyncRequestCompleted) {
|
||||
const note = this.application.items.findItem(originalNote.uuid)
|
||||
if (note) {
|
||||
expect(note.dirty).to.not.be.ok
|
||||
@@ -241,7 +231,7 @@ describe('online syncing', function () {
|
||||
expect(this.application.itemManager.getDisplayableItemsKeys().length).to.equal(1)
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
this.expectedItemCount++
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
const notePayload = noteObjectsFromObjects(rawPayloads)
|
||||
@@ -283,7 +273,7 @@ describe('online syncing', function () {
|
||||
|
||||
const originalTitle = note.content.title
|
||||
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
|
||||
const encrypted = CreateEncryptedServerSyncPushPayload(
|
||||
@@ -299,7 +289,7 @@ describe('online syncing', function () {
|
||||
errorDecrypting: true,
|
||||
})
|
||||
|
||||
const items = await this.application.itemManager.emitItemsFromPayloads([errorred], PayloadEmitSource.LocalChanged)
|
||||
const items = await this.application.mutator.emitItemsFromPayloads([errorred], PayloadEmitSource.LocalChanged)
|
||||
|
||||
const mappedItem = this.application.itemManager.findAnyItem(errorred.uuid)
|
||||
|
||||
@@ -311,7 +301,7 @@ describe('online syncing', function () {
|
||||
},
|
||||
})
|
||||
|
||||
const mappedItems2 = await this.application.itemManager.emitItemsFromPayloads(
|
||||
const mappedItems2 = await this.application.mutator.emitItemsFromPayloads(
|
||||
[decryptedPayload],
|
||||
PayloadEmitSource.LocalChanged,
|
||||
)
|
||||
@@ -336,14 +326,14 @@ describe('online syncing', function () {
|
||||
let note = await Factory.createMappedNote(this.application)
|
||||
this.expectedItemCount++
|
||||
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.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)
|
||||
|
||||
await this.application.itemManager.setItemToBeDeleted(note)
|
||||
await this.application.mutator.setItemToBeDeleted(note)
|
||||
note = this.application.items.findAnyItem(note.uuid)
|
||||
expect(note.dirty).to.equal(true)
|
||||
this.expectedItemCount--
|
||||
@@ -361,7 +351,7 @@ describe('online syncing', function () {
|
||||
|
||||
it('retrieving item with no content should correctly map local state', async function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
|
||||
const syncToken = await this.application.syncService.getLastSyncToken()
|
||||
@@ -370,7 +360,7 @@ describe('online syncing', function () {
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
|
||||
// client A
|
||||
await this.application.itemManager.setItemToBeDeleted(note)
|
||||
await this.application.mutator.setItemToBeDeleted(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
|
||||
// Subtract 1
|
||||
@@ -399,7 +389,7 @@ describe('online syncing', function () {
|
||||
|
||||
await Factory.sleep(0.1)
|
||||
|
||||
await this.application.itemManager.changeItem(note, (mutator) => {
|
||||
await this.application.mutator.changeItem(note, (mutator) => {
|
||||
mutator.title = 'latest title'
|
||||
})
|
||||
|
||||
@@ -427,7 +417,7 @@ describe('online syncing', function () {
|
||||
|
||||
await Factory.sleep(0.1)
|
||||
|
||||
await this.application.itemManager.setItemToBeDeleted(note)
|
||||
await this.application.mutator.setItemToBeDeleted(note)
|
||||
|
||||
this.expectedItemCount--
|
||||
|
||||
@@ -444,8 +434,8 @@ describe('online syncing', function () {
|
||||
|
||||
it('items that are never synced and deleted should not be uploaded to server', async function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.itemManager.setItemToBeDeleted(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.mutator.setItemToBeDeleted(note)
|
||||
|
||||
let success = true
|
||||
let didCompleteRelevantSync = false
|
||||
@@ -457,7 +447,7 @@ describe('online syncing', function () {
|
||||
if (!beginCheckingResponse) {
|
||||
return
|
||||
}
|
||||
if (!didCompleteRelevantSync && eventName === SyncEvent.SingleRoundTripSyncCompleted) {
|
||||
if (!didCompleteRelevantSync && eventName === SyncEvent.PaginatedSyncRequestCompleted) {
|
||||
didCompleteRelevantSync = true
|
||||
const response = data
|
||||
const matching = response.savedPayloads.find((p) => p.uuid === note.uuid)
|
||||
@@ -474,20 +464,20 @@ describe('online syncing', function () {
|
||||
it('items that are deleted after download first sync complete should not be uploaded to server', async function () {
|
||||
/** The singleton manager may delete items are download first. We dont want those uploaded to server. */
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
|
||||
let success = true
|
||||
let didCompleteRelevantSync = false
|
||||
let beginCheckingResponse = false
|
||||
this.application.syncService.addEventObserver(async (eventName, data) => {
|
||||
if (eventName === SyncEvent.DownloadFirstSyncCompleted) {
|
||||
await this.application.itemManager.setItemToBeDeleted(note)
|
||||
await this.application.mutator.setItemToBeDeleted(note)
|
||||
beginCheckingResponse = true
|
||||
}
|
||||
if (!beginCheckingResponse) {
|
||||
return
|
||||
}
|
||||
if (!didCompleteRelevantSync && eventName === SyncEvent.SingleRoundTripSyncCompleted) {
|
||||
if (!didCompleteRelevantSync && eventName === SyncEvent.PaginatedSyncRequestCompleted) {
|
||||
didCompleteRelevantSync = true
|
||||
const response = data
|
||||
const matching = response.savedPayloads.find((p) => p.uuid === note.uuid)
|
||||
@@ -527,7 +517,7 @@ describe('online syncing', function () {
|
||||
|
||||
const decryptionResults = await this.application.protocolService.decryptSplit(keyedSplit)
|
||||
|
||||
await this.application.itemManager.emitItemsFromPayloads(decryptionResults, PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads(decryptionResults, PayloadEmitSource.LocalChanged)
|
||||
|
||||
expect(this.application.itemManager.allTrackedItems().length).to.equal(this.expectedItemCount)
|
||||
|
||||
@@ -543,7 +533,7 @@ describe('online syncing', function () {
|
||||
const largeItemCount = SyncUpDownLimit + 10
|
||||
for (let i = 0; i < largeItemCount; i++) {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
}
|
||||
|
||||
this.expectedItemCount += largeItemCount
|
||||
@@ -558,7 +548,7 @@ describe('online syncing', function () {
|
||||
const largeItemCount = SyncUpDownLimit + 10
|
||||
for (let i = 0; i < largeItemCount; i++) {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
}
|
||||
/** Upload */
|
||||
this.application.syncService.sync({ awaitAll: true, checkIntegrity: false })
|
||||
@@ -583,7 +573,7 @@ describe('online syncing', function () {
|
||||
|
||||
it('syncing an item should storage it encrypted', async function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
this.expectedItemCount++
|
||||
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
|
||||
@@ -593,7 +583,7 @@ describe('online syncing', function () {
|
||||
|
||||
it('syncing an item before data load should storage it encrypted', async function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
this.expectedItemCount++
|
||||
|
||||
/** Simulate database not loaded */
|
||||
@@ -610,7 +600,7 @@ describe('online syncing', function () {
|
||||
it('saving an item after sync should persist it with content property', async function () {
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
const text = Factory.randomString(10000)
|
||||
await this.application.mutator.changeAndSaveItem(
|
||||
await this.application.changeAndSaveItem(
|
||||
note,
|
||||
(mutator) => {
|
||||
mutator.text = text
|
||||
@@ -634,7 +624,7 @@ describe('online syncing', function () {
|
||||
expect(this.application.itemManager.getDirtyItems().length).to.equal(0)
|
||||
|
||||
let note = await Factory.createMappedNote(this.application)
|
||||
note = await this.application.itemManager.changeItem(note, (mutator) => {
|
||||
note = await this.application.mutator.changeItem(note, (mutator) => {
|
||||
mutator.text = `${Math.random()}`
|
||||
})
|
||||
/** This sync request should exit prematurely as we called ut_setDatabaseNotLoaded */
|
||||
@@ -705,13 +695,13 @@ describe('online syncing', function () {
|
||||
|
||||
it('valid sync date tracking', async function () {
|
||||
let note = await Factory.createMappedNote(this.application)
|
||||
note = await this.application.itemManager.setItemDirty(note)
|
||||
note = await this.application.mutator.setItemDirty(note)
|
||||
this.expectedItemCount++
|
||||
|
||||
expect(note.dirty).to.equal(true)
|
||||
expect(note.payload.dirtyIndex).to.be.at.most(getCurrentDirtyIndex())
|
||||
|
||||
note = await this.application.itemManager.changeItem(note, (mutator) => {
|
||||
note = await this.application.mutator.changeItem(note, (mutator) => {
|
||||
mutator.text = `${Math.random()}`
|
||||
})
|
||||
const sync = this.application.sync.sync(syncOptions)
|
||||
@@ -748,7 +738,7 @@ describe('online syncing', function () {
|
||||
* It will do based on comparing whether item.dirtyIndex > item.globalDirtyIndexAtLastSync
|
||||
*/
|
||||
let note = await Factory.createMappedNote(this.application)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
this.expectedItemCount++
|
||||
|
||||
// client A. Don't await, we want to do other stuff.
|
||||
@@ -759,12 +749,12 @@ describe('online syncing', function () {
|
||||
|
||||
// While that sync is going on, we want to modify this item many times.
|
||||
const text = `${Math.random()}`
|
||||
note = await this.application.itemManager.changeItem(note, (mutator) => {
|
||||
note = await this.application.mutator.changeItem(note, (mutator) => {
|
||||
mutator.text = text
|
||||
})
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
expect(note.payload.dirtyIndex).to.be.above(note.payload.globalDirtyIndexAtLastSync)
|
||||
|
||||
// Now do a regular sync with no latency.
|
||||
@@ -817,7 +807,7 @@ describe('online syncing', function () {
|
||||
|
||||
setTimeout(
|
||||
async function () {
|
||||
await this.application.itemManager.changeItem(note, (mutator) => {
|
||||
await this.application.mutator.changeItem(note, (mutator) => {
|
||||
mutator.text = newText
|
||||
})
|
||||
}.bind(this),
|
||||
@@ -862,9 +852,9 @@ describe('online syncing', function () {
|
||||
const newText = `${Math.random()}`
|
||||
|
||||
this.application.syncService.addEventObserver(async (eventName) => {
|
||||
if (eventName === SyncEvent.SyncWillBegin && !didPerformMutatation) {
|
||||
if (eventName === SyncEvent.SyncDidBeginProcessing && !didPerformMutatation) {
|
||||
didPerformMutatation = true
|
||||
await this.application.itemManager.changeItem(note, (mutator) => {
|
||||
await this.application.mutator.changeItem(note, (mutator) => {
|
||||
mutator.text = newText
|
||||
})
|
||||
}
|
||||
@@ -898,7 +888,7 @@ describe('online syncing', function () {
|
||||
dirtyIndex: changed[0].payload.globalDirtyIndexAtLastSync + 1,
|
||||
})
|
||||
|
||||
await this.application.itemManager.emitItemFromPayload(mutated)
|
||||
await this.application.mutator.emitItemFromPayload(mutated)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -916,6 +906,7 @@ describe('online syncing', function () {
|
||||
const note = await Factory.createSyncedNote(this.application)
|
||||
const preDeleteSyncToken = await this.application.syncService.getLastSyncToken()
|
||||
await this.application.mutator.deleteItem(note)
|
||||
await this.application.sync.sync()
|
||||
await this.application.syncService.setLastSyncToken(preDeleteSyncToken)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
@@ -938,7 +929,7 @@ describe('online syncing', function () {
|
||||
dirty: true,
|
||||
})
|
||||
|
||||
await this.application.itemManager.emitItemFromPayload(errored)
|
||||
await this.application.payloadManager.emitPayload(errored)
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
const updatedNote = this.application.items.findAnyItem(note.uuid)
|
||||
@@ -966,7 +957,7 @@ describe('online syncing', function () {
|
||||
},
|
||||
})
|
||||
|
||||
await this.application.syncService.handleSuccessServerResponse({ payloadsSavedOrSaving: [] }, response)
|
||||
await this.application.syncService.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
|
||||
@@ -995,7 +986,7 @@ describe('online syncing', function () {
|
||||
content: {},
|
||||
})
|
||||
this.expectedItemCount++
|
||||
await this.application.itemManager.emitItemsFromPayloads([payload])
|
||||
await this.application.mutator.emitItemsFromPayloads([payload])
|
||||
await this.application.sync.sync(syncOptions)
|
||||
|
||||
/** Item should no longer be dirty, otherwise it would keep syncing */
|
||||
@@ -1006,7 +997,7 @@ describe('online syncing', function () {
|
||||
it('should call onPresyncSave before sync begins', async function () {
|
||||
const events = []
|
||||
this.application.syncService.addEventObserver((event) => {
|
||||
if (event === SyncEvent.SyncWillBegin) {
|
||||
if (event === SyncEvent.SyncDidBeginProcessing) {
|
||||
events.push('sync-will-begin')
|
||||
}
|
||||
})
|
||||
@@ -1032,6 +1023,7 @@ describe('online syncing', function () {
|
||||
|
||||
const note = await Factory.createSyncedNote(this.application)
|
||||
await this.application.mutator.deleteItem(note)
|
||||
await this.application.sync.sync()
|
||||
|
||||
expect(conditionMet).to.equal(true)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user