Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept empty input to Usernotes constructor #63

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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