Skip to content

Commit c91eedf

Browse files
authored
Should not throw when creating initials on event with undefined username (#33)
* Should not throw when creating initials on event with undefined username Fixes #32 * Fixes broken test
1 parent c4e67b5 commit c91eedf

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/crash/crash-api-client/crash-api-client.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('CrashApiClient', () => {
2828
describe('reprocessCrash', () => {
2929
it('should return 200 for database fred and a recent crash that has symbols', async () => {
3030
// TODO BG https://github.com/BugSplat-Git/bugsplat-js-api-client/issues/19
31-
const response = await client.reprocessCrash(database, 100820);
31+
const response = await client.reprocessCrash(database, 103339);
3232

3333
expect(response.success).toEqual(true);
3434
});

src/events/event/create-event-from-api-response.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ function getInitialsOrDefault(event: any): string {
2121
return `${firstInitial}${lastInitial}`;
2222
}
2323

24-
return event.username.substring(0, 2);
24+
return event.username?.substring(0, 2) ?? '';
2525
}

src/events/event/event.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,16 @@ describe('Events', () => {
5353
jasmine.arrayContaining([expected])
5454
);
5555
});
56+
57+
it('should return empty string if username is null or undefined', () => {
58+
const eventWithoutUsername = {
59+
...fakeEvents[0],
60+
username: undefined
61+
};
62+
63+
const results = convertEventsToEventStreamEvents([eventWithoutUsername]);
64+
65+
expect(results[0].subject.initials).toEqual('');
66+
});
5667
});
5768
});

0 commit comments

Comments
 (0)