Merge branch 'main' of github.com:standardnotes/app
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { ContentType } from '@standardnotes/common'
|
||||
import { PayloadTimestampDefaults } from '../../Payload'
|
||||
import { isCorruptTransferPayload } from './TypeCheck'
|
||||
|
||||
describe('type check', () => {
|
||||
describe('isCorruptTransferPayload', () => {
|
||||
it('should return false if is valid', () => {
|
||||
expect(
|
||||
isCorruptTransferPayload({
|
||||
uuid: '123',
|
||||
content_type: ContentType.Note,
|
||||
content: '123',
|
||||
...PayloadTimestampDefaults(),
|
||||
}),
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('should return true if uuid is missing', () => {
|
||||
expect(
|
||||
isCorruptTransferPayload({
|
||||
uuid: undefined as never,
|
||||
content_type: ContentType.Note,
|
||||
content: '123',
|
||||
...PayloadTimestampDefaults(),
|
||||
}),
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('should return true if is deleted but has content', () => {
|
||||
expect(
|
||||
isCorruptTransferPayload({
|
||||
uuid: '123',
|
||||
content_type: ContentType.Note,
|
||||
content: '123',
|
||||
deleted: true,
|
||||
...PayloadTimestampDefaults(),
|
||||
}),
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('should return true if content type is unknown', () => {
|
||||
expect(
|
||||
isCorruptTransferPayload({
|
||||
uuid: '123',
|
||||
content_type: ContentType.Unknown,
|
||||
content: '123',
|
||||
...PayloadTimestampDefaults(),
|
||||
}),
|
||||
).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ContentType } from '@standardnotes/common'
|
||||
import { isObject, isString } from '@standardnotes/utils'
|
||||
import { DecryptedTransferPayload } from './DecryptedTransferPayload'
|
||||
import { DeletedTransferPayload } from './DeletedTransferPayload'
|
||||
@@ -24,5 +25,6 @@ export function isDeletedTransferPayload(payload: TransferPayload): payload is D
|
||||
|
||||
export function isCorruptTransferPayload(payload: TransferPayload): boolean {
|
||||
const invalidDeletedState = payload.deleted === true && payload.content != undefined
|
||||
return payload.uuid == undefined || invalidDeletedState
|
||||
|
||||
return payload.uuid == undefined || invalidDeletedState || payload.content_type === ContentType.Unknown
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user