Files
standardnotes-app-web/packages/snjs/lib/Services/Mutator/MutatorService.spec.ts
Mo 767d354780 feat: display number of files for 'Files' view (#2065)
* feat: display number of files for 'Files' view

* feat: include files count in Preferences > Security
2022-11-28 15:38:50 -06:00

83 lines
2.3 KiB
TypeScript

import { SNHistoryManager } from './../History/HistoryManager'
import { NoteContent, SNNote, FillItemContent, DecryptedPayload, PayloadTimestampDefaults } from '@standardnotes/models'
import { ContentType } from '@standardnotes/common'
import { EncryptionService, InternalEventBusInterface } from '@standardnotes/services'
import {
ChallengeService,
MutatorService,
PayloadManager,
SNComponentManager,
SNProtectionService,
ItemManager,
SNSyncService,
} from '../'
import { UuidGenerator } from '@standardnotes/utils'
const setupRandomUuid = () => {
UuidGenerator.SetGenerator(() => String(Math.random()))
}
describe('mutator service', () => {
let mutatorService: MutatorService
let payloadManager: PayloadManager
let itemManager: ItemManager
let syncService: SNSyncService
let protectionService: SNProtectionService
let protocolService: EncryptionService
let challengeService: ChallengeService
let componentManager: SNComponentManager
let historyService: SNHistoryManager
let internalEventBus: InternalEventBusInterface
beforeEach(() => {
setupRandomUuid()
internalEventBus = {} as jest.Mocked<InternalEventBusInterface>
internalEventBus.publish = jest.fn()
payloadManager = new PayloadManager(internalEventBus)
itemManager = new ItemManager(payloadManager, internalEventBus)
mutatorService = new MutatorService(
itemManager,
syncService,
protectionService,
protocolService,
payloadManager,
challengeService,
componentManager,
historyService,
internalEventBus,
)
})
const insertNote = (title: string) => {
const note = new SNNote(
new DecryptedPayload({
uuid: String(Math.random()),
content_type: ContentType.Note,
content: FillItemContent<NoteContent>({
title: title,
}),
...PayloadTimestampDefaults(),
}),
)
return mutatorService.insertItem(note)
}
describe('note modifications', () => {
it('pinning should not update timestamps', async () => {
const note = await insertNote('hello')
const pinnedNote = await mutatorService.changeItem(
note,
(mutator) => {
mutator.pinned = true
},
false,
)
expect(note.userModifiedDate).toEqual(pinnedNote?.userModifiedDate)
})
})
})