Skip to content

Commit fd8785f

Browse files
committed
2 parents 50ab35c + ee24a2c commit fd8785f

File tree

4 files changed

+51
-21
lines changed

4 files changed

+51
-21
lines changed

src/renderer/components/avatars/AvatarWithFallback.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, screen } from '@testing-library/react';
1+
import { fireEvent, render, screen } from '@testing-library/react';
22

33
import { type Link, Size } from '../../types';
44
import {
@@ -47,8 +47,8 @@ describe('renderer/components/avatars/AvatarWithFallback.tsx', () => {
4747
// Find the avatar element by its alt text
4848
const avatar = screen.getByAltText('gitify-app') as HTMLImageElement;
4949

50-
// Simulate an error event on the image element
51-
avatar.dispatchEvent(new Event('error'));
50+
// Simulate image load error (wrapped in act via fireEvent)
51+
fireEvent.error(avatar);
5252

5353
expect(screen.getByTestId('avatar')).toMatchSnapshot();
5454
});
@@ -59,8 +59,8 @@ describe('renderer/components/avatars/AvatarWithFallback.tsx', () => {
5959
// Find the avatar element by its alt text
6060
const avatar = screen.getByAltText('gitify-app') as HTMLImageElement;
6161

62-
// Simulate an error event on the image element
63-
avatar.dispatchEvent(new Event('error'));
62+
// Simulate image load error (wrapped in act via fireEvent)
63+
fireEvent.error(avatar);
6464

6565
expect(screen.getByTestId('avatar')).toMatchSnapshot();
6666
});

src/renderer/components/avatars/__snapshots__/AvatarWithFallback.test.tsx.snap

Lines changed: 28 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/utils/api/errors.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { AxiosError, type AxiosResponse } from 'axios';
22

3+
import { EVENTS } from '../../../shared/events';
4+
35
import type { Link } from '../../types';
46
import type { GitHubRESTError } from '../../typesGitHub';
57
import { Errors } from '../errors';
@@ -93,6 +95,18 @@ describe('renderer/utils/api/errors.ts', () => {
9395
});
9496
});
9597

98+
it('bad credentials - safe storage', async () => {
99+
const mockError: Partial<AxiosError<GitHubRESTError>> = {
100+
message: `Error invoking remote method '${EVENTS.SAFE_STORAGE_DECRYPT}': Error: Error while decrypting the ciphertext provided to safeStorage.decryptString. Ciphertext does not appear to be encrypted.`,
101+
};
102+
103+
const result = determineFailureType(
104+
mockError as AxiosError<GitHubRESTError>,
105+
);
106+
107+
expect(result).toBe(Errors.BAD_CREDENTIALS);
108+
});
109+
96110
it('unknown error', async () => {
97111
const mockError: Partial<AxiosError<GitHubRESTError>> = {
98112
code: 'anything',

src/renderer/utils/api/errors.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export function determineFailureType(
1313
return Errors.NETWORK;
1414
}
1515

16+
if (err.message?.includes('safeStorage')) {
17+
return Errors.BAD_CREDENTIALS;
18+
}
19+
1620
if (code !== AxiosError.ERR_BAD_REQUEST) {
1721
return Errors.UNKNOWN;
1822
}

0 commit comments

Comments
 (0)