Skip to content

Commit

Permalink
Accept empty input to Usernotes constructor (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
eritbh authored Oct 31, 2024
1 parent f9fe4de commit 3859e96
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 13 additions & 1 deletion src/classes/Usernotes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
11 changes: 6 additions & 5 deletions src/classes/Usernotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +19,12 @@ export class Usernotes {
/** A mapping of usernames to notes on the given user. */
private users = new Map<string, Usernote[]>();

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);

Expand Down

0 comments on commit 3859e96

Please sign in to comment.