chore: fix uuid generation for importers

This commit is contained in:
Mo
2023-08-07 05:06:11 -05:00
parent cedd8e1006
commit ee473fe34d
17 changed files with 94 additions and 47 deletions

View File

@@ -1,13 +1,18 @@
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { NativeFeatureIdentifier, NoteType } from '@standardnotes/features'
import { AegisToAuthenticatorConverter } from './AegisToAuthenticatorConverter'
import data from './testData'
import { UuidGenerator } from '@standardnotes/utils'
UuidGenerator.SetGenerator(() => String(Math.random()))
import { GenerateUuid } from '@standardnotes/services'
describe('AegisConverter', () => {
const crypto = {
generateUUID: () => String(Math.random()),
} as unknown as PureCryptoInterface
const generateUuid = new GenerateUuid(crypto)
it('should parse entries', () => {
const converter = new AegisToAuthenticatorConverter()
const converter = new AegisToAuthenticatorConverter(generateUuid)
const result = converter.parseEntries(data)
@@ -28,7 +33,7 @@ describe('AegisConverter', () => {
})
it('should create note from entries with editor info', () => {
const converter = new AegisToAuthenticatorConverter()
const converter = new AegisToAuthenticatorConverter(generateUuid)
const parsedEntries = converter.parseEntries(data)
@@ -55,7 +60,7 @@ describe('AegisConverter', () => {
})
it('should create note from entries without editor info', () => {
const converter = new AegisToAuthenticatorConverter()
const converter = new AegisToAuthenticatorConverter(generateUuid)
const parsedEntries = converter.parseEntries(data)

View File

@@ -2,7 +2,7 @@ import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models'
import { readFileAsText } from '../Utils'
import { NativeFeatureIdentifier, NoteType } from '@standardnotes/features'
import { ContentType } from '@standardnotes/domain-core'
import { UuidGenerator } from '@standardnotes/utils'
import { GenerateUuid } from '@standardnotes/services'
type AegisData = {
db: {
@@ -27,7 +27,7 @@ type AuthenticatorEntry = {
}
export class AegisToAuthenticatorConverter {
constructor() {}
constructor(private _generateUuid: GenerateUuid) {}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
static isValidAegisJson(json: any): boolean {
@@ -63,7 +63,7 @@ export class AegisToAuthenticatorConverter {
created_at_timestamp: file.lastModified,
updated_at: new Date(file.lastModified),
updated_at_timestamp: file.lastModified,
uuid: UuidGenerator.GenerateUuid(),
uuid: this._generateUuid.execute().getValue(),
content_type: ContentType.TYPES.Note,
content: {
title: file.name.split('.')[0],