refactor: importer service (#2674)
This commit is contained in:
@@ -4,33 +4,30 @@
|
||||
|
||||
import { jsonTextContentData, htmlTestData, jsonListContentData } from './testData'
|
||||
import { GoogleKeepConverter } from './GoogleKeepConverter'
|
||||
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
|
||||
import { GenerateUuid } from '@standardnotes/services'
|
||||
import { FileItem, SuperConverterServiceInterface } from '@standardnotes/snjs'
|
||||
import { ContentType, DecryptedTransferPayload, NoteContent } from '@standardnotes/snjs'
|
||||
import { CreateNoteFn } from '../Converter'
|
||||
|
||||
describe('GoogleKeepConverter', () => {
|
||||
const crypto = {
|
||||
generateUUID: () => String(Math.random()),
|
||||
} as unknown as PureCryptoInterface
|
||||
|
||||
const superConverterService: SuperConverterServiceInterface = {
|
||||
isValidSuperString: () => true,
|
||||
convertOtherFormatToSuperString: (data: string) => data,
|
||||
convertSuperStringToOtherFormat: async (data: string) => data,
|
||||
getEmbeddedFileIDsFromSuperString: () => [],
|
||||
uploadAndReplaceInlineFilesInSuperString: async (
|
||||
superString: string,
|
||||
_uploadFile: (file: File) => Promise<FileItem | undefined>,
|
||||
_linkFile: (file: FileItem) => Promise<void>,
|
||||
_generateUuid: GenerateUuid,
|
||||
) => superString,
|
||||
}
|
||||
const generateUuid = new GenerateUuid(crypto)
|
||||
const createNote: CreateNoteFn = ({ title, text, createdAt, updatedAt, trashed, archived, pinned }) =>
|
||||
({
|
||||
uuid: Math.random().toString(),
|
||||
created_at: createdAt,
|
||||
updated_at: updatedAt,
|
||||
content_type: ContentType.TYPES.Note,
|
||||
content: {
|
||||
title,
|
||||
text,
|
||||
trashed,
|
||||
archived,
|
||||
pinned,
|
||||
references: [],
|
||||
},
|
||||
}) as unknown as DecryptedTransferPayload<NoteContent>
|
||||
|
||||
it('should parse json data', () => {
|
||||
const converter = new GoogleKeepConverter(superConverterService, generateUuid)
|
||||
const converter = new GoogleKeepConverter()
|
||||
|
||||
const textContent = converter.tryParseAsJson(jsonTextContentData, false)
|
||||
const textContent = converter.tryParseAsJson(jsonTextContentData, createNote, (md) => md)
|
||||
|
||||
expect(textContent).not.toBeNull()
|
||||
expect(textContent?.created_at).toBeInstanceOf(Date)
|
||||
@@ -43,7 +40,7 @@ describe('GoogleKeepConverter', () => {
|
||||
expect(textContent?.content.archived).toBe(false)
|
||||
expect(textContent?.content.pinned).toBe(false)
|
||||
|
||||
const listContent = converter.tryParseAsJson(jsonListContentData, false)
|
||||
const listContent = converter.tryParseAsJson(jsonListContentData, createNote, (md) => md)
|
||||
|
||||
expect(listContent).not.toBeNull()
|
||||
expect(listContent?.created_at).toBeInstanceOf(Date)
|
||||
@@ -58,13 +55,15 @@ describe('GoogleKeepConverter', () => {
|
||||
})
|
||||
|
||||
it('should parse html data', () => {
|
||||
const converter = new GoogleKeepConverter(superConverterService, generateUuid)
|
||||
const converter = new GoogleKeepConverter()
|
||||
|
||||
const result = converter.tryParseAsHtml(
|
||||
htmlTestData,
|
||||
{
|
||||
name: 'note-2.html',
|
||||
},
|
||||
createNote,
|
||||
(html) => html,
|
||||
false,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user