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

node: Allow the avatar URL and display name to be null #128

Merged
merged 1 commit into from
May 15, 2023
Merged
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
2 changes: 1 addition & 1 deletion seshat-node/src/utils.rs
Original file line number Diff line number Diff line change
@@ -398,7 +398,7 @@ pub(crate) fn parse_profile(
) -> Result<Profile, neon::result::Throw> {
let get_optional_string =
|cx: &mut FunctionContext, value: Handle<'_, JsValue>, error: &str| {
if value.is_a::<JsUndefined, _>(cx) {
if value.is_a::<JsUndefined, _>(cx) || value.is_a::<JsNull, _>(cx) {
Ok(None)
} else {
Ok(Some(
15 changes: 12 additions & 3 deletions seshat-node/test/test.js
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@ const checkPoint = {
}

describe('Database', function() {
it('should be created succesfully.', function() {
it('should be created successfully.', function() {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'seshat-'));
const db = new Seshat(tempDir);
});
@@ -183,7 +183,7 @@ describe('Database', function() {
db.addEvent(matrixEvent, matrixProfileOnlyDisplayName);
});

it('should allow events to be commited', function() {
it('should allow events to be committed', function() {
const db = createDb();
db.commitSync(true, true);

@@ -194,7 +194,7 @@ describe('Database', function() {
expect(ret).toBeUndefined();
});

it('should allow events to be commited using a promise', async function() {
it('should allow events to be committed using a promise', async function() {
const db = createDb();
await db.commit(true);
});
@@ -596,6 +596,15 @@ describe('Database', function() {
expect(results.results[0].result).toEqual(fileEvent);
});

it('should accept events if the avatar URL is null.', function() {
const badProfile = {
displayname: 'Alice (from wonderland)',
avatar_url: null,
};

db.addEvent(matrixEvent, badProfile);
});

it('should throw an error when adding events with missing fields.', function() {
delete matrixEvent.content;
expect(() => db.addEvent(matrixEvent, matrixProfile)).toThrow(TypeError('Event doesn\'t contain any content'));