Skip to content

Commit

Permalink
fix(models): filter out items with unknown content type (#2192)
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Feb 1, 2023
1 parent 0a72e8f commit b3cfb87
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ContentType } from '@standardnotes/common'
import { isObject, isString } from '@standardnotes/utils'
import { DecryptedTransferPayload } from './DecryptedTransferPayload'
import { DeletedTransferPayload } from './DeletedTransferPayload'
Expand All @@ -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
}

0 comments on commit b3cfb87

Please sign in to comment.