From babf8b2d177b096828141a86407b961a7d575950 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 14 Mar 2024 07:50:26 -0400 Subject: [PATCH 1/2] delete comment resolved by #54 --- src/classes/Usernotes.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/classes/Usernotes.ts b/src/classes/Usernotes.ts index 9e96e60..3fc27eb 100644 --- a/src/classes/Usernotes.ts +++ b/src/classes/Usernotes.ts @@ -9,10 +9,6 @@ import { import {RawUsernotes, RawUsernotesConstants} from '../types/RawUsernotes'; import {Usernote} from '../types/Usernote'; -// TODO: nothing here handles username case correctly; go back and check the -// toolbox implementation of that for correctness later and write test -// cases for it - /** * A class that interfaces with the raw contents of a subreddit's `usernotes` * wiki page, automatically upgrading old storage schemas to the current version From 1d0814412721b17209660be4c2439344f136d2d9 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 14 Mar 2024 07:54:34 -0400 Subject: [PATCH 2/2] allow empty values passed to Usernotes constructor --- src/classes/Usernotes.test.ts | 14 +++++++++++++- src/classes/Usernotes.ts | 7 ++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/classes/Usernotes.test.ts b/src/classes/Usernotes.test.ts index e7e5b74..1de8953 100644 --- a/src/classes/Usernotes.test.ts +++ b/src/classes/Usernotes.test.ts @@ -3,7 +3,19 @@ import {compressBlob, decompressBlob} from '../helpers/usernotes'; import type {RawUsernotes} from '../types/RawUsernotes'; import {Usernotes} from './Usernotes'; -test.todo('constructor'); +test('constructor: accept empty input', t => { + t.assert( + new Usernotes() instanceof Usernotes, + 'passing nothing to Usernotes constructor should return a Usernotes instance', + ); + + t.assert( + new Usernotes('') instanceof Usernotes, + 'passing empty string to Usernotes constructor should return a Usernotes instance', + ); +}); + +test.todo('constructor: most other things'); test.todo('get: most other things'); diff --git a/src/classes/Usernotes.ts b/src/classes/Usernotes.ts index 3fc27eb..542fde6 100644 --- a/src/classes/Usernotes.ts +++ b/src/classes/Usernotes.ts @@ -19,7 +19,12 @@ export class Usernotes { /** A mapping of usernames to notes on the given user. */ private users = new Map(); - constructor (jsonString: string) { + constructor (jsonString?: string) { + // if we have no data to start with, we start fresh + if (!jsonString) { + return; + } + let data = migrateUsernotesToLatestSchema(JSON.parse(jsonString)); const rawUsers = decompressBlob(data.blob);