Skip to content

Commit

Permalink
allow empty values passed to Usernotes constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
eritbh committed Mar 14, 2024
1 parent babf8b2 commit 1d08144
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 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
7 changes: 6 additions & 1 deletion src/classes/Usernotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,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 1d08144

Please sign in to comment.