Skip to content
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
6 changes: 3 additions & 3 deletions src/__mocks__/mockedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
Notification,
Repository,
User,
} from '../typesGithub';
} from '../typesGitHub';
import Constants from '../utils/constants';

export const mockedEnterpriseAccounts: EnterpriseAccount[] = [
Expand Down Expand Up @@ -199,7 +199,7 @@ export const mockedSingleNotification: Notification = {

// 2 Notifications
// Repository : 'manosim/notifications-tests'
export const mockedGithubNotifications = [
export const mockedGitHubNotifications = [
mockedSingleNotification,
{
id: '148827438',
Expand Down Expand Up @@ -366,7 +366,7 @@ export const mockedEnterpriseNotifications = [
export const mockedAccountNotifications: AccountNotifications[] = [
{
hostname: 'github.com',
notifications: mockedGithubNotifications,
notifications: mockedGitHubNotifications,
},
{
hostname: 'github.gitify.io',
Expand Down
2 changes: 1 addition & 1 deletion src/__mocks__/partial-mocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Notification, Subject, User } from '../typesGithub';
import type { Notification, Subject, User } from '../typesGitHub';

export function partialMockNotification(
subject: Partial<Subject>,
Expand Down
4 changes: 2 additions & 2 deletions src/components/AccountNotifications.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TestRenderer from 'react-test-renderer';

import { mockedGithubNotifications } from '../__mocks__/mockedData';
import { mockedGitHubNotifications } from '../__mocks__/mockedData';
import { AccountNotifications } from './AccountNotifications';

jest.mock('./Repository', () => ({
Expand All @@ -11,7 +11,7 @@ describe('components/AccountNotifications.tsx', () => {
it('should render itself (github.com with notifications)', () => {
const props = {
hostname: 'github.com',
notifications: mockedGithubNotifications,
notifications: mockedGitHubNotifications,
showAccountHostname: true,
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/AccountNotifications.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChevronDownIcon, ChevronLeftIcon } from '@primer/octicons-react';

import type { Notification } from '../typesGithub';
import type { Notification } from '../typesGitHub';
import { RepositoryNotifications } from './Repository';

interface IProps {
Expand Down
2 changes: 1 addition & 1 deletion src/components/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from 'react';

import { AppContext } from '../context/App';
import type { Notification } from '../typesGithub';
import type { Notification } from '../typesGitHub';
import { openExternalLink } from '../utils/comms';
import { formatForDisplay, openInBrowser } from '../utils/helpers';
import {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Repository.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fireEvent, render, screen } from '@testing-library/react';
import TestRenderer from 'react-test-renderer';
import { mockedGithubNotifications } from '../__mocks__/mockedData';
import { mockedGitHubNotifications } from '../__mocks__/mockedData';
import { AppContext } from '../context/App';
import { RepositoryNotifications } from './Repository';
const { shell } = require('electron');
Expand All @@ -16,7 +16,7 @@ describe('components/Repository.tsx', () => {
const props = {
hostname: 'github.com',
repoName: 'manosim/gitify',
repoNotifications: mockedGithubNotifications,
repoNotifications: mockedGitHubNotifications,
};

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Repository.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type FC, useCallback, useContext } from 'react';
import { CSSTransition, TransitionGroup } from 'react-transition-group';

import { AppContext } from '../context/App';
import type { Notification } from '../typesGithub';
import type { Notification } from '../typesGitHub';
import { openExternalLink } from '../utils/comms';
import { NotificationRow } from './NotificationRow';

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
GitifyError,
SettingsState,
} from '../types';
import type { GithubRESTError, Notification } from '../typesGithub';
import type { GitHubRESTError, Notification } from '../typesGitHub';
import { apiRequestAuth } from '../utils/api-requests';
import { determineFailureType } from '../utils/api/errors';
import Constants from '../utils/constants';
Expand Down Expand Up @@ -198,7 +198,7 @@ export const useNotifications = (): NotificationsState => {
});
}),
)
.catch((err: AxiosError<GithubRESTError>) => {
.catch((err: AxiosError<GitHubRESTError>) => {
setIsFetching(false);
setRequestFailed(true);
setErrorDetails(determineFailureType(err));
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Notification } from './typesGithub';
import type { Notification } from './typesGitHub';

export interface AuthState {
token?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/typesGithub.ts → src/typesGitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export interface WorkflowRunAttributes {
status: CheckSuiteStatus | null;
}

export interface GithubRESTError {
export interface GitHubRESTError {
message: string;
documentation_url: string;
}
32 changes: 16 additions & 16 deletions src/utils/api/errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
import { AxiosError, type AxiosResponse } from 'axios';
import type { GithubRESTError } from '../../typesGithub';
import type { GitHubRESTError } from '../../typesGitHub';
import { Errors } from '../constants';
import { determineFailureType } from './errors';

describe('utils/api/errors.ts', () => {
it('network error', async () => {
const mockError: Partial<AxiosError<GithubRESTError>> = {
const mockError: Partial<AxiosError<GitHubRESTError>> = {
code: AxiosError.ERR_NETWORK,
};

const result = determineFailureType(
mockError as AxiosError<GithubRESTError>,
mockError as AxiosError<GitHubRESTError>,
);

expect(result).toBe(Errors.NETWORK);
});

describe('bad request errors', () => {
it('bad credentials', async () => {
const mockError: Partial<AxiosError<GithubRESTError>> = {
const mockError: Partial<AxiosError<GitHubRESTError>> = {
code: AxiosError.ERR_BAD_REQUEST,
status: 401,
response: createMockResponse(401, 'Bad credentials'),
};

const result = determineFailureType(
mockError as AxiosError<GithubRESTError>,
mockError as AxiosError<GitHubRESTError>,
);

expect(result).toBe(Errors.BAD_CREDENTIALS);
});

it('missing scopes', async () => {
const mockError: Partial<AxiosError<GithubRESTError>> = {
const mockError: Partial<AxiosError<GitHubRESTError>> = {
code: AxiosError.ERR_BAD_REQUEST,
status: 403,
response: createMockResponse(403, "Missing the 'notifications' scope"),
};

const result = determineFailureType(
mockError as AxiosError<GithubRESTError>,
mockError as AxiosError<GitHubRESTError>,
);

expect(result).toBe(Errors.MISSING_SCOPES);
});

it('rate limited - primary', async () => {
const mockError: Partial<AxiosError<GithubRESTError>> = {
const mockError: Partial<AxiosError<GitHubRESTError>> = {
code: AxiosError.ERR_BAD_REQUEST,
status: 403,
response: createMockResponse(403, 'API rate limit exceeded'),
};

const result = determineFailureType(
mockError as AxiosError<GithubRESTError>,
mockError as AxiosError<GitHubRESTError>,
);

expect(result).toBe(Errors.RATE_LIMITED);
});

it('rate limited - secondary', async () => {
const mockError: Partial<AxiosError<GithubRESTError>> = {
const mockError: Partial<AxiosError<GitHubRESTError>> = {
code: AxiosError.ERR_BAD_REQUEST,
status: 403,
response: createMockResponse(
Expand All @@ -70,34 +70,34 @@ describe('utils/api/errors.ts', () => {
};

const result = determineFailureType(
mockError as AxiosError<GithubRESTError>,
mockError as AxiosError<GitHubRESTError>,
);

expect(result).toBe(Errors.RATE_LIMITED);
});

it('unhandled bad request error', async () => {
const mockError: Partial<AxiosError<GithubRESTError>> = {
const mockError: Partial<AxiosError<GitHubRESTError>> = {
code: AxiosError.ERR_BAD_REQUEST,
status: 400,
response: createMockResponse(403, 'Oops! Something went wrong.'),
};

const result = determineFailureType(
mockError as AxiosError<GithubRESTError>,
mockError as AxiosError<GitHubRESTError>,
);

expect(result).toBe(Errors.UNKNOWN);
});
});

it('unknown error', async () => {
const mockError: Partial<AxiosError<GithubRESTError>> = {
const mockError: Partial<AxiosError<GitHubRESTError>> = {
code: 'anything',
};

const result = determineFailureType(
mockError as AxiosError<GithubRESTError>,
mockError as AxiosError<GitHubRESTError>,
);

expect(result).toBe(Errors.UNKNOWN);
Expand All @@ -107,7 +107,7 @@ describe('utils/api/errors.ts', () => {
function createMockResponse(
status: number,
message: string,
): AxiosResponse<GithubRESTError> {
): AxiosResponse<GitHubRESTError> {
return {
data: {
message,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/api/errors.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AxiosError } from 'axios';
import type { GitifyError } from '../../types';
import type { GithubRESTError } from '../../typesGithub';
import type { GitHubRESTError } from '../../typesGitHub';
import { Errors } from '../constants';

export function determineFailureType(
err: AxiosError<GithubRESTError>,
err: AxiosError<GitHubRESTError>,
): GitifyError {
const code = err.code;

Expand Down
6 changes: 3 additions & 3 deletions src/utils/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('utils/auth.tsx', () => {
loadURLMock.mockReset();
});

it('should call authGithub - success', async () => {
it('should call authGitHub - success', async () => {
// Casting to jest.Mock avoids Typescript errors, where the spy is expected to match all the original
// function's typing. I might fix all that if the return type of this was actually used, or if I was
// writing this test for a new feature. Since I'm just upgrading Jest, jest.Mock is a nice escape hatch
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('utils/auth.tsx', () => {
expect(browserWindow.destroy).toHaveBeenCalledTimes(1);
});

it('should call authGithub - failure', async () => {
it('should call authGitHub - failure', async () => {
(
jest.spyOn(browserWindow.webContents, 'on') as jest.Mock
).mockImplementation((event, callback): void => {
Expand All @@ -55,7 +55,7 @@ describe('utils/auth.tsx', () => {
});

await expect(async () => await auth.authGitHub()).rejects.toEqual(
"Oops! Something went wrong and we couldn't log you in using Github. Please try again.",
"Oops! Something went wrong and we couldn't log you in using GitHub. Please try again.",
);
expect(loadURLMock).toHaveBeenCalledTimes(1);
});
Expand Down
4 changes: 2 additions & 2 deletions src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
AuthTokenResponse,
GitifyUser,
} from '../types';
import type { UserDetails } from '../typesGithub';
import type { UserDetails } from '../typesGitHub';
import { apiRequest, apiRequestAuth } from '../utils/api-requests';
import { Constants } from '../utils/constants';
import { generateGitHubAPIUrl, isEnterpriseHost } from './helpers';
Expand Down Expand Up @@ -44,7 +44,7 @@ export const authGitHub = (
} else if (error) {
reject(
"Oops! Something went wrong and we couldn't " +
'log you in using Github. Please try again.',
'log you in using GitHub. Please try again.',
);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/utils/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
mockedSingleNotification,
mockedUser,
} from '../__mocks__/mockedData';
import type { SubjectType } from '../typesGithub';
import type { SubjectType } from '../typesGitHub';
import * as apiRequests from './api-requests';
import {
addHours,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
IssueComments,
Notification,
PullRequest,
} from '../typesGithub';
} from '../typesGitHub';
import { apiRequestAuth } from '../utils/api-requests';
import { openExternalLink } from '../utils/comms';
import { Constants } from './constants';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/icons.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StateType, Subject, SubjectType } from '../typesGithub';
import type { StateType, Subject, SubjectType } from '../typesGitHub';
import { getNotificationTypeIcon, getNotificationTypeIconColor } from './icons';

describe('utils/icons.ts', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '@primer/octicons-react';
import type { FC } from 'react';
import { IconColor } from '../types';
import type { Subject } from '../typesGithub';
import type { Subject } from '../typesGitHub';

export function getNotificationTypeIcon(subject: Subject): FC<OcticonProps> {
switch (subject.type) {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/notifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ipcRenderer } from 'electron';
import { mockAccounts } from '../__mocks__/mock-state';
import {
mockedAccountNotifications,
mockedGithubNotifications,
mockedGitHubNotifications,
mockedSingleAccountNotifications,
} from '../__mocks__/mockedData';
import { defaultSettings } from '../context/App';
Expand Down Expand Up @@ -109,22 +109,22 @@ describe('utils/notifications.ts', () => {

const nativeNotification: Notification =
notificationsHelpers.raiseNativeNotification(
[mockedGithubNotifications[0]],
[mockedGitHubNotifications[0]],
mockAccounts,
);
nativeNotification.onclick(null);

expect(helpers.openInBrowser).toHaveBeenCalledTimes(1);
expect(helpers.openInBrowser).toHaveBeenLastCalledWith(
mockedGithubNotifications[0],
mockedGitHubNotifications[0],
mockAccounts,
);
expect(ipcRenderer.send).toHaveBeenCalledWith('hide-window');
});

it('should click on a native notification (with more than 1 notification)', () => {
const nativeNotification = notificationsHelpers.raiseNativeNotification(
mockedGithubNotifications,
mockedGitHubNotifications,
mockAccounts,
);
nativeNotification.onclick(null);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ipcRenderer } from 'electron';
import { Notification } from '../typesGithub';
import { Notification } from '../typesGitHub';
import { openInBrowser } from '../utils/helpers';
import { updateTrayIcon } from './comms';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/reason.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Reason } from '../typesGithub';
import type { Reason } from '../typesGitHub';
import { formatReason } from './reason';

describe('utils/reason.ts', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/reason.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FormattedReason } from '../types';
import type { Reason } from '../typesGithub';
import type { Reason } from '../typesGitHub';

const FORMATTED_REASONS: Record<Reason, FormattedReason> = {
approval_requested: {
Expand Down
Loading