internal: incomplete vault systems behind feature flag (#2340)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable camelcase */
|
||||
/* 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
|
||||
@@ -70,8 +70,8 @@ describe('app models', () => {
|
||||
},
|
||||
})
|
||||
|
||||
await this.application.itemManager.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
|
||||
await this.application.itemManager.emitItemsFromPayloads([params2], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([params2], PayloadEmitSource.LocalChanged)
|
||||
|
||||
const item1 = this.application.itemManager.findItem(params1.uuid)
|
||||
const item2 = this.application.itemManager.findItem(params2.uuid)
|
||||
@@ -93,11 +93,11 @@ describe('app models', () => {
|
||||
},
|
||||
})
|
||||
|
||||
let items = await this.application.itemManager.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
|
||||
let items = await this.application.mutator.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
|
||||
let item = items[0]
|
||||
expect(item).to.be.ok
|
||||
|
||||
items = await this.application.itemManager.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
|
||||
items = await this.application.mutator.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
|
||||
item = items[0]
|
||||
|
||||
expect(item.content.foo).to.equal('bar')
|
||||
@@ -108,10 +108,10 @@ describe('app models', () => {
|
||||
const item1 = await Factory.createMappedNote(this.application)
|
||||
const item2 = await Factory.createMappedNote(this.application)
|
||||
|
||||
await this.application.itemManager.changeItem(item1, (mutator) => {
|
||||
await this.application.mutator.changeItem(item1, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
|
||||
})
|
||||
await this.application.itemManager.changeItem(item2, (mutator) => {
|
||||
await this.application.mutator.changeItem(item2, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(item1)
|
||||
})
|
||||
|
||||
@@ -123,10 +123,10 @@ describe('app models', () => {
|
||||
var item1 = await Factory.createMappedNote(this.application)
|
||||
var item2 = await Factory.createMappedNote(this.application)
|
||||
|
||||
await this.application.itemManager.changeItem(item1, (mutator) => {
|
||||
await this.application.mutator.changeItem(item1, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
|
||||
})
|
||||
await this.application.itemManager.changeItem(item2, (mutator) => {
|
||||
await this.application.mutator.changeItem(item2, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(item1)
|
||||
})
|
||||
|
||||
@@ -143,7 +143,7 @@ describe('app models', () => {
|
||||
references: [],
|
||||
},
|
||||
})
|
||||
await this.application.itemManager.emitItemsFromPayloads([damagedPayload], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([damagedPayload], PayloadEmitSource.LocalChanged)
|
||||
|
||||
const refreshedItem1_2 = this.application.itemManager.findItem(item1.uuid)
|
||||
const refreshedItem2_2 = this.application.itemManager.findItem(item2.uuid)
|
||||
@@ -155,10 +155,10 @@ describe('app models', () => {
|
||||
it('creating and removing relationships between two items should have valid references', async function () {
|
||||
var item1 = await Factory.createMappedNote(this.application)
|
||||
var item2 = await Factory.createMappedNote(this.application)
|
||||
await this.application.itemManager.changeItem(item1, (mutator) => {
|
||||
await this.application.mutator.changeItem(item1, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
|
||||
})
|
||||
await this.application.itemManager.changeItem(item2, (mutator) => {
|
||||
await this.application.mutator.changeItem(item2, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(item1)
|
||||
})
|
||||
|
||||
@@ -171,10 +171,10 @@ describe('app models', () => {
|
||||
expect(this.application.itemManager.itemsReferencingItem(item1)).to.include(refreshedItem2)
|
||||
expect(this.application.itemManager.itemsReferencingItem(item2)).to.include(refreshedItem1)
|
||||
|
||||
await this.application.itemManager.changeItem(item1, (mutator) => {
|
||||
await this.application.mutator.changeItem(item1, (mutator) => {
|
||||
mutator.removeItemAsRelationship(item2)
|
||||
})
|
||||
await this.application.itemManager.changeItem(item2, (mutator) => {
|
||||
await this.application.mutator.changeItem(item2, (mutator) => {
|
||||
mutator.removeItemAsRelationship(item1)
|
||||
})
|
||||
|
||||
@@ -190,7 +190,7 @@ describe('app models', () => {
|
||||
|
||||
it('properly duplicates item with no relationships', async function () {
|
||||
const item = await Factory.createMappedNote(this.application)
|
||||
const duplicate = await this.application.itemManager.duplicateItem(item)
|
||||
const duplicate = await this.application.mutator.duplicateItem(item)
|
||||
expect(duplicate.uuid).to.not.equal(item.uuid)
|
||||
expect(item.isItemContentEqualWith(duplicate)).to.equal(true)
|
||||
expect(item.created_at.toISOString()).to.equal(duplicate.created_at.toISOString())
|
||||
@@ -201,13 +201,13 @@ describe('app models', () => {
|
||||
const item1 = await Factory.createMappedNote(this.application)
|
||||
const item2 = await Factory.createMappedNote(this.application)
|
||||
|
||||
const refreshedItem1 = await this.application.itemManager.changeItem(item1, (mutator) => {
|
||||
const refreshedItem1 = await this.application.mutator.changeItem(item1, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
|
||||
})
|
||||
|
||||
expect(refreshedItem1.content.references.length).to.equal(1)
|
||||
|
||||
const duplicate = await this.application.itemManager.duplicateItem(item1)
|
||||
const duplicate = await this.application.mutator.duplicateItem(item1)
|
||||
expect(duplicate.uuid).to.not.equal(item1.uuid)
|
||||
expect(duplicate.content.references.length).to.equal(1)
|
||||
|
||||
@@ -223,11 +223,11 @@ describe('app models', () => {
|
||||
it('removing references should update cross-refs', async function () {
|
||||
const item1 = await Factory.createMappedNote(this.application)
|
||||
const item2 = await Factory.createMappedNote(this.application)
|
||||
const refreshedItem1 = await this.application.itemManager.changeItem(item1, (mutator) => {
|
||||
const refreshedItem1 = await this.application.mutator.changeItem(item1, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
|
||||
})
|
||||
|
||||
const refreshedItem1_2 = await this.application.itemManager.emitItemFromPayload(
|
||||
const refreshedItem1_2 = await this.application.mutator.emitItemFromPayload(
|
||||
refreshedItem1.payloadRepresentation({
|
||||
deleted: true,
|
||||
content: {
|
||||
@@ -247,7 +247,7 @@ describe('app models', () => {
|
||||
const item1 = await Factory.createMappedNote(this.application)
|
||||
const item2 = await Factory.createMappedNote(this.application)
|
||||
|
||||
const refreshedItem1 = await this.application.itemManager.changeItem(item1, (mutator) => {
|
||||
const refreshedItem1 = await this.application.mutator.changeItem(item1, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
|
||||
})
|
||||
|
||||
@@ -290,12 +290,12 @@ describe('app models', () => {
|
||||
waitingForKey: true,
|
||||
})
|
||||
|
||||
await this.application.itemManager.emitItemFromPayload(errored)
|
||||
await this.application.payloadManager.emitPayload(errored)
|
||||
|
||||
expect(this.application.payloadManager.findOne(item1.uuid).errorDecrypting).to.equal(true)
|
||||
expect(this.application.payloadManager.findOne(item1.uuid).items_key_id).to.equal(itemsKey.uuid)
|
||||
|
||||
sinon.stub(this.application.protocolService.itemsEncryption, 'decryptErroredPayloads').callsFake(() => {
|
||||
sinon.stub(this.application.protocolService.itemsEncryption, 'decryptErroredItemPayloads').callsFake(() => {
|
||||
// prevent auto decryption
|
||||
})
|
||||
|
||||
@@ -310,7 +310,7 @@ describe('app models', () => {
|
||||
const item2 = await Factory.createMappedNote(this.application)
|
||||
this.expectedItemCount += 2
|
||||
|
||||
await this.application.itemManager.changeItem(item1, (mutator) => {
|
||||
await this.application.mutator.changeItem(item1, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
|
||||
})
|
||||
|
||||
@@ -339,13 +339,13 @@ describe('app models', () => {
|
||||
it('maintains referencing relationships when duplicating', async function () {
|
||||
const tag = await Factory.createMappedTag(this.application)
|
||||
const note = await Factory.createMappedNote(this.application)
|
||||
const refreshedTag = await this.application.itemManager.changeItem(tag, (mutator) => {
|
||||
const refreshedTag = await this.application.mutator.changeItem(tag, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(note)
|
||||
})
|
||||
|
||||
expect(refreshedTag.content.references.length).to.equal(1)
|
||||
|
||||
const noteCopy = await this.application.itemManager.duplicateItem(note)
|
||||
const noteCopy = await this.application.mutator.duplicateItem(note)
|
||||
expect(note.uuid).to.not.equal(noteCopy.uuid)
|
||||
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(2)
|
||||
@@ -358,7 +358,7 @@ describe('app models', () => {
|
||||
})
|
||||
|
||||
it('maintains editor reference when duplicating note', async function () {
|
||||
const editor = await this.application.itemManager.createItem(
|
||||
const editor = await this.application.mutator.createItem(
|
||||
ContentType.Component,
|
||||
{ area: ComponentArea.Editor, package_info: { identifier: 'foo-editor' } },
|
||||
true,
|
||||
@@ -369,7 +369,7 @@ describe('app models', () => {
|
||||
|
||||
expect(this.application.componentManager.editorForNote(note).uuid).to.equal(editor.uuid)
|
||||
|
||||
const duplicate = await this.application.itemManager.duplicateItem(note, true)
|
||||
const duplicate = await this.application.mutator.duplicateItem(note, true)
|
||||
expect(this.application.componentManager.editorForNote(duplicate).uuid).to.equal(editor.uuid)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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'
|
||||
import { createRelatedNoteTagPairPayload } from '../lib/Items.js'
|
||||
chai.use(chaiAsPromised)
|
||||
@@ -43,7 +43,7 @@ describe('importing', function () {
|
||||
|
||||
it('should not import backups made from unsupported versions', async function () {
|
||||
await setup({ fakeCrypto: true })
|
||||
const result = await application.mutator.importData({
|
||||
const result = await application.importData({
|
||||
version: '-1',
|
||||
items: [],
|
||||
})
|
||||
@@ -58,7 +58,7 @@ describe('importing', function () {
|
||||
password,
|
||||
version: ProtocolVersion.V003,
|
||||
})
|
||||
const result = await application.mutator.importData({
|
||||
const result = await application.importData({
|
||||
version: ProtocolVersion.V004,
|
||||
items: [],
|
||||
})
|
||||
@@ -71,7 +71,7 @@ describe('importing', function () {
|
||||
const notePayload = pair[0]
|
||||
const tagPayload = pair[1]
|
||||
|
||||
await application.itemManager.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
|
||||
await application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
|
||||
expectedItemCount += 2
|
||||
const note = application.itemManager.getItems([ContentType.Note])[0]
|
||||
const tag = application.itemManager.getItems([ContentType.Tag])[0]
|
||||
@@ -82,7 +82,7 @@ describe('importing', function () {
|
||||
expect(note.content.references.length).to.equal(0)
|
||||
expect(application.itemManager.itemsReferencingItem(note).length).to.equal(1)
|
||||
|
||||
await application.mutator.importData(
|
||||
await application.importData(
|
||||
{
|
||||
items: [notePayload, tagPayload],
|
||||
},
|
||||
@@ -105,7 +105,7 @@ describe('importing', function () {
|
||||
*/
|
||||
await setup({ fakeCrypto: true })
|
||||
const notePayload = Factory.createNotePayload()
|
||||
await application.itemManager.emitItemFromPayload(notePayload, PayloadEmitSource.LocalChanged)
|
||||
await application.mutator.emitItemFromPayload(notePayload, PayloadEmitSource.LocalChanged)
|
||||
expectedItemCount++
|
||||
const mutatedNote = new DecryptedPayload({
|
||||
...notePayload,
|
||||
@@ -114,7 +114,7 @@ describe('importing', function () {
|
||||
title: `${Math.random()}`,
|
||||
},
|
||||
})
|
||||
await application.mutator.importData(
|
||||
await application.importData(
|
||||
{
|
||||
items: [mutatedNote, mutatedNote, mutatedNote],
|
||||
},
|
||||
@@ -130,7 +130,7 @@ describe('importing', function () {
|
||||
await setup({ fakeCrypto: true })
|
||||
const pair = createRelatedNoteTagPairPayload()
|
||||
const tagPayload = pair[1]
|
||||
await application.itemManager.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged)
|
||||
await application.mutator.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged)
|
||||
const mutatedTag = new DecryptedPayload({
|
||||
...tagPayload,
|
||||
content: {
|
||||
@@ -138,7 +138,7 @@ describe('importing', function () {
|
||||
references: [],
|
||||
},
|
||||
})
|
||||
await application.mutator.importData(
|
||||
await application.importData(
|
||||
{
|
||||
items: [mutatedTag],
|
||||
},
|
||||
@@ -153,7 +153,7 @@ describe('importing', function () {
|
||||
const pair = createRelatedNoteTagPairPayload()
|
||||
const notePayload = pair[0]
|
||||
const tagPayload = pair[1]
|
||||
await application.itemManager.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged)
|
||||
await application.mutator.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged)
|
||||
expectedItemCount += 2
|
||||
const note = application.itemManager.getDisplayableNotes()[0]
|
||||
const tag = application.itemManager.getDisplayableTags()[0]
|
||||
@@ -171,7 +171,7 @@ describe('importing', function () {
|
||||
title: `${Math.random()}`,
|
||||
},
|
||||
})
|
||||
await application.mutator.importData(
|
||||
await application.importData(
|
||||
{
|
||||
items: [mutatedNote, mutatedTag],
|
||||
},
|
||||
@@ -217,7 +217,7 @@ describe('importing', function () {
|
||||
const tag = await Factory.createMappedTag(application)
|
||||
expectedItemCount += 2
|
||||
|
||||
await application.itemManager.changeItem(tag, (mutator) => {
|
||||
await application.mutator.changeItem(tag, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(note)
|
||||
})
|
||||
|
||||
@@ -240,7 +240,7 @@ describe('importing', function () {
|
||||
},
|
||||
)
|
||||
|
||||
await application.mutator.importData(
|
||||
await application.importData(
|
||||
{
|
||||
items: [externalNote, externalTag],
|
||||
},
|
||||
@@ -272,12 +272,14 @@ describe('importing', function () {
|
||||
await application.sync.sync({ awaitAll: true })
|
||||
|
||||
await application.mutator.deleteItem(note)
|
||||
await application.sync.sync()
|
||||
expect(application.items.findItem(note.uuid)).to.not.exist
|
||||
|
||||
await application.mutator.deleteItem(tag)
|
||||
await application.sync.sync()
|
||||
expect(application.items.findItem(tag.uuid)).to.not.exist
|
||||
|
||||
await application.mutator.importData(
|
||||
await application.importData(
|
||||
{
|
||||
items: [note, tag],
|
||||
},
|
||||
@@ -311,7 +313,7 @@ describe('importing', function () {
|
||||
password: password,
|
||||
})
|
||||
|
||||
await application.mutator.importData(
|
||||
await application.importData(
|
||||
{
|
||||
items: [note.payload],
|
||||
},
|
||||
@@ -341,7 +343,7 @@ describe('importing', function () {
|
||||
password: password,
|
||||
})
|
||||
|
||||
await application.mutator.importData(
|
||||
await application.importData(
|
||||
{
|
||||
items: [note],
|
||||
},
|
||||
@@ -372,12 +374,14 @@ describe('importing', function () {
|
||||
await application.sync.sync({ awaitAll: true })
|
||||
|
||||
await application.mutator.deleteItem(note)
|
||||
await application.sync.sync()
|
||||
expect(application.items.findItem(note.uuid)).to.not.exist
|
||||
|
||||
await application.mutator.deleteItem(tag)
|
||||
await application.sync.sync()
|
||||
expect(application.items.findItem(tag.uuid)).to.not.exist
|
||||
|
||||
await application.mutator.importData(backupData, true)
|
||||
await application.importData(backupData, true)
|
||||
|
||||
expect(application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(application.items.findItem(note.uuid).deleted).to.not.be.ok
|
||||
@@ -402,7 +406,7 @@ describe('importing', function () {
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
Factory.handlePasswordChallenges(application, password)
|
||||
|
||||
await application.mutator.importData(backupData, true)
|
||||
await application.importData(backupData, true)
|
||||
|
||||
const importedNote = application.items.findItem(note.uuid)
|
||||
const importedTag = application.items.findItem(tag.uuid)
|
||||
@@ -427,7 +431,7 @@ describe('importing', function () {
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
Factory.handlePasswordChallenges(application, password)
|
||||
|
||||
await application.mutator.importData(backupData, true)
|
||||
await application.importData(backupData, true)
|
||||
|
||||
const importedNote = application.items.findItem(note.uuid)
|
||||
const importedTag = application.items.findItem(tag.uuid)
|
||||
@@ -445,7 +449,7 @@ describe('importing', function () {
|
||||
version: oldVersion,
|
||||
})
|
||||
|
||||
const noteItem = await application.itemManager.createItem(ContentType.Note, {
|
||||
const noteItem = await application.mutator.createItem(ContentType.Note, {
|
||||
title: 'Encrypted note',
|
||||
text: 'On protocol version 003.',
|
||||
})
|
||||
@@ -456,7 +460,7 @@ describe('importing', function () {
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
Factory.handlePasswordChallenges(application, password)
|
||||
|
||||
const result = await application.mutator.importData(backupData, true)
|
||||
const result = await application.importData(backupData, true)
|
||||
expect(result).to.not.be.undefined
|
||||
expect(result.affectedItems.length).to.be.eq(backupData.items.length)
|
||||
expect(result.errorCount).to.be.eq(0)
|
||||
@@ -512,7 +516,7 @@ describe('importing', function () {
|
||||
application = await Factory.createInitAppWithRealCrypto()
|
||||
Factory.handlePasswordChallenges(application, password)
|
||||
|
||||
const result = await application.mutator.importData(backupData, true)
|
||||
const result = await application.importData(backupData, true)
|
||||
expect(result).to.not.be.undefined
|
||||
expect(result.affectedItems.length).to.be.eq(backupData.items.length)
|
||||
expect(result.errorCount).to.be.eq(0)
|
||||
@@ -526,7 +530,7 @@ describe('importing', function () {
|
||||
password: password,
|
||||
})
|
||||
|
||||
const noteItem = await application.itemManager.createItem(ContentType.Note, {
|
||||
const noteItem = await application.mutator.createItem(ContentType.Note, {
|
||||
title: 'Encrypted note',
|
||||
text: 'On protocol version 004.',
|
||||
})
|
||||
@@ -537,7 +541,7 @@ describe('importing', function () {
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
Factory.handlePasswordChallenges(application, password)
|
||||
|
||||
const result = await application.mutator.importData(backupData, true)
|
||||
const result = await application.importData(backupData, true)
|
||||
expect(result).to.not.be.undefined
|
||||
expect(result.affectedItems.length).to.be.eq(backupData.items.length)
|
||||
expect(result.errorCount).to.be.eq(0)
|
||||
@@ -556,7 +560,7 @@ describe('importing', function () {
|
||||
password: password,
|
||||
})
|
||||
|
||||
const noteItem = await application.itemManager.createItem(ContentType.Note, {
|
||||
const noteItem = await application.mutator.createItem(ContentType.Note, {
|
||||
title: 'This is a valid, encrypted note',
|
||||
text: 'On protocol version 004.',
|
||||
})
|
||||
@@ -577,7 +581,7 @@ describe('importing', function () {
|
||||
|
||||
backupData.items = [...backupData.items, madeUpPayload]
|
||||
|
||||
const result = await application.mutator.importData(backupData, true)
|
||||
const result = await application.importData(backupData, true)
|
||||
expect(result).to.not.be.undefined
|
||||
expect(result.affectedItems.length).to.be.eq(backupData.items.length - 1)
|
||||
expect(result.errorCount).to.be.eq(1)
|
||||
@@ -594,7 +598,7 @@ describe('importing', function () {
|
||||
version: oldVersion,
|
||||
})
|
||||
|
||||
await application.itemManager.createItem(ContentType.Note, {
|
||||
await application.mutator.createItem(ContentType.Note, {
|
||||
title: 'Encrypted note',
|
||||
text: 'On protocol version 003.',
|
||||
})
|
||||
@@ -615,7 +619,7 @@ describe('importing', function () {
|
||||
},
|
||||
})
|
||||
|
||||
const result = await application.mutator.importData(backupData, true)
|
||||
const result = await application.importData(backupData, true)
|
||||
expect(result).to.not.be.undefined
|
||||
|
||||
expect(result.affectedItems.length).to.be.eq(0)
|
||||
@@ -631,7 +635,7 @@ describe('importing', function () {
|
||||
password: password,
|
||||
})
|
||||
|
||||
await application.itemManager.createItem(ContentType.Note, {
|
||||
await application.mutator.createItem(ContentType.Note, {
|
||||
title: 'This is a valid, encrypted note',
|
||||
text: 'On protocol version 004.',
|
||||
})
|
||||
@@ -647,7 +651,7 @@ describe('importing', function () {
|
||||
},
|
||||
})
|
||||
|
||||
const result = await application.mutator.importData(backupData, true)
|
||||
const result = await application.importData(backupData, true)
|
||||
expect(result).to.not.be.undefined
|
||||
expect(result.affectedItems.length).to.be.eq(0)
|
||||
expect(result.errorCount).to.be.eq(backupData.items.length)
|
||||
@@ -662,7 +666,7 @@ describe('importing', function () {
|
||||
password: password,
|
||||
})
|
||||
|
||||
await application.itemManager.createItem(ContentType.Note, {
|
||||
await application.mutator.createItem(ContentType.Note, {
|
||||
title: 'Encrypted note',
|
||||
text: 'On protocol version 004.',
|
||||
})
|
||||
@@ -673,7 +677,7 @@ describe('importing', function () {
|
||||
await Factory.safeDeinit(application)
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
|
||||
const result = await application.mutator.importData(backupData)
|
||||
const result = await application.importData(backupData)
|
||||
|
||||
expect(result.error).to.be.ok
|
||||
})
|
||||
@@ -687,7 +691,7 @@ describe('importing', function () {
|
||||
})
|
||||
Factory.handlePasswordChallenges(application, password)
|
||||
|
||||
await application.itemManager.createItem(ContentType.Note, {
|
||||
await application.mutator.createItem(ContentType.Note, {
|
||||
title: 'Encrypted note',
|
||||
text: 'On protocol version 004.',
|
||||
})
|
||||
@@ -699,11 +703,13 @@ describe('importing', function () {
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
Factory.handlePasswordChallenges(application, password)
|
||||
|
||||
const result = await application.mutator.importData(backupData, true)
|
||||
const result = await application.importData(backupData, true)
|
||||
|
||||
expect(result).to.not.be.undefined
|
||||
expect(result.affectedItems.length).to.be.eq(0)
|
||||
expect(result.errorCount).to.be.eq(backupData.items.length)
|
||||
|
||||
expect(result.affectedItems.length).to.equal(BaseItemCounts.BackupFileRootKeyEncryptedItems)
|
||||
|
||||
expect(result.errorCount).to.be.eq(backupData.items.length - BaseItemCounts.BackupFileRootKeyEncryptedItems)
|
||||
expect(application.itemManager.getDisplayableNotes().length).to.equal(0)
|
||||
})
|
||||
|
||||
@@ -784,7 +790,14 @@ describe('importing', function () {
|
||||
|
||||
await application.prepareForLaunch({
|
||||
receiveChallenge: (challenge) => {
|
||||
if (challenge.prompts.length === 2) {
|
||||
if (challenge.reason === ChallengeReason.Custom) {
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
challenge.reason === ChallengeReason.DecryptEncryptedFile ||
|
||||
challenge.reason === ChallengeReason.ImportFile
|
||||
) {
|
||||
application.submitValuesForChallenge(
|
||||
challenge,
|
||||
challenge.prompts.map((prompt) =>
|
||||
@@ -796,9 +809,6 @@ describe('importing', function () {
|
||||
),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
const prompt = challenge.prompts[0]
|
||||
application.submitValuesForChallenge(challenge, [CreateChallengeValue(prompt, password)])
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -827,7 +837,7 @@ describe('importing', function () {
|
||||
},
|
||||
}
|
||||
|
||||
const result = await application.mutator.importData(backupFile, false)
|
||||
const result = await application.importData(backupFile, false)
|
||||
expect(result.errorCount).to.equal(0)
|
||||
await Factory.safeDeinit(application)
|
||||
})
|
||||
@@ -846,7 +856,7 @@ describe('importing', function () {
|
||||
Factory.handlePasswordChallenges(application, password)
|
||||
|
||||
const pair = createRelatedNoteTagPairPayload()
|
||||
await application.itemManager.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged)
|
||||
await application.mutator.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged)
|
||||
|
||||
await application.sync.sync()
|
||||
|
||||
@@ -862,7 +872,7 @@ describe('importing', function () {
|
||||
password: password,
|
||||
})
|
||||
|
||||
await application.mutator.importData(backupData, true)
|
||||
await application.importData(backupData, true)
|
||||
|
||||
expect(application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(application.itemManager.getDisplayableTags().length).to.equal(1)
|
||||
@@ -872,4 +882,8 @@ describe('importing', function () {
|
||||
expect(application.itemManager.referencesForItem(importedTag).length).to.equal(1)
|
||||
expect(application.itemManager.itemsReferencingItem(importedNote).length).to.equal(1)
|
||||
})
|
||||
|
||||
it('should decrypt backup file which contains a vaulted note without a synced key system root key', async () => {
|
||||
console.error('TODO: Implement this test')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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
|
||||
@@ -22,11 +22,11 @@ describe('items', () => {
|
||||
|
||||
it('setting an item as dirty should update its client updated at', async function () {
|
||||
const params = Factory.createNotePayload()
|
||||
await this.application.itemManager.emitItemsFromPayloads([params], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([params], PayloadEmitSource.LocalChanged)
|
||||
const item = this.application.itemManager.items[0]
|
||||
const prevDate = item.userModifiedDate.getTime()
|
||||
await Factory.sleep(0.1)
|
||||
await this.application.itemManager.setItemDirty(item, true)
|
||||
await this.application.mutator.setItemDirty(item, true)
|
||||
const refreshedItem = this.application.itemManager.findItem(item.uuid)
|
||||
const newDate = refreshedItem.userModifiedDate.getTime()
|
||||
expect(prevDate).to.not.equal(newDate)
|
||||
@@ -34,23 +34,23 @@ describe('items', () => {
|
||||
|
||||
it('setting an item as dirty with option to skip client updated at', async function () {
|
||||
const params = Factory.createNotePayload()
|
||||
await this.application.itemManager.emitItemsFromPayloads([params], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([params], PayloadEmitSource.LocalChanged)
|
||||
const item = this.application.itemManager.items[0]
|
||||
const prevDate = item.userModifiedDate.getTime()
|
||||
await Factory.sleep(0.1)
|
||||
await this.application.itemManager.setItemDirty(item)
|
||||
await this.application.mutator.setItemDirty(item)
|
||||
const newDate = item.userModifiedDate.getTime()
|
||||
expect(prevDate).to.equal(newDate)
|
||||
})
|
||||
|
||||
it('properly pins, archives, and locks', async function () {
|
||||
const params = Factory.createNotePayload()
|
||||
await this.application.itemManager.emitItemsFromPayloads([params], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([params], PayloadEmitSource.LocalChanged)
|
||||
|
||||
const item = this.application.itemManager.items[0]
|
||||
expect(item.pinned).to.not.be.ok
|
||||
|
||||
const refreshedItem = await this.application.mutator.changeAndSaveItem(
|
||||
const refreshedItem = await this.application.changeAndSaveItem(
|
||||
item,
|
||||
(mutator) => {
|
||||
mutator.pinned = true
|
||||
@@ -69,7 +69,7 @@ describe('items', () => {
|
||||
it('properly compares item equality', async function () {
|
||||
const params1 = Factory.createNotePayload()
|
||||
const params2 = Factory.createNotePayload()
|
||||
await this.application.itemManager.emitItemsFromPayloads([params1, params2], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([params1, params2], PayloadEmitSource.LocalChanged)
|
||||
|
||||
let item1 = this.application.itemManager.getDisplayableNotes()[0]
|
||||
let item2 = this.application.itemManager.getDisplayableNotes()[1]
|
||||
@@ -77,7 +77,7 @@ describe('items', () => {
|
||||
expect(item1.isItemContentEqualWith(item2)).to.equal(true)
|
||||
|
||||
// items should ignore this field when checking for equality
|
||||
item1 = await this.application.mutator.changeAndSaveItem(
|
||||
item1 = await this.application.changeAndSaveItem(
|
||||
item1,
|
||||
(mutator) => {
|
||||
mutator.userModifiedDate = new Date()
|
||||
@@ -86,7 +86,7 @@ describe('items', () => {
|
||||
undefined,
|
||||
syncOptions,
|
||||
)
|
||||
item2 = await this.application.mutator.changeAndSaveItem(
|
||||
item2 = await this.application.changeAndSaveItem(
|
||||
item2,
|
||||
(mutator) => {
|
||||
mutator.userModifiedDate = undefined
|
||||
@@ -98,7 +98,7 @@ describe('items', () => {
|
||||
|
||||
expect(item1.isItemContentEqualWith(item2)).to.equal(true)
|
||||
|
||||
item1 = await this.application.mutator.changeAndSaveItem(
|
||||
item1 = await this.application.changeAndSaveItem(
|
||||
item1,
|
||||
(mutator) => {
|
||||
mutator.mutableContent.foo = 'bar'
|
||||
@@ -110,7 +110,7 @@ describe('items', () => {
|
||||
|
||||
expect(item1.isItemContentEqualWith(item2)).to.equal(false)
|
||||
|
||||
item2 = await this.application.mutator.changeAndSaveItem(
|
||||
item2 = await this.application.changeAndSaveItem(
|
||||
item2,
|
||||
(mutator) => {
|
||||
mutator.mutableContent.foo = 'bar'
|
||||
@@ -123,7 +123,7 @@ describe('items', () => {
|
||||
expect(item1.isItemContentEqualWith(item2)).to.equal(true)
|
||||
expect(item2.isItemContentEqualWith(item1)).to.equal(true)
|
||||
|
||||
item1 = await this.application.mutator.changeAndSaveItem(
|
||||
item1 = await this.application.changeAndSaveItem(
|
||||
item1,
|
||||
(mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(item2)
|
||||
@@ -132,7 +132,7 @@ describe('items', () => {
|
||||
undefined,
|
||||
syncOptions,
|
||||
)
|
||||
item2 = await this.application.mutator.changeAndSaveItem(
|
||||
item2 = await this.application.changeAndSaveItem(
|
||||
item2,
|
||||
(mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(item1)
|
||||
@@ -147,7 +147,7 @@ describe('items', () => {
|
||||
|
||||
expect(item1.isItemContentEqualWith(item2)).to.equal(false)
|
||||
|
||||
item1 = await this.application.mutator.changeAndSaveItem(
|
||||
item1 = await this.application.changeAndSaveItem(
|
||||
item1,
|
||||
(mutator) => {
|
||||
mutator.removeItemAsRelationship(item2)
|
||||
@@ -156,7 +156,7 @@ describe('items', () => {
|
||||
undefined,
|
||||
syncOptions,
|
||||
)
|
||||
item2 = await this.application.mutator.changeAndSaveItem(
|
||||
item2 = await this.application.changeAndSaveItem(
|
||||
item2,
|
||||
(mutator) => {
|
||||
mutator.removeItemAsRelationship(item1)
|
||||
@@ -174,12 +174,12 @@ describe('items', () => {
|
||||
it('content equality should not have side effects', async function () {
|
||||
const params1 = Factory.createNotePayload()
|
||||
const params2 = Factory.createNotePayload()
|
||||
await this.application.itemManager.emitItemsFromPayloads([params1, params2], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([params1, params2], PayloadEmitSource.LocalChanged)
|
||||
|
||||
let item1 = this.application.itemManager.getDisplayableNotes()[0]
|
||||
const item2 = this.application.itemManager.getDisplayableNotes()[1]
|
||||
|
||||
item1 = await this.application.mutator.changeAndSaveItem(
|
||||
item1 = await this.application.changeAndSaveItem(
|
||||
item1,
|
||||
(mutator) => {
|
||||
mutator.mutableContent.foo = 'bar'
|
||||
@@ -203,7 +203,7 @@ describe('items', () => {
|
||||
// There was an issue where calling that function would modify values directly to omit keys
|
||||
// in contentKeysToIgnoreWhenCheckingEquality.
|
||||
|
||||
await this.application.itemManager.setItemsDirty([item1, item2])
|
||||
await this.application.mutator.setItemsDirty([item1, item2])
|
||||
|
||||
expect(item1.userModifiedDate).to.be.ok
|
||||
expect(item2.userModifiedDate).to.be.ok
|
||||
|
||||
@@ -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'
|
||||
import { createNoteParams } from '../lib/Items.js'
|
||||
chai.use(chaiAsPromised)
|
||||
@@ -20,7 +20,7 @@ describe('model manager mapping', () => {
|
||||
|
||||
it('mapping nonexistent item creates it', async function () {
|
||||
const payload = Factory.createNotePayload()
|
||||
await this.application.itemManager.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
|
||||
this.expectedItemCount++
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
})
|
||||
@@ -31,13 +31,13 @@ describe('model manager mapping', () => {
|
||||
dirty: false,
|
||||
deleted: true,
|
||||
})
|
||||
await this.application.itemManager.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
|
||||
await this.application.payloadManager.emitPayload(payload, PayloadEmitSource.LocalChanged)
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
})
|
||||
|
||||
it('mapping and deleting nonexistent item creates and deletes it', async function () {
|
||||
const payload = Factory.createNotePayload()
|
||||
await this.application.itemManager.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
|
||||
|
||||
this.expectedItemCount++
|
||||
|
||||
@@ -51,7 +51,7 @@ describe('model manager mapping', () => {
|
||||
|
||||
this.expectedItemCount--
|
||||
|
||||
await this.application.itemManager.emitItemsFromPayloads([changedParams], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([changedParams], PayloadEmitSource.LocalChanged)
|
||||
|
||||
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
|
||||
})
|
||||
@@ -59,22 +59,22 @@ describe('model manager mapping', () => {
|
||||
it('mapping deleted but dirty item should not delete it', async function () {
|
||||
const payload = Factory.createNotePayload()
|
||||
|
||||
const [item] = await this.application.itemManager.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
|
||||
const [item] = await this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
|
||||
|
||||
this.expectedItemCount++
|
||||
|
||||
await this.application.itemManager.emitItemFromPayload(new DeleteItemMutator(item).getDeletedResult())
|
||||
await this.application.payloadManager.emitPayload(new DeleteItemMutator(item).getDeletedResult())
|
||||
|
||||
const payload2 = new DeletedPayload(this.application.payloadManager.findOne(payload.uuid).ejected())
|
||||
|
||||
await this.application.itemManager.emitItemsFromPayloads([payload2], PayloadEmitSource.LocalChanged)
|
||||
await this.application.payloadManager.emitPayloads([payload2], PayloadEmitSource.LocalChanged)
|
||||
|
||||
expect(this.application.payloadManager.collection.all().length).to.equal(this.expectedItemCount)
|
||||
})
|
||||
|
||||
it('mapping existing item updates its properties', async function () {
|
||||
const payload = Factory.createNotePayload()
|
||||
await this.application.itemManager.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
|
||||
|
||||
const newTitle = 'updated title'
|
||||
const mutated = new DecryptedPayload({
|
||||
@@ -84,7 +84,7 @@ describe('model manager mapping', () => {
|
||||
title: newTitle,
|
||||
},
|
||||
})
|
||||
await this.application.itemManager.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([mutated], PayloadEmitSource.LocalChanged)
|
||||
const item = this.application.itemManager.getDisplayableNotes()[0]
|
||||
|
||||
expect(item.content.title).to.equal(newTitle)
|
||||
@@ -92,9 +92,9 @@ describe('model manager mapping', () => {
|
||||
|
||||
it('setting an item dirty should retrieve it in dirty items', async function () {
|
||||
const payload = Factory.createNotePayload()
|
||||
await this.application.itemManager.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
|
||||
const note = this.application.itemManager.getDisplayableNotes()[0]
|
||||
await this.application.itemManager.setItemDirty(note)
|
||||
await this.application.mutator.setItemDirty(note)
|
||||
const dirtyItems = this.application.itemManager.getDirtyItems()
|
||||
expect(Uuids(dirtyItems).includes(note.uuid))
|
||||
})
|
||||
@@ -106,7 +106,7 @@ describe('model manager mapping', () => {
|
||||
for (let i = 0; i < count; i++) {
|
||||
payloads.push(Factory.createNotePayload())
|
||||
}
|
||||
await this.application.itemManager.emitItemsFromPayloads(payloads, PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads(payloads, PayloadEmitSource.LocalChanged)
|
||||
await this.application.syncService.markAllItemsAsNeedingSyncAndPersist()
|
||||
|
||||
const dirtyItems = this.application.itemManager.getDirtyItems()
|
||||
@@ -115,14 +115,14 @@ describe('model manager mapping', () => {
|
||||
|
||||
it('sync observers should be notified of changes', async function () {
|
||||
const payload = Factory.createNotePayload()
|
||||
await this.application.itemManager.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
|
||||
const item = this.application.itemManager.items[0]
|
||||
return new Promise((resolve) => {
|
||||
this.application.itemManager.addObserver(ContentType.Any, ({ changed }) => {
|
||||
expect(changed[0].uuid === item.uuid)
|
||||
resolve()
|
||||
})
|
||||
this.application.itemManager.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
|
||||
this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import * as Factory from '../lib/factory.js'
|
||||
import * as Utils from '../lib/Utils.js'
|
||||
import { createRelatedNoteTagPairPayload } from '../lib/Items.js'
|
||||
import { BaseItemCounts } from '../lib/Applications.js'
|
||||
import { BaseItemCounts } from '../lib/BaseItemCounts.js'
|
||||
chai.use(chaiAsPromised)
|
||||
const expect = chai.expect
|
||||
|
||||
@@ -25,7 +25,7 @@ describe('notes and tags', () => {
|
||||
|
||||
it('uses proper class for note', async function () {
|
||||
const payload = Factory.createNotePayload()
|
||||
await this.application.itemManager.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
|
||||
const note = this.application.itemManager.getItems([ContentType.Note])[0]
|
||||
expect(note.constructor === SNNote).to.equal(true)
|
||||
})
|
||||
@@ -33,7 +33,7 @@ describe('notes and tags', () => {
|
||||
it('properly constructs syncing params', async function () {
|
||||
const title = 'Foo'
|
||||
const text = 'Bar'
|
||||
const note = await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
const note = await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title,
|
||||
text,
|
||||
})
|
||||
@@ -41,7 +41,7 @@ describe('notes and tags', () => {
|
||||
expect(note.content.title).to.equal(title)
|
||||
expect(note.content.text).to.equal(text)
|
||||
|
||||
const tag = await this.application.mutator.createTemplateItem(ContentType.Tag, {
|
||||
const tag = await this.application.items.createTemplateItem(ContentType.Tag, {
|
||||
title,
|
||||
})
|
||||
|
||||
@@ -73,7 +73,7 @@ describe('notes and tags', () => {
|
||||
},
|
||||
})
|
||||
|
||||
await this.application.itemManager.emitItemsFromPayloads([mutatedNote, mutatedTag], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([mutatedNote, mutatedTag], PayloadEmitSource.LocalChanged)
|
||||
const note = this.application.itemManager.getItems([ContentType.Note])[0]
|
||||
const tag = this.application.itemManager.getItems([ContentType.Tag])[0]
|
||||
|
||||
@@ -89,7 +89,7 @@ describe('notes and tags', () => {
|
||||
expect(notePayload.content.references.length).to.equal(0)
|
||||
expect(tagPayload.content.references.length).to.equal(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]
|
||||
|
||||
@@ -106,7 +106,7 @@ describe('notes and tags', () => {
|
||||
expect(note.payload.references.length).to.equal(0)
|
||||
expect(tag.noteCount).to.equal(1)
|
||||
|
||||
await this.application.itemManager.setItemToBeDeleted(note)
|
||||
await this.application.mutator.setItemToBeDeleted(note)
|
||||
|
||||
tag = this.application.itemManager.getDisplayableTags()[0]
|
||||
|
||||
@@ -130,7 +130,7 @@ describe('notes and tags', () => {
|
||||
const notePayload = pair[0]
|
||||
const tagPayload = pair[1]
|
||||
|
||||
await this.application.itemManager.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged)
|
||||
let note = this.application.itemManager.getItems([ContentType.Note])[0]
|
||||
let tag = this.application.itemManager.getItems([ContentType.Tag])[0]
|
||||
|
||||
@@ -147,7 +147,7 @@ describe('notes and tags', () => {
|
||||
references: [],
|
||||
},
|
||||
})
|
||||
await this.application.itemManager.emitItemsFromPayloads([mutatedTag], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([mutatedTag], PayloadEmitSource.LocalChanged)
|
||||
|
||||
note = this.application.itemManager.findItem(note.uuid)
|
||||
tag = this.application.itemManager.findItem(tag.uuid)
|
||||
@@ -177,14 +177,14 @@ describe('notes and tags', () => {
|
||||
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]
|
||||
let tag = this.application.itemManager.getItems([ContentType.Tag])[0]
|
||||
|
||||
expect(note.content.references.length).to.equal(0)
|
||||
expect(tag.content.references.length).to.equal(1)
|
||||
|
||||
tag = await this.application.mutator.changeAndSaveItem(
|
||||
tag = await this.application.changeAndSaveItem(
|
||||
tag,
|
||||
(mutator) => {
|
||||
mutator.removeItemAsRelationship(note)
|
||||
@@ -200,11 +200,11 @@ describe('notes and tags', () => {
|
||||
|
||||
it('properly handles tag duplication', async function () {
|
||||
const pair = createRelatedNoteTagPairPayload()
|
||||
await this.application.itemManager.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged)
|
||||
let note = this.application.itemManager.getDisplayableNotes()[0]
|
||||
let tag = this.application.itemManager.getDisplayableTags()[0]
|
||||
|
||||
const duplicateTag = await this.application.itemManager.duplicateItem(tag, true)
|
||||
const duplicateTag = await this.application.mutator.duplicateItem(tag, true)
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
|
||||
note = this.application.itemManager.findItem(note.uuid)
|
||||
@@ -232,9 +232,9 @@ describe('notes and tags', () => {
|
||||
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 note = this.application.itemManager.getItems([ContentType.Note])[0]
|
||||
const duplicateNote = await this.application.itemManager.duplicateItem(note, true)
|
||||
const duplicateNote = await this.application.mutator.duplicateItem(note, true)
|
||||
expect(note.uuid).to.not.equal(duplicateNote.uuid)
|
||||
|
||||
expect(this.application.itemManager.itemsReferencingItem(duplicateNote).length).to.equal(
|
||||
@@ -246,7 +246,7 @@ describe('notes and tags', () => {
|
||||
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 note = this.application.itemManager.getItems([ContentType.Note])[0]
|
||||
let tag = this.application.itemManager.getItems([ContentType.Tag])[0]
|
||||
|
||||
@@ -256,16 +256,16 @@ describe('notes and tags', () => {
|
||||
expect(note.content.references.length).to.equal(0)
|
||||
expect(this.application.itemManager.itemsReferencingItem(note).length).to.equal(1)
|
||||
|
||||
await this.application.itemManager.setItemToBeDeleted(tag)
|
||||
await this.application.mutator.setItemToBeDeleted(tag)
|
||||
tag = this.application.itemManager.findItem(tag.uuid)
|
||||
expect(tag).to.not.be.ok
|
||||
})
|
||||
|
||||
it('modifying item content should not modify payload content', async function () {
|
||||
const notePayload = Factory.createNotePayload()
|
||||
await this.application.itemManager.emitItemsFromPayloads([notePayload], PayloadEmitSource.LocalChanged)
|
||||
await this.application.mutator.emitItemsFromPayloads([notePayload], PayloadEmitSource.LocalChanged)
|
||||
let note = this.application.itemManager.getItems([ContentType.Note])[0]
|
||||
note = await this.application.mutator.changeAndSaveItem(
|
||||
note = await this.application.changeAndSaveItem(
|
||||
note,
|
||||
(mutator) => {
|
||||
mutator.mutableContent.title = Math.random()
|
||||
@@ -285,12 +285,12 @@ describe('notes and tags', () => {
|
||||
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.getItems([ContentType.Note])[0]
|
||||
let tag = this.application.itemManager.getItems([ContentType.Tag])[0]
|
||||
|
||||
await this.application.syncService.sync(syncOptions)
|
||||
await this.application.itemManager.setItemToBeDeleted(tag)
|
||||
await this.application.mutator.setItemToBeDeleted(tag)
|
||||
|
||||
note = this.application.itemManager.findItem(note.uuid)
|
||||
this.application.itemManager.findItem(tag.uuid)
|
||||
@@ -302,7 +302,7 @@ describe('notes and tags', () => {
|
||||
await Promise.all(
|
||||
['Y', 'Z', 'A', 'B'].map(async (title) => {
|
||||
return this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, { title }),
|
||||
await this.application.items.createTemplateItem(ContentType.Note, { title }),
|
||||
)
|
||||
}),
|
||||
)
|
||||
@@ -316,7 +316,7 @@ describe('notes and tags', () => {
|
||||
})
|
||||
|
||||
it('setting a note dirty should collapse its properties into content', async function () {
|
||||
let note = await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
let note = await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'Foo',
|
||||
})
|
||||
await this.application.mutator.insertItem(note)
|
||||
@@ -339,7 +339,7 @@ describe('notes and tags', () => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(taggedNote)
|
||||
})
|
||||
await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'A',
|
||||
}),
|
||||
)
|
||||
@@ -379,7 +379,7 @@ describe('notes and tags', () => {
|
||||
await Promise.all(
|
||||
['Y', 'Z', 'A', 'B'].map(async (title) => {
|
||||
return this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title,
|
||||
}),
|
||||
)
|
||||
@@ -413,17 +413,17 @@ describe('notes and tags', () => {
|
||||
describe('Smart views', function () {
|
||||
it('"title", "startsWith", "Foo"', async function () {
|
||||
const note = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'Foo 🎲',
|
||||
}),
|
||||
)
|
||||
await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'Not Foo 🎲',
|
||||
}),
|
||||
)
|
||||
const view = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.SmartView, {
|
||||
await this.application.items.createTemplateItem(ContentType.SmartView, {
|
||||
title: 'Foo Notes',
|
||||
predicate: {
|
||||
keypath: 'title',
|
||||
@@ -447,7 +447,7 @@ describe('notes and tags', () => {
|
||||
|
||||
it('"pinned", "=", true', async function () {
|
||||
const note = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'A',
|
||||
}),
|
||||
)
|
||||
@@ -455,13 +455,13 @@ describe('notes and tags', () => {
|
||||
mutator.pinned = true
|
||||
})
|
||||
await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'B',
|
||||
pinned: false,
|
||||
}),
|
||||
)
|
||||
const view = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.SmartView, {
|
||||
await this.application.items.createTemplateItem(ContentType.SmartView, {
|
||||
title: 'Pinned',
|
||||
predicate: {
|
||||
keypath: 'pinned',
|
||||
@@ -485,7 +485,7 @@ describe('notes and tags', () => {
|
||||
|
||||
it('"pinned", "=", false', async function () {
|
||||
const pinnedNote = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'A',
|
||||
}),
|
||||
)
|
||||
@@ -493,12 +493,12 @@ describe('notes and tags', () => {
|
||||
mutator.pinned = true
|
||||
})
|
||||
const unpinnedNote = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'B',
|
||||
}),
|
||||
)
|
||||
const view = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.SmartView, {
|
||||
await this.application.items.createTemplateItem(ContentType.SmartView, {
|
||||
title: 'Not pinned',
|
||||
predicate: {
|
||||
keypath: 'pinned',
|
||||
@@ -522,19 +522,19 @@ describe('notes and tags', () => {
|
||||
|
||||
it('"text.length", ">", 500', async function () {
|
||||
const longNote = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'A',
|
||||
text: Array(501).fill(0).join(''),
|
||||
}),
|
||||
)
|
||||
await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'B',
|
||||
text: 'b',
|
||||
}),
|
||||
)
|
||||
const view = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.SmartView, {
|
||||
await this.application.items.createTemplateItem(ContentType.SmartView, {
|
||||
title: 'Long',
|
||||
predicate: {
|
||||
keypath: 'text.length',
|
||||
@@ -563,18 +563,20 @@ describe('notes and tags', () => {
|
||||
})
|
||||
|
||||
const recentNote = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'A',
|
||||
}),
|
||||
true,
|
||||
)
|
||||
|
||||
await this.application.sync.sync()
|
||||
|
||||
const olderNote = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'B',
|
||||
text: 'b',
|
||||
}),
|
||||
true,
|
||||
)
|
||||
|
||||
const threeDays = 3 * 24 * 60 * 60 * 1000
|
||||
@@ -582,13 +584,13 @@ describe('notes and tags', () => {
|
||||
|
||||
/** Create an unsynced note which shouldn't get an updated_at */
|
||||
await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'B',
|
||||
text: 'b',
|
||||
}),
|
||||
)
|
||||
const view = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.SmartView, {
|
||||
await this.application.items.createTemplateItem(ContentType.SmartView, {
|
||||
title: 'One day ago',
|
||||
predicate: {
|
||||
keypath: 'serverUpdatedAt',
|
||||
@@ -598,6 +600,9 @@ describe('notes and tags', () => {
|
||||
}),
|
||||
)
|
||||
const matches = this.application.items.notesMatchingSmartView(view)
|
||||
expect(matches.length).to.equal(1)
|
||||
expect(matches[0].uuid).to.equal(recentNote.uuid)
|
||||
|
||||
this.application.items.setPrimaryItemDisplayOptions({
|
||||
sortBy: 'title',
|
||||
sortDirection: 'asc',
|
||||
@@ -605,13 +610,11 @@ describe('notes and tags', () => {
|
||||
})
|
||||
const displayedNotes = this.application.items.getDisplayableNotes()
|
||||
expect(displayedNotes).to.deep.equal(matches)
|
||||
expect(matches.length).to.equal(1)
|
||||
expect(matches[0].uuid).to.equal(recentNote.uuid)
|
||||
})
|
||||
|
||||
it('"tags.length", "=", 0', async function () {
|
||||
const untaggedNote = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'A',
|
||||
}),
|
||||
)
|
||||
@@ -622,7 +625,7 @@ describe('notes and tags', () => {
|
||||
})
|
||||
|
||||
const view = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.SmartView, {
|
||||
await this.application.items.createTemplateItem(ContentType.SmartView, {
|
||||
title: 'Untagged',
|
||||
predicate: {
|
||||
keypath: 'tags.length',
|
||||
@@ -650,13 +653,13 @@ describe('notes and tags', () => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(taggedNote)
|
||||
})
|
||||
await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'A',
|
||||
}),
|
||||
)
|
||||
|
||||
const view = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.SmartView, {
|
||||
await this.application.items.createTemplateItem(ContentType.SmartView, {
|
||||
title: 'B-tags',
|
||||
predicate: {
|
||||
keypath: 'tags',
|
||||
@@ -685,7 +688,7 @@ describe('notes and tags', () => {
|
||||
})
|
||||
|
||||
const pinnedNote = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'A',
|
||||
}),
|
||||
)
|
||||
@@ -694,7 +697,7 @@ describe('notes and tags', () => {
|
||||
})
|
||||
|
||||
const lockedNote = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'A',
|
||||
}),
|
||||
)
|
||||
@@ -703,7 +706,7 @@ describe('notes and tags', () => {
|
||||
})
|
||||
|
||||
const view = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.SmartView, {
|
||||
await this.application.items.createTemplateItem(ContentType.SmartView, {
|
||||
title: 'Pinned & Locked',
|
||||
predicate: {
|
||||
operator: 'and',
|
||||
@@ -733,7 +736,7 @@ describe('notes and tags', () => {
|
||||
})
|
||||
|
||||
const pinnedNote = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'A',
|
||||
}),
|
||||
)
|
||||
@@ -742,7 +745,7 @@ describe('notes and tags', () => {
|
||||
})
|
||||
|
||||
const pinnedAndProtectedNote = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'A',
|
||||
}),
|
||||
)
|
||||
@@ -752,13 +755,13 @@ describe('notes and tags', () => {
|
||||
})
|
||||
|
||||
await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.Note, {
|
||||
await this.application.items.createTemplateItem(ContentType.Note, {
|
||||
title: 'A',
|
||||
}),
|
||||
)
|
||||
|
||||
const view = await this.application.mutator.insertItem(
|
||||
await this.application.mutator.createTemplateItem(ContentType.SmartView, {
|
||||
await this.application.items.createTemplateItem(ContentType.SmartView, {
|
||||
title: 'Protected or Pinned',
|
||||
predicate: {
|
||||
operator: 'or',
|
||||
@@ -794,7 +797,7 @@ describe('notes and tags', () => {
|
||||
const notePayload3 = Factory.createNotePayload('Bar')
|
||||
const notePayload4 = Factory.createNotePayload('Testing')
|
||||
|
||||
await this.application.itemManager.emitItemsFromPayloads(
|
||||
await this.application.mutator.emitItemsFromPayloads(
|
||||
[notePayload1, notePayload2, notePayload3, notePayload4, tagPayload1],
|
||||
PayloadEmitSource.LocalChanged,
|
||||
)
|
||||
@@ -824,7 +827,7 @@ describe('notes and tags', () => {
|
||||
const notePayload3 = Factory.createNotePayload('Testing FOO (Bar)')
|
||||
const notePayload4 = Factory.createNotePayload('This should not match')
|
||||
|
||||
await this.application.itemManager.emitItemsFromPayloads(
|
||||
await this.application.mutator.emitItemsFromPayloads(
|
||||
[notePayload1, notePayload2, notePayload3, notePayload4, tagPayload1],
|
||||
PayloadEmitSource.LocalChanged,
|
||||
)
|
||||
|
||||
@@ -75,8 +75,8 @@ describe('tags as folders', () => {
|
||||
const note2 = await Factory.createMappedNote(this.application, 'my second note')
|
||||
|
||||
// ## The user add a note to the child tag
|
||||
await this.application.items.addTagToNote(note1, tags.child, true)
|
||||
await this.application.items.addTagToNote(note2, tags.another, true)
|
||||
await this.application.mutator.addTagToNote(note1, tags.child, true)
|
||||
await this.application.mutator.addTagToNote(note2, tags.another, true)
|
||||
|
||||
// ## The note has been added to other tags
|
||||
const note1Tags = await this.application.items.getSortedTagsForItem(note1)
|
||||
|
||||
@@ -56,7 +56,7 @@ describe('mapping performance', () => {
|
||||
const batchSize = 100
|
||||
for (let i = 0; i < payloads.length; i += batchSize) {
|
||||
const subArray = payloads.slice(currentIndex, currentIndex + batchSize)
|
||||
await application.itemManager.emitItemsFromPayloads(subArray, PayloadEmitSource.LocalChanged)
|
||||
await application.mutator.emitItemsFromPayloads(subArray, PayloadEmitSource.LocalChanged)
|
||||
currentIndex += batchSize
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ describe('mapping performance', () => {
|
||||
const batchSize = 100
|
||||
for (let i = 0; i < payloads.length; i += batchSize) {
|
||||
var subArray = payloads.slice(currentIndex, currentIndex + batchSize)
|
||||
await application.itemManager.emitItemsFromPayloads(subArray, PayloadEmitSource.LocalChanged)
|
||||
await application.mutator.emitItemsFromPayloads(subArray, PayloadEmitSource.LocalChanged)
|
||||
currentIndex += batchSize
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user