Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(models): filter out items with unknown content type #2192

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
}