feat: add models package
This commit is contained in:
80
packages/models/src/Domain/Utilities/Test/SpecUtils.ts
Normal file
80
packages/models/src/Domain/Utilities/Test/SpecUtils.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { TagContent } from './../../Syncable/Tag/Tag'
|
||||
import { ContentType } from '@standardnotes/common'
|
||||
import { FillItemContent, ItemContent } from '../../Abstract/Content/ItemContent'
|
||||
import { DecryptedPayload, PayloadSource, PayloadTimestampDefaults } from '../../Abstract/Payload'
|
||||
import { FileContent, FileItem } from '../../Syncable/File'
|
||||
import { NoteContent, SNNote } from '../../Syncable/Note'
|
||||
import { SNTag } from '../../Syncable/Tag'
|
||||
|
||||
let currentId = 0
|
||||
|
||||
export const mockUuid = () => {
|
||||
return `${currentId++}`
|
||||
}
|
||||
|
||||
export const createNote = (payload?: Partial<NoteContent>): SNNote => {
|
||||
return new SNNote(
|
||||
new DecryptedPayload(
|
||||
{
|
||||
uuid: mockUuid(),
|
||||
content_type: ContentType.Note,
|
||||
content: FillItemContent({ ...payload }),
|
||||
...PayloadTimestampDefaults(),
|
||||
},
|
||||
PayloadSource.Constructor,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
export const createNoteWithContent = (content: Partial<NoteContent>, createdAt?: Date): SNNote => {
|
||||
return new SNNote(
|
||||
new DecryptedPayload(
|
||||
{
|
||||
uuid: mockUuid(),
|
||||
content_type: ContentType.Note,
|
||||
content: FillItemContent<NoteContent>(content),
|
||||
...PayloadTimestampDefaults(),
|
||||
created_at: createdAt || new Date(),
|
||||
},
|
||||
PayloadSource.Constructor,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
export const createTag = (title = 'photos') => {
|
||||
return new SNTag(
|
||||
new DecryptedPayload(
|
||||
{
|
||||
uuid: mockUuid(),
|
||||
content_type: ContentType.Tag,
|
||||
content: FillItemContent<TagContent>({ title }),
|
||||
...PayloadTimestampDefaults(),
|
||||
},
|
||||
PayloadSource.Constructor,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
export const createFile = (name = 'screenshot.png') => {
|
||||
return new FileItem(
|
||||
new DecryptedPayload(
|
||||
{
|
||||
uuid: mockUuid(),
|
||||
content_type: ContentType.File,
|
||||
content: FillItemContent<FileContent>({ name }),
|
||||
...PayloadTimestampDefaults(),
|
||||
},
|
||||
PayloadSource.Constructor,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
export const pinnedContent = (): Partial<ItemContent> => {
|
||||
return {
|
||||
appData: {
|
||||
'org.standardnotes.sn': {
|
||||
pinned: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user