feat: add snjs package

This commit is contained in:
Karol Sójko
2022-07-06 14:04:18 +02:00
parent 321a055bae
commit 0e40469e2f
296 changed files with 46109 additions and 187 deletions

View File

@@ -0,0 +1,53 @@
import {
DecryptedPayload,
FillItemContent,
ItemsKeyContent,
PayloadEmitSource,
PayloadTimestampDefaults,
} from '@standardnotes/models'
import { PayloadManager } from './PayloadManager'
import { InternalEventBusInterface } from '@standardnotes/services'
import { ContentType } from '@standardnotes/common'
describe('payload manager', () => {
let payloadManager: PayloadManager
let internalEventBus: InternalEventBusInterface
beforeEach(() => {
internalEventBus = {} as jest.Mocked<InternalEventBusInterface>
internalEventBus.publish = jest.fn()
payloadManager = new PayloadManager(internalEventBus)
})
it('emitting a payload should emit as-is and not merge on top of existing payload', async () => {
const decrypted = new DecryptedPayload({
uuid: '123',
content_type: ContentType.ItemsKey,
content: FillItemContent<ItemsKeyContent>({
itemsKey: 'secret',
}),
...PayloadTimestampDefaults(),
updated_at_timestamp: 1,
dirty: true,
})
await payloadManager.emitPayload(decrypted, PayloadEmitSource.LocalInserted)
const nondirty = new DecryptedPayload({
uuid: '123',
content_type: ContentType.ItemsKey,
...PayloadTimestampDefaults(),
updated_at_timestamp: 2,
content: FillItemContent<ItemsKeyContent>({
itemsKey: 'secret',
}),
})
await payloadManager.emitPayload(nondirty, PayloadEmitSource.LocalChanged)
const result = payloadManager.findOne('123')
expect(result?.dirty).toBeFalsy()
})
})