refactor: importer service (#2674)

This commit is contained in:
Aman Harwara
2023-12-05 02:55:32 +05:30
committed by GitHub
parent 9265e7afe9
commit 85ecb10924
17 changed files with 509 additions and 518 deletions

View File

@@ -1,19 +1,28 @@
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models'
import { SimplenoteConverter } from './SimplenoteConverter'
import data from './testData'
import { GenerateUuid } from '@standardnotes/services'
import { ContentType } from '@standardnotes/domain-core'
import { CreateNoteFn } from '../Converter'
describe('SimplenoteConverter', () => {
const crypto = {
generateUUID: () => String(Math.random()),
} as unknown as PureCryptoInterface
const generateUuid = new GenerateUuid(crypto)
const createNote: CreateNoteFn = ({ title, text, trashed, createdAt, updatedAt }) =>
({
uuid: Math.random().toString(),
created_at: createdAt,
updated_at: updatedAt,
content_type: ContentType.TYPES.Note,
content: {
title,
text,
trashed,
references: [],
},
}) as unknown as DecryptedTransferPayload<NoteContent>
it('should parse', () => {
const converter = new SimplenoteConverter(generateUuid)
const converter = new SimplenoteConverter()
const result = converter.parse(data)
const result = converter.parse(data, createNote)
expect(result).not.toBeNull()
expect(result?.length).toBe(3)