chore: fix ContentType usage (#2353)

* chore: fix ContentType usage

* chore: fix specs
This commit is contained in:
Karol Sójko
2023-07-12 13:53:29 +02:00
committed by GitHub
parent d057cdff84
commit 325737bfbd
247 changed files with 1092 additions and 1060 deletions

View File

@@ -62,7 +62,7 @@ describe('online conflict handling', function () {
}
it('components should not be duplicated under any circumstances', async function () {
const payload = createDirtyPayload(ContentType.Component)
const payload = createDirtyPayload(ContentType.TYPES.Component)
const item = await this.application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
@@ -90,7 +90,7 @@ describe('online conflict handling', function () {
})
it('items keys should not be duplicated under any circumstances', async function () {
const payload = createDirtyPayload(ContentType.ItemsKey)
const payload = createDirtyPayload(ContentType.TYPES.ItemsKey)
const item = await this.application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged)
this.expectedItemCount++
await this.application.syncService.sync(syncOptions)
@@ -527,13 +527,13 @@ describe('online conflict handling', function () {
}).timeout(60000)
it('duplicating an item should maintian its relationships', async function () {
const payload1 = Factory.createStorageItemPayload(ContentType.Tag)
const payload2 = Factory.createStorageItemPayload(ContentType.UserPrefs)
const payload1 = Factory.createStorageItemPayload(ContentType.TYPES.Tag)
const payload2 = Factory.createStorageItemPayload(ContentType.TYPES.UserPrefs)
this.expectedItemCount -= 1 /** auto-created user preferences */
await this.application.mutator.emitItemsFromPayloads([payload1, payload2], PayloadEmitSource.LocalChanged)
this.expectedItemCount += 2
let tag = this.application.itemManager.getItems(ContentType.Tag)[0]
let userPrefs = this.application.itemManager.getItems(ContentType.UserPrefs)[0]
let tag = this.application.itemManager.getItems(ContentType.TYPES.Tag)[0]
let userPrefs = this.application.itemManager.getItems(ContentType.TYPES.UserPrefs)[0]
expect(tag).to.be.ok
expect(userPrefs).to.be.ok
@@ -567,7 +567,7 @@ describe('online conflict handling', function () {
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
expect(rawPayloads.length).to.equal(this.expectedItemCount)
const fooItems = this.application.itemManager.getItems(ContentType.Tag)
const fooItems = this.application.itemManager.getItems(ContentType.TYPES.Tag)
const fooItem2 = fooItems[1]
expect(fooItem2.content.conflict_of).to.equal(tag.uuid)
@@ -772,9 +772,9 @@ describe('online conflict handling', function () {
let backupFile = await this.application.createEncryptedBackupFileForAutomatedDesktopBackups()
/** Sort matters, and is the cause of the original issue, where tag comes before the note */
backupFile.items = [
backupFile.items.find((i) => i.content_type === ContentType.ItemsKey),
backupFile.items.find((i) => i.content_type === ContentType.Tag),
backupFile.items.find((i) => i.content_type === ContentType.Note),
backupFile.items.find((i) => i.content_type === ContentType.TYPES.ItemsKey),
backupFile.items.find((i) => i.content_type === ContentType.TYPES.Tag),
backupFile.items.find((i) => i.content_type === ContentType.TYPES.Note),
]
backupFile = JSON.parse(JSON.stringify(backupFile))
/** Register new account and import this same data */
@@ -806,10 +806,10 @@ describe('online conflict handling', function () {
})
let backupFile = await this.application.createEncryptedBackupFileForAutomatedDesktopBackups()
backupFile.items = [
backupFile.items.find((i) => i.content_type === ContentType.ItemsKey),
backupFile.items.filter((i) => i.content_type === ContentType.Note)[0],
backupFile.items.filter((i) => i.content_type === ContentType.Note)[1],
backupFile.items.find((i) => i.content_type === ContentType.Tag),
backupFile.items.find((i) => i.content_type === ContentType.TYPES.ItemsKey),
backupFile.items.filter((i) => i.content_type === ContentType.TYPES.Note)[0],
backupFile.items.filter((i) => i.content_type === ContentType.TYPES.Note)[1],
backupFile.items.find((i) => i.content_type === ContentType.TYPES.Tag),
]
backupFile = JSON.parse(JSON.stringify(backupFile))
/** Register new account and import this same data */

View File

@@ -53,8 +53,8 @@ describe('notes + tags syncing', function () {
const tagPayload = pair[1]
await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged)
const note = this.application.itemManager.getItems([ContentType.Note])[0]
const tag = this.application.itemManager.getItems([ContentType.Tag])[0]
const note = this.application.itemManager.getItems([ContentType.TYPES.Note])[0]
const tag = this.application.itemManager.getItems([ContentType.TYPES.Tag])[0]
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
expect(this.application.itemManager.getDisplayableTags().length).to.equal(1)

View File

@@ -64,8 +64,8 @@ describe('offline syncing', () => {
const rawPayloads2 = await this.application.diskStorageService.getAllRawPayloads()
expect(rawPayloads2.length).to.equal(this.expectedItemCount)
const itemsKeyRaw = (await Factory.getStoragePayloadsOfType(this.application, ContentType.ItemsKey))[0]
const noteRaw = (await Factory.getStoragePayloadsOfType(this.application, ContentType.Note))[0]
const itemsKeyRaw = (await Factory.getStoragePayloadsOfType(this.application, ContentType.TYPES.ItemsKey))[0]
const noteRaw = (await Factory.getStoragePayloadsOfType(this.application, ContentType.TYPES.Note))[0]
/** Encrypts with default items key */
expect(typeof noteRaw.content).to.equal('string')

View File

@@ -54,7 +54,7 @@ describe('online syncing', function () {
})
function noteObjectsFromObjects(items) {
return items.filter((item) => item.content_type === ContentType.Note)
return items.filter((item) => item.content_type === ContentType.TYPES.Note)
}
it('should register and sync basic model online', async function () {
@@ -577,7 +577,7 @@ describe('online syncing', function () {
await this.application.syncService.sync(syncOptions)
this.expectedItemCount++
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
const notePayload = rawPayloads.find((p) => p.content_type === ContentType.Note)
const notePayload = rawPayloads.find((p) => p.content_type === ContentType.TYPES.Note)
expect(typeof notePayload.content).to.equal('string')
})
@@ -593,7 +593,7 @@ describe('online syncing', function () {
await Factory.sleep(0.3)
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
const notePayload = rawPayloads.find((p) => p.content_type === ContentType.Note)
const notePayload = rawPayloads.find((p) => p.content_type === ContentType.TYPES.Note)
expect(typeof notePayload.content).to.equal('string')
})
@@ -611,7 +611,7 @@ describe('online syncing', function () {
)
this.expectedItemCount++
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
const notePayload = rawPayloads.find((p) => p.content_type === ContentType.Note)
const notePayload = rawPayloads.find((p) => p.content_type === ContentType.TYPES.Note)
expect(typeof notePayload.content).to.equal('string')
expect(notePayload.content.length).to.be.above(text.length)
})
@@ -790,7 +790,7 @@ describe('online syncing', function () {
/** Create an item and sync it */
let note = await Factory.createMappedNote(this.application)
this.application.itemManager.addObserver(ContentType.Note, ({ source }) => {
this.application.itemManager.addObserver(ContentType.TYPES.Note, ({ source }) => {
if (source === PayloadEmitSource.RemoteSaved) {
actualSaveCount++
}
@@ -837,7 +837,7 @@ describe('online syncing', function () {
/** Create an item and sync it */
let note = await Factory.createMappedNote(this.application)
this.application.itemManager.addObserver(ContentType.Note, ({ source }) => {
this.application.itemManager.addObserver(ContentType.TYPES.Note, ({ source }) => {
if (source === PayloadEmitSource.RemoteSaved) {
actualSaveCount++
}
@@ -876,7 +876,7 @@ describe('online syncing', function () {
let didPerformMutatation = false
const newText = `${Math.random()}`
this.application.itemManager.addObserver(ContentType.Note, async ({ changed, source }) => {
this.application.itemManager.addObserver(ContentType.TYPES.Note, async ({ changed, source }) => {
if (source === PayloadEmitSource.RemoteSaved) {
actualSaveCount++
} else if (source === PayloadEmitSource.PreSyncSave && !didPerformMutatation) {
@@ -1015,7 +1015,7 @@ describe('online syncing', function () {
it('deleting an item permanently should include it in PayloadEmitSource.PreSyncSave item change observer', async function () {
let conditionMet = false
this.application.streamItems([ContentType.Note], async ({ removed, source }) => {
this.application.streamItems([ContentType.TYPES.Note], async ({ removed, source }) => {
if (source === PayloadEmitSource.PreSyncSave && removed.length === 1) {
conditionMet = true
}