From ac40046bc26f23e15149954f642a476d4a9dd964 Mon Sep 17 00:00:00 2001 From: Carlos Miceli Date: Sat, 8 Nov 2025 00:57:08 -0300 Subject: [PATCH 1/3] handle null entry for avatar local --- src/libs/Avatars/PresetAvatarCatalog.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libs/Avatars/PresetAvatarCatalog.ts b/src/libs/Avatars/PresetAvatarCatalog.ts index d512657bd2ef..7a17d55ae337 100644 --- a/src/libs/Avatars/PresetAvatarCatalog.ts +++ b/src/libs/Avatars/PresetAvatarCatalog.ts @@ -216,8 +216,20 @@ function getLetterAvatar(name?: string): React.FC | null { const PRESET_AVATAR_CATALOG_ORDERED = buildOrderedAvatars(); -const getAvatarLocal = (id: PresetAvatarID) => PRESET_AVATAR_CATALOG[id].local; -const getAvatarURL = (id: PresetAvatarID) => PRESET_AVATAR_CATALOG[id].url; +const getAvatarLocal = (id: PresetAvatarID) => { + const entry = PRESET_AVATAR_CATALOG[id]; + if (!entry) { + return undefined; + } + return entry.local; +}; +const getAvatarURL = (id: PresetAvatarID) => { + const entry = PRESET_AVATAR_CATALOG[id]; + if (!entry) { + return undefined; + } + return entry.url; +}; /** * Type guard to check if a value is a valid PresetAvatarID From 35d25f058d9f991980619da12e0fd66c42d27a64 Mon Sep 17 00:00:00 2001 From: Carlos Miceli Date: Sat, 8 Nov 2025 01:17:04 -0300 Subject: [PATCH 2/3] ternary for drying --- src/libs/Avatars/PresetAvatarCatalog.ts | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/libs/Avatars/PresetAvatarCatalog.ts b/src/libs/Avatars/PresetAvatarCatalog.ts index 7a17d55ae337..95ad94d22a8b 100644 --- a/src/libs/Avatars/PresetAvatarCatalog.ts +++ b/src/libs/Avatars/PresetAvatarCatalog.ts @@ -216,20 +216,8 @@ function getLetterAvatar(name?: string): React.FC | null { const PRESET_AVATAR_CATALOG_ORDERED = buildOrderedAvatars(); -const getAvatarLocal = (id: PresetAvatarID) => { - const entry = PRESET_AVATAR_CATALOG[id]; - if (!entry) { - return undefined; - } - return entry.local; -}; -const getAvatarURL = (id: PresetAvatarID) => { - const entry = PRESET_AVATAR_CATALOG[id]; - if (!entry) { - return undefined; - } - return entry.url; -}; +const getAvatarLocal = (id: PresetAvatarID) => PRESET_AVATAR_CATALOG[id]?.local; +const getAvatarURL = (id: PresetAvatarID) => PRESET_AVATAR_CATALOG[id]?.url; /** * Type guard to check if a value is a valid PresetAvatarID From 9b86fbe3fe591c0db164ce06fbf7802971249b1c Mon Sep 17 00:00:00 2001 From: Carlos Miceli Date: Sat, 8 Nov 2025 01:17:22 -0300 Subject: [PATCH 3/3] update tests --- tests/unit/libs/Avatars/PresetAvatarCatalogTest.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/libs/Avatars/PresetAvatarCatalogTest.tsx b/tests/unit/libs/Avatars/PresetAvatarCatalogTest.tsx index 51e97017180f..2a2f5a88fe67 100644 --- a/tests/unit/libs/Avatars/PresetAvatarCatalogTest.tsx +++ b/tests/unit/libs/Avatars/PresetAvatarCatalogTest.tsx @@ -49,7 +49,9 @@ describe('PresetAvatarCatalog', () => { it('throws or returns undefined for an unknown ID', () => { // @ts-expect-error - This is a test for an unknown ID - expect(() => getAvatarLocal('not-a-real-id')).toThrow(); + expect(getAvatarLocal('not-a-real-id')).toBeUndefined(); + // @ts-expect-error - This is a test for an unknown ID + expect(getAvatarURL('not-a-real-id')).toBeUndefined(); }); it('ALL contains both default and seasonal IDs', () => {