From ae9f1724f992e715faa8c4dab949463732bcabbd Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sat, 25 May 2024 17:58:44 -0400 Subject: [PATCH 1/2] refactor(mocks): use consistent naming --- src/__mocks__/mock-state.ts | 22 --- src/__mocks__/notifications-mocks.ts | 24 +++ src/__mocks__/partial-mocks.ts | 12 +- src/__mocks__/state-mocks.ts | 40 +++++ src/components/AccountNotifications.test.tsx | 2 +- src/components/NotificationRow.test.tsx | 28 ++-- src/components/Repository.test.tsx | 2 +- src/components/Sidebar.test.tsx | 6 +- src/context/App.test.tsx | 14 +- src/hooks/useNotifications.test.ts | 100 +++++++------ src/routes/LoginWithOAuthApp.test.tsx | 2 +- src/routes/Notifications.test.tsx | 6 +- src/routes/Settings.test.tsx | 82 +++++------ .../api/__mocks__/response-mocks.ts} | 60 ++------ src/utils/helpers.test.ts | 55 ++++--- src/utils/notifications.test.ts | 37 ++--- src/utils/remove-notification.test.ts | 12 +- src/utils/remove-notifications.test.ts | 4 +- src/utils/storage.test.ts | 4 +- src/utils/subject.test.ts | 138 +++++++++--------- 20 files changed, 331 insertions(+), 319 deletions(-) delete mode 100644 src/__mocks__/mock-state.ts create mode 100644 src/__mocks__/notifications-mocks.ts create mode 100644 src/__mocks__/state-mocks.ts rename src/{__mocks__/mockedData.ts => utils/api/__mocks__/response-mocks.ts} (93%) diff --git a/src/__mocks__/mock-state.ts b/src/__mocks__/mock-state.ts deleted file mode 100644 index 4a930d0e7..000000000 --- a/src/__mocks__/mock-state.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { type AuthState, type SettingsState, Theme } from '../types'; -import { mockedEnterpriseAccounts, mockedUser } from './mockedData'; - -export const mockAccounts: AuthState = { - token: 'token-123-456', - enterpriseAccounts: mockedEnterpriseAccounts, - user: mockedUser, -}; - -export const mockSettings: SettingsState = { - participating: false, - playSound: true, - showNotifications: true, - showBots: true, - showNotificationsCountInTray: false, - openAtStartup: false, - theme: Theme.SYSTEM, - detailedNotifications: true, - markAsDoneOnOpen: false, - showAccountHostname: false, - delayNotificationState: false, -}; diff --git a/src/__mocks__/notifications-mocks.ts b/src/__mocks__/notifications-mocks.ts new file mode 100644 index 000000000..071099b76 --- /dev/null +++ b/src/__mocks__/notifications-mocks.ts @@ -0,0 +1,24 @@ +import type { AccountNotifications } from '../types'; +import { + mockedEnterpriseNotifications, + mockedGitHubNotifications, + mockedSingleNotification, +} from '../utils/api/__mocks__/response-mocks'; + +export const mockedAccountNotifications: AccountNotifications[] = [ + { + hostname: 'github.com', + notifications: mockedGitHubNotifications, + }, + { + hostname: 'github.gitify.io', + notifications: mockedEnterpriseNotifications, + }, +]; + +export const mockedSingleAccountNotifications: AccountNotifications[] = [ + { + hostname: 'github.com', + notifications: [mockedSingleNotification], + }, +]; diff --git a/src/__mocks__/partial-mocks.ts b/src/__mocks__/partial-mocks.ts index f0d2c0ef6..1166cc08b 100644 --- a/src/__mocks__/partial-mocks.ts +++ b/src/__mocks__/partial-mocks.ts @@ -1,24 +1,24 @@ import type { Notification, Subject, User } from '../typesGitHub'; import Constants from '../utils/constants'; -export function partialMockNotification( +export function partialMockedNotification( subject: Partial, ): Notification { - const mockNotification: Partial = { + const mockedNotification: Partial = { hostname: Constants.GITHUB_API_BASE_URL, subject: subject as Subject, }; - return mockNotification as Notification; + return mockedNotification as Notification; } -export function partialMockUser(login: string): User { - const mockUser: Partial = { +export function partialMockedUser(login: string): User { + const mockedUser: Partial = { login: login, html_url: `https://github.com/${login}`, avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4', type: 'User', }; - return mockUser as User; + return mockedUser as User; } diff --git a/src/__mocks__/state-mocks.ts b/src/__mocks__/state-mocks.ts new file mode 100644 index 000000000..e844a3940 --- /dev/null +++ b/src/__mocks__/state-mocks.ts @@ -0,0 +1,40 @@ +import { + type AuthState, + type EnterpriseAccount, + type GitifyUser, + type SettingsState, + Theme, +} from '../types'; + +export const mockedEnterpriseAccounts: EnterpriseAccount[] = [ + { + hostname: 'github.gitify.io', + token: '1234568790', + }, +]; + +export const mockedUser: GitifyUser = { + login: 'octocat', + name: 'Mona Lisa Octocat', + id: 123456789, +}; + +export const mockedAccounts: AuthState = { + token: 'token-123-456', + enterpriseAccounts: mockedEnterpriseAccounts, + user: mockedUser, +}; + +export const mockedSettings: SettingsState = { + participating: false, + playSound: true, + showNotifications: true, + showBots: true, + showNotificationsCountInTray: false, + openAtStartup: false, + theme: Theme.SYSTEM, + detailedNotifications: true, + markAsDoneOnOpen: false, + showAccountHostname: false, + delayNotificationState: false, +}; diff --git a/src/components/AccountNotifications.test.tsx b/src/components/AccountNotifications.test.tsx index b18ffa47c..d07408f0f 100644 --- a/src/components/AccountNotifications.test.tsx +++ b/src/components/AccountNotifications.test.tsx @@ -1,6 +1,6 @@ import TestRenderer from 'react-test-renderer'; -import { mockedGitHubNotifications } from '../__mocks__/mockedData'; +import { mockedGitHubNotifications } from '../utils/api/__mocks__/response-mocks'; import { AccountNotifications } from './AccountNotifications'; jest.mock('./Repository', () => ({ diff --git a/src/components/NotificationRow.test.tsx b/src/components/NotificationRow.test.tsx index 4677f92d5..3aa37bf48 100644 --- a/src/components/NotificationRow.test.tsx +++ b/src/components/NotificationRow.test.tsx @@ -5,10 +5,10 @@ import * as TestRenderer from 'react-test-renderer'; import * as helpers from '../utils/helpers'; import { shell } from 'electron'; -import { mockAccounts, mockSettings } from '../__mocks__/mock-state'; -import { mockedSingleNotification } from '../__mocks__/mockedData'; +import { mockedAccounts, mockedSettings } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import type { UserType } from '../typesGitHub'; +import { mockedSingleNotification } from '../utils/api/__mocks__/response-mocks'; import { NotificationRow } from './NotificationRow'; describe('components/NotificationRow.tsx', () => { @@ -133,9 +133,9 @@ describe('components/NotificationRow.tsx', () => { render( @@ -158,9 +158,9 @@ describe('components/NotificationRow.tsx', () => { render( @@ -183,9 +183,9 @@ describe('components/NotificationRow.tsx', () => { render( @@ -208,8 +208,8 @@ describe('components/NotificationRow.tsx', () => { render( @@ -233,8 +233,8 @@ describe('components/NotificationRow.tsx', () => { render( @@ -288,8 +288,8 @@ describe('components/NotificationRow.tsx', () => { render( diff --git a/src/components/Repository.test.tsx b/src/components/Repository.test.tsx index 03bac4f6a..cf18aaf4c 100644 --- a/src/components/Repository.test.tsx +++ b/src/components/Repository.test.tsx @@ -1,7 +1,7 @@ import { fireEvent, render, screen } from '@testing-library/react'; import TestRenderer from 'react-test-renderer'; -import { mockedGitHubNotifications } from '../__mocks__/mockedData'; import { AppContext } from '../context/App'; +import { mockedGitHubNotifications } from '../utils/api/__mocks__/response-mocks'; import { RepositoryNotifications } from './Repository'; const { shell } = require('electron'); diff --git a/src/components/Sidebar.test.tsx b/src/components/Sidebar.test.tsx index 0dad3f782..4c82cf634 100644 --- a/src/components/Sidebar.test.tsx +++ b/src/components/Sidebar.test.tsx @@ -2,8 +2,8 @@ import { fireEvent, render, screen } from '@testing-library/react'; import { MemoryRouter } from 'react-router-dom'; import * as TestRenderer from 'react-test-renderer'; const { shell, ipcRenderer } = require('electron'); -import { mockSettings } from '../__mocks__/mock-state'; -import { mockedAccountNotifications } from '../__mocks__/mockedData'; +import { mockedAccountNotifications } from '../__mocks__/notifications-mocks'; +import { mockedSettings } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import { Sidebar } from './Sidebar'; @@ -32,7 +32,7 @@ describe('components/Sidebar.tsx', () => { const tree = TestRenderer.create( diff --git a/src/context/App.test.tsx b/src/context/App.test.tsx index bf8c297f7..e6dd964c9 100644 --- a/src/context/App.test.tsx +++ b/src/context/App.test.tsx @@ -1,7 +1,7 @@ import { act, fireEvent, render, waitFor } from '@testing-library/react'; import { useContext } from 'react'; -import { mockAccounts, mockSettings } from '../__mocks__/mock-state'; +import { mockedAccounts, mockedSettings } from '../__mocks__/state-mocks'; import { useNotifications } from '../hooks/useNotifications'; import type { AuthState, SettingsState } from '../types'; import * as apiRequests from '../utils/api/request'; @@ -15,8 +15,8 @@ jest.mock('../hooks/useNotifications'); const customRender = ( ui, - accounts: AuthState = mockAccounts, - settings: SettingsState = mockSettings, + accounts: AuthState = mockedAccounts, + settings: SettingsState = mockedSettings, ) => { return render( @@ -136,7 +136,7 @@ describe('context/App.tsx', () => { token: null, user: null, }, - mockSettings, + mockedSettings, '123-456', 'github.com', ); @@ -165,7 +165,7 @@ describe('context/App.tsx', () => { expect(markNotificationDoneMock).toHaveBeenCalledTimes(1); expect(markNotificationDoneMock).toHaveBeenCalledWith( { enterpriseAccounts: [], token: null, user: null }, - mockSettings, + mockedSettings, '123-456', 'github.com', ); @@ -194,7 +194,7 @@ describe('context/App.tsx', () => { expect(unsubscribeNotificationMock).toHaveBeenCalledTimes(1); expect(unsubscribeNotificationMock).toHaveBeenCalledWith( { enterpriseAccounts: [], token: null, user: null }, - mockSettings, + mockedSettings, '123-456', 'github.com', ); @@ -228,7 +228,7 @@ describe('context/App.tsx', () => { expect(markRepoNotificationsMock).toHaveBeenCalledTimes(1); expect(markRepoNotificationsMock).toHaveBeenCalledWith( { enterpriseAccounts: [], token: null, user: null }, - mockSettings, + mockedSettings, 'gitify-app/notifications-test', 'github.com', ); diff --git a/src/hooks/useNotifications.test.ts b/src/hooks/useNotifications.test.ts index 29e4be3bd..bc7c09acb 100644 --- a/src/hooks/useNotifications.test.ts +++ b/src/hooks/useNotifications.test.ts @@ -2,9 +2,13 @@ import { act, renderHook, waitFor } from '@testing-library/react'; import axios, { AxiosError } from 'axios'; import nock from 'nock'; -import { mockAccounts, mockSettings } from '../__mocks__/mock-state'; -import { mockedNotificationUser, mockedUser } from '../__mocks__/mockedData'; +import { + mockedAccounts, + mockedSettings, + mockedUser, +} from '../__mocks__/state-mocks'; import type { AuthState } from '../types'; +import { mockedNotificationUser } from '../utils/api/__mocks__/response-mocks'; import { Errors } from '../utils/constants'; import { useNotifications } from './useNotifications'; @@ -34,8 +38,8 @@ describe('hooks/useNotifications.ts', () => { const { result } = renderHook(() => useNotifications()); act(() => { - result.current.fetchNotifications(mockAccounts, { - ...mockSettings, + result.current.fetchNotifications(mockedAccounts, { + ...mockedSettings, detailedNotifications: false, }); }); @@ -87,7 +91,7 @@ describe('hooks/useNotifications.ts', () => { const { result } = renderHook(() => useNotifications()); act(() => { - result.current.fetchNotifications(mockAccounts, mockSettings); + result.current.fetchNotifications(mockedAccounts, mockedSettings); }); expect(result.current.status).toBe('loading'); @@ -103,7 +107,7 @@ describe('hooks/useNotifications.ts', () => { describe('enterprise', () => { it('should fetch notifications with success - enterprise only', async () => { const accounts: AuthState = { - ...mockAccounts, + ...mockedAccounts, token: null, }; @@ -120,7 +124,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.fetchNotifications(accounts, { - ...mockSettings, + ...mockedSettings, detailedNotifications: false, }); }); @@ -137,7 +141,7 @@ describe('hooks/useNotifications.ts', () => { it('should fetch notifications with failure - enterprise only', async () => { const accounts: AuthState = { - ...mockAccounts, + ...mockedAccounts, token: null, }; @@ -156,7 +160,7 @@ describe('hooks/useNotifications.ts', () => { const { result } = renderHook(() => useNotifications()); act(() => { - result.current.fetchNotifications(accounts, mockSettings); + result.current.fetchNotifications(accounts, mockedSettings); }); await waitFor(() => { @@ -168,7 +172,7 @@ describe('hooks/useNotifications.ts', () => { describe('github.com', () => { it('should fetch notifications with success - github.com only', async () => { const accounts: AuthState = { - ...mockAccounts, + ...mockedAccounts, enterpriseAccounts: [], user: mockedUser, }; @@ -186,7 +190,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.fetchNotifications(accounts, { - ...mockSettings, + ...mockedSettings, detailedNotifications: false, }); }); @@ -201,7 +205,7 @@ describe('hooks/useNotifications.ts', () => { it('should fetch notifications with failures - github.com only', async () => { const accounts: AuthState = { - ...mockAccounts, + ...mockedAccounts, enterpriseAccounts: [], }; @@ -220,7 +224,7 @@ describe('hooks/useNotifications.ts', () => { const { result } = renderHook(() => useNotifications()); act(() => { - result.current.fetchNotifications(accounts, mockSettings); + result.current.fetchNotifications(accounts, mockedSettings); }); await waitFor(() => { @@ -233,7 +237,7 @@ describe('hooks/useNotifications.ts', () => { describe('with detailed notifications', () => { it('should fetch notifications with success', async () => { const accounts: AuthState = { - ...mockAccounts, + ...mockedAccounts, enterpriseAccounts: [], user: mockedUser, }; @@ -391,7 +395,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.fetchNotifications(accounts, { - ...mockSettings, + ...mockedSettings, detailedNotifications: true, }); }); @@ -426,8 +430,8 @@ describe('hooks/useNotifications.ts', () => { const { result } = renderHook(() => useNotifications()); act(() => { - result.current.fetchNotifications(mockAccounts, { - ...mockSettings, + result.current.fetchNotifications(mockedAccounts, { + ...mockedSettings, detailedNotifications: false, }); }); @@ -438,7 +442,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.removeNotificationFromState( - mockSettings, + mockedSettings, result.current.notifications[0].notifications[0].id, result.current.notifications[0].hostname, ); @@ -452,7 +456,7 @@ describe('hooks/useNotifications.ts', () => { const id = 'notification-123'; describe('github.com', () => { - const accounts = { ...mockAccounts, enterpriseAccounts: [] }; + const accounts = { ...mockedAccounts, enterpriseAccounts: [] }; const hostname = 'github.com'; it('should mark a notification as read with success - github.com', async () => { @@ -465,7 +469,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationRead( accounts, - mockSettings, + mockedSettings, id, hostname, ); @@ -488,7 +492,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationRead( accounts, - mockSettings, + mockedSettings, id, hostname, ); @@ -503,7 +507,7 @@ describe('hooks/useNotifications.ts', () => { }); describe('enterprise', () => { - const accounts = { ...mockAccounts, token: null }; + const accounts = { ...mockedAccounts, token: null }; const hostname = 'github.gitify.io'; it('should mark a notification as read with success - enterprise', async () => { @@ -516,7 +520,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationRead( accounts, - mockSettings, + mockedSettings, id, hostname, ); @@ -539,7 +543,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationRead( accounts, - mockSettings, + mockedSettings, id, hostname, ); @@ -558,7 +562,7 @@ describe('hooks/useNotifications.ts', () => { const id = 'notification-123'; describe('github.com', () => { - const accounts = { ...mockAccounts, enterpriseAccounts: [] }; + const accounts = { ...mockedAccounts, enterpriseAccounts: [] }; const hostname = 'github.com'; it('should mark a notification as done with success - github.com', async () => { @@ -571,7 +575,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationDone( accounts, - mockSettings, + mockedSettings, id, hostname, ); @@ -594,7 +598,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationDone( accounts, - mockSettings, + mockedSettings, id, hostname, ); @@ -609,7 +613,7 @@ describe('hooks/useNotifications.ts', () => { }); describe('enterprise', () => { - const accounts = { ...mockAccounts, token: null }; + const accounts = { ...mockedAccounts, token: null }; const hostname = 'github.gitify.io'; it('should mark a notification as done with success - enterprise', async () => { @@ -622,7 +626,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationDone( accounts, - mockSettings, + mockedSettings, id, hostname, ); @@ -645,7 +649,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationDone( accounts, - mockSettings, + mockedSettings, id, hostname, ); @@ -664,7 +668,7 @@ describe('hooks/useNotifications.ts', () => { const id = 'notification-123'; describe('github.com', () => { - const accounts = { ...mockAccounts, enterpriseAccounts: [] }; + const accounts = { ...mockedAccounts, enterpriseAccounts: [] }; const hostname = 'github.com'; it('should unsubscribe from a notification with success - github.com', async () => { @@ -683,7 +687,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.unsubscribeNotification( accounts, - mockSettings, + mockedSettings, id, hostname, ); @@ -712,7 +716,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.unsubscribeNotification( accounts, - mockSettings, + mockedSettings, id, hostname, ); @@ -727,7 +731,7 @@ describe('hooks/useNotifications.ts', () => { }); describe('enterprise', () => { - const accounts = { ...mockAccounts, token: null }; + const accounts = { ...mockedAccounts, token: null }; const hostname = 'github.gitify.io'; it('should unsubscribe from a notification with success - enterprise', async () => { @@ -746,7 +750,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.unsubscribeNotification( accounts, - mockSettings, + mockedSettings, id, hostname, ); @@ -775,7 +779,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.unsubscribeNotification( accounts, - mockSettings, + mockedSettings, id, hostname, ); @@ -794,7 +798,7 @@ describe('hooks/useNotifications.ts', () => { const repoSlug = 'gitify-app/notifications-test'; describe('github.com', () => { - const accounts = { ...mockAccounts, enterpriseAccounts: [] }; + const accounts = { ...mockedAccounts, enterpriseAccounts: [] }; const hostname = 'github.com'; it("should mark a repository's notifications as read with success - github.com", async () => { @@ -807,7 +811,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotifications( accounts, - mockSettings, + mockedSettings, repoSlug, hostname, ); @@ -830,7 +834,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotifications( accounts, - mockSettings, + mockedSettings, repoSlug, hostname, ); @@ -845,7 +849,7 @@ describe('hooks/useNotifications.ts', () => { }); describe('enterprise', () => { - const accounts = { ...mockAccounts, token: null }; + const accounts = { ...mockedAccounts, token: null }; const hostname = 'github.gitify.io'; it("should mark a repository's notifications as read with success - enterprise", async () => { @@ -858,7 +862,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotifications( accounts, - mockSettings, + mockedSettings, repoSlug, hostname, ); @@ -881,7 +885,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotifications( accounts, - mockSettings, + mockedSettings, repoSlug, hostname, ); @@ -901,7 +905,7 @@ describe('hooks/useNotifications.ts', () => { const id = 'notification-123'; describe('github.com', () => { - const accounts = { ...mockAccounts, enterpriseAccounts: [] }; + const accounts = { ...mockedAccounts, enterpriseAccounts: [] }; const hostname = 'github.com'; it("should mark a repository's notifications as done with success - github.com", async () => { @@ -914,7 +918,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotificationsDone( accounts, - mockSettings, + mockedSettings, repoSlug, hostname, ); @@ -937,7 +941,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotificationsDone( accounts, - mockSettings, + mockedSettings, repoSlug, hostname, ); @@ -952,7 +956,7 @@ describe('hooks/useNotifications.ts', () => { }); describe('enterprise', () => { - const accounts = { ...mockAccounts, token: null }; + const accounts = { ...mockedAccounts, token: null }; const hostname = 'github.gitify.io'; it("should mark a repository's notifications as done with success - enterprise", async () => { @@ -965,7 +969,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotificationsDone( accounts, - mockSettings, + mockedSettings, repoSlug, hostname, ); @@ -988,7 +992,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotificationsDone( accounts, - mockSettings, + mockedSettings, repoSlug, hostname, ); diff --git a/src/routes/LoginWithOAuthApp.test.tsx b/src/routes/LoginWithOAuthApp.test.tsx index 63f7a256a..06ec1ea49 100644 --- a/src/routes/LoginWithOAuthApp.test.tsx +++ b/src/routes/LoginWithOAuthApp.test.tsx @@ -3,7 +3,7 @@ import { MemoryRouter } from 'react-router-dom'; import * as TestRenderer from 'react-test-renderer'; const { ipcRenderer } = require('electron'); import { shell } from 'electron'; -import { mockedEnterpriseAccounts } from '../__mocks__/mockedData'; +import { mockedEnterpriseAccounts } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import type { AuthState } from '../types'; import { LoginWithOAuthApp, validate } from './LoginWithOAuthApp'; diff --git a/src/routes/Notifications.test.tsx b/src/routes/Notifications.test.tsx index 155a274be..57d743eef 100644 --- a/src/routes/Notifications.test.tsx +++ b/src/routes/Notifications.test.tsx @@ -1,7 +1,7 @@ import TestRenderer from 'react-test-renderer'; -import { mockSettings } from '../__mocks__/mock-state'; -import { mockedAccountNotifications } from '../__mocks__/mockedData'; +import { mockedAccountNotifications } from '../__mocks__/notifications-mocks'; +import { mockedSettings } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import { Errors } from '../utils/constants'; import { NotificationsRoute } from './Notifications'; @@ -45,7 +45,7 @@ describe('routes/Notifications.tsx', () => { diff --git a/src/routes/Settings.test.tsx b/src/routes/Settings.test.tsx index b670f4297..ccdd699b3 100644 --- a/src/routes/Settings.test.tsx +++ b/src/routes/Settings.test.tsx @@ -5,7 +5,7 @@ import { MemoryRouter } from 'react-router-dom'; const { ipcRenderer } = require('electron'); import { shell } from 'electron'; -import { mockAccounts, mockSettings } from '../__mocks__/mock-state'; +import { mockedAccounts, mockedSettings } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import { SettingsRoute } from './Settings'; @@ -27,7 +27,7 @@ describe('routes/Settings.tsx', () => { await act(async () => { render( @@ -44,8 +44,8 @@ describe('routes/Settings.tsx', () => { render( @@ -65,8 +65,8 @@ describe('routes/Settings.tsx', () => { render( @@ -88,8 +88,8 @@ describe('routes/Settings.tsx', () => { render( @@ -118,8 +118,8 @@ describe('routes/Settings.tsx', () => { render( @@ -143,8 +143,8 @@ describe('routes/Settings.tsx', () => { render( @@ -179,11 +179,11 @@ describe('routes/Settings.tsx', () => { @@ -220,11 +220,11 @@ describe('routes/Settings.tsx', () => { @@ -260,8 +260,8 @@ describe('routes/Settings.tsx', () => { render( @@ -285,8 +285,8 @@ describe('routes/Settings.tsx', () => { render( @@ -315,8 +315,8 @@ describe('routes/Settings.tsx', () => { render( @@ -346,8 +346,8 @@ describe('routes/Settings.tsx', () => { render( @@ -371,8 +371,8 @@ describe('routes/Settings.tsx', () => { render( @@ -396,8 +396,8 @@ describe('routes/Settings.tsx', () => { render( @@ -423,8 +423,8 @@ describe('routes/Settings.tsx', () => { render( @@ -448,8 +448,8 @@ describe('routes/Settings.tsx', () => { render( @@ -478,8 +478,8 @@ describe('routes/Settings.tsx', () => { render( @@ -501,9 +501,9 @@ describe('routes/Settings.tsx', () => { render( { render( @@ -549,8 +549,8 @@ describe('routes/Settings.tsx', () => { render( @@ -575,7 +575,7 @@ describe('routes/Settings.tsx', () => { await act(async () => { render( diff --git a/src/__mocks__/mockedData.ts b/src/utils/api/__mocks__/response-mocks.ts similarity index 93% rename from src/__mocks__/mockedData.ts rename to src/utils/api/__mocks__/response-mocks.ts index 085fa8e1a..7ecfd48d7 100644 --- a/src/__mocks__/mockedData.ts +++ b/src/utils/api/__mocks__/response-mocks.ts @@ -1,8 +1,3 @@ -import type { - AccountNotifications, - EnterpriseAccount, - GitifyUser, -} from '../types'; import type { Discussion, DiscussionAuthor, @@ -11,21 +6,8 @@ import type { Notification, Repository, User, -} from '../typesGitHub'; -import Constants from '../utils/constants'; - -export const mockedEnterpriseAccounts: EnterpriseAccount[] = [ - { - hostname: 'github.gitify.io', - token: '1234568790', - }, -]; - -export const mockedUser: GitifyUser = { - login: 'octocat', - name: 'Mona Lisa Octocat', - id: 123456789, -}; +} from '../../../typesGitHub'; +import Constants from '../../constants'; export const mockedNotificationUser: User = { login: 'octocat', @@ -49,6 +31,7 @@ export const mockedNotificationUser: User = { }; // 2 Notifications +// Hostname : 'github.com' // Repository : 'gitify-app/notifications-test' export const mockedGitHubNotifications: Notification[] = [ { @@ -255,6 +238,7 @@ export const mockedGitHubNotifications: Notification[] = [ ]; // 2 Notifications +// Hostname : 'github.gitify.io' // Repository : 'myorg/notifications-test' export const mockedEnterpriseNotifications: Notification[] = [ { @@ -367,53 +351,32 @@ export const mockedEnterpriseNotifications: Notification[] = [ }, ]; -export const mockedSingleNotification: Notification = - mockedGitHubNotifications[0]; - -export const mockedAccountNotifications: AccountNotifications[] = [ - { - hostname: 'github.com', - notifications: mockedGitHubNotifications, - }, - { - hostname: 'github.gitify.io', - notifications: mockedEnterpriseNotifications, - }, -]; - -export const mockedSingleAccountNotifications: AccountNotifications[] = [ - { - hostname: 'github.com', - notifications: [mockedSingleNotification], - }, -]; - -const mockDiscussionAuthor: DiscussionAuthor = { +const mockedDiscussionAuthor: DiscussionAuthor = { login: 'comment-user', url: 'https://github.com/comment-user', avatar_url: 'https://avatars.githubusercontent.com/u/123456789?v=4', type: 'User', }; -const mockDiscussionReplier: DiscussionAuthor = { +const mockedDiscussionReplier: DiscussionAuthor = { login: 'reply-user', url: 'https://github.com/reply-user', avatar_url: 'https://avatars.githubusercontent.com/u/123456789?v=4', type: 'User', }; -export const mockDiscussionComments: DiscussionComments = { +export const mockedDiscussionComments: DiscussionComments = { nodes: [ { databaseId: 2258799, createdAt: '2022-02-27T01:22:20Z', - author: mockDiscussionAuthor, + author: mockedDiscussionAuthor, replies: { nodes: [ { databaseId: 2300902, createdAt: '2022-03-05T17:43:52Z', - author: mockDiscussionReplier, + author: mockedDiscussionReplier, }, ], }, @@ -437,9 +400,12 @@ export const mockedGraphQLResponse: GraphQLSearch = { avatar_url: 'https://avatars.githubusercontent.com/u/123456789?v=4', type: 'User', }, - comments: mockDiscussionComments, + comments: mockedDiscussionComments, }, ], }, }, }; + +export const mockedSingleNotification: Notification = + mockedGitHubNotifications[0]; diff --git a/src/utils/helpers.test.ts b/src/utils/helpers.test.ts index d22a64113..b587e6006 100644 --- a/src/utils/helpers.test.ts +++ b/src/utils/helpers.test.ts @@ -1,11 +1,10 @@ import type { AxiosPromise, AxiosResponse } from 'axios'; -import { mockAccounts } from '../__mocks__/mock-state'; +import { mockedAccounts, mockedUser } from '../__mocks__/state-mocks'; +import type { SubjectType } from '../typesGitHub'; import { mockedGraphQLResponse, mockedSingleNotification, - mockedUser, -} from '../__mocks__/mockedData'; -import type { SubjectType } from '../typesGitHub'; +} from './api/__mocks__/response-mocks'; import * as apiRequests from './api/request'; import { formatForDisplay, @@ -20,13 +19,13 @@ describe('utils/helpers.ts', () => { describe('isPersonalAccessTokenLoggedIn', () => { it('logged in', () => { expect( - isPersonalAccessTokenLoggedIn({ ...mockAccounts, token: '1234' }), + isPersonalAccessTokenLoggedIn({ ...mockedAccounts, token: '1234' }), ).toBe(true); }); it('logged out', () => { expect( - isPersonalAccessTokenLoggedIn({ ...mockAccounts, token: null }), + isPersonalAccessTokenLoggedIn({ ...mockedAccounts, token: null }), ).toBe(false); }); }); @@ -35,7 +34,7 @@ describe('utils/helpers.ts', () => { it('logged in', () => { expect( isOAuthAppLoggedIn({ - ...mockAccounts, + ...mockedAccounts, enterpriseAccounts: [{ hostname: 'github.gitify.io', token: '1234' }], }), ).toBe(true); @@ -43,11 +42,11 @@ describe('utils/helpers.ts', () => { it('logged out', () => { expect( - isOAuthAppLoggedIn({ ...mockAccounts, enterpriseAccounts: null }), + isOAuthAppLoggedIn({ ...mockedAccounts, enterpriseAccounts: null }), ).toBe(false); expect( - isOAuthAppLoggedIn({ ...mockAccounts, enterpriseAccounts: [] }), + isOAuthAppLoggedIn({ ...mockedAccounts, enterpriseAccounts: [] }), ).toBe(false); }); }); @@ -111,14 +110,14 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); expect(apiRequestAuthMock).toHaveBeenCalledWith( subject.latest_comment_url, 'GET', - mockAccounts.token, + mockedAccounts.token, ); expect(result).toBe(`${mockedHtmlUrl}?${mockedNotificationReferrer}`); }); @@ -146,14 +145,14 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); expect(apiRequestAuthMock).toHaveBeenCalledWith( subject.url, 'GET', - mockAccounts.token, + mockedAccounts.token, ); expect(result).toBe(`${mockedHtmlUrl}?${mockedNotificationReferrer}`); }); @@ -172,7 +171,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); @@ -194,7 +193,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); @@ -216,7 +215,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); @@ -238,7 +237,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); @@ -260,7 +259,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); @@ -282,7 +281,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); @@ -304,7 +303,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); @@ -336,7 +335,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); @@ -368,7 +367,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); @@ -396,7 +395,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); @@ -420,7 +419,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); @@ -443,7 +442,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); @@ -466,7 +465,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); @@ -488,7 +487,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); @@ -511,7 +510,7 @@ describe('utils/helpers.ts', () => { ...mockedSingleNotification, subject: subject, }, - mockAccounts, + mockedAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); diff --git a/src/utils/notifications.test.ts b/src/utils/notifications.test.ts index b679131ba..57596ec16 100644 --- a/src/utils/notifications.test.ts +++ b/src/utils/notifications.test.ts @@ -1,14 +1,17 @@ import { ipcRenderer } from 'electron'; -import { mockAccounts, mockSettings } from '../__mocks__/mock-state'; import { mockedAccountNotifications, - mockedGitHubNotifications, mockedSingleAccountNotifications, -} from '../__mocks__/mockedData'; -import { partialMockNotification } from '../__mocks__/partial-mocks'; +} from '../__mocks__/notifications-mocks'; +import { partialMockedNotification } from '../__mocks__/partial-mocks'; +import { mockedAccounts, mockedSettings } from '../__mocks__/state-mocks'; import { defaultSettings } from '../context/App'; import type { SettingsState } from '../types'; +import { + mockedGitHubNotifications, + mockedSingleNotification, +} from './api/__mocks__/response-mocks'; import * as helpers from './helpers'; import * as notificationsHelpers from './notifications'; import { filterNotifications } from './notifications'; @@ -32,7 +35,7 @@ describe('utils/notifications.ts', () => { [], mockedAccountNotifications, settings, - mockAccounts, + mockedAccounts, ); expect(notificationsHelpers.raiseNativeNotification).toHaveBeenCalledTimes( @@ -57,7 +60,7 @@ describe('utils/notifications.ts', () => { [], mockedAccountNotifications, settings, - mockAccounts, + mockedAccounts, ); expect(notificationsHelpers.raiseNativeNotification).not.toHaveBeenCalled(); @@ -78,7 +81,7 @@ describe('utils/notifications.ts', () => { mockedSingleAccountNotifications, mockedSingleAccountNotifications, settings, - mockAccounts, + mockedAccounts, ); expect(notificationsHelpers.raiseNativeNotification).not.toHaveBeenCalled(); @@ -99,7 +102,7 @@ describe('utils/notifications.ts', () => { [], [], settings, - mockAccounts, + mockedAccounts, ); expect(notificationsHelpers.raiseNativeNotification).not.toHaveBeenCalled(); @@ -111,15 +114,15 @@ describe('utils/notifications.ts', () => { const nativeNotification: Notification = notificationsHelpers.raiseNativeNotification( - [mockedGitHubNotifications[0]], - mockAccounts, + [mockedSingleNotification], + mockedAccounts, ); nativeNotification.onclick(null); expect(helpers.openInBrowser).toHaveBeenCalledTimes(1); expect(helpers.openInBrowser).toHaveBeenLastCalledWith( - mockedGitHubNotifications[0], - mockAccounts, + mockedSingleNotification, + mockedAccounts, ); expect(ipcRenderer.send).toHaveBeenCalledWith('hide-window'); }); @@ -127,7 +130,7 @@ describe('utils/notifications.ts', () => { it('should click on a native notification (with more than 1 notification)', () => { const nativeNotification = notificationsHelpers.raiseNativeNotification( mockedGitHubNotifications, - mockAccounts, + mockedAccounts, ); nativeNotification.onclick(null); @@ -142,7 +145,7 @@ describe('utils/notifications.ts', () => { describe('filterNotifications', () => { const mockNotifications = [ - partialMockNotification({ + partialMockedNotification({ title: 'User authored notification', user: { login: 'user', @@ -152,7 +155,7 @@ describe('utils/notifications.ts', () => { type: 'User', }, }), - partialMockNotification({ + partialMockedNotification({ title: 'Bot authored notification', user: { login: 'bot', @@ -166,7 +169,7 @@ describe('utils/notifications.ts', () => { it('should hide bot notifications when set to false', async () => { const result = filterNotifications(mockNotifications, { - ...mockSettings, + ...mockedSettings, showBots: false, }); @@ -176,7 +179,7 @@ describe('utils/notifications.ts', () => { it('should show bot notifications when set to true', async () => { const result = filterNotifications(mockNotifications, { - ...mockSettings, + ...mockedSettings, showBots: true, }); diff --git a/src/utils/remove-notification.test.ts b/src/utils/remove-notification.test.ts index 625d00d4f..85b51b5ad 100644 --- a/src/utils/remove-notification.test.ts +++ b/src/utils/remove-notification.test.ts @@ -1,8 +1,6 @@ -import { mockSettings } from '../__mocks__/mock-state'; -import { - mockedSingleAccountNotifications, - mockedSingleNotification, -} from '../__mocks__/mockedData'; +import { mockedSingleAccountNotifications } from '../__mocks__/notifications-mocks'; +import { mockedSettings } from '../__mocks__/state-mocks'; +import { mockedSingleNotification } from './api/__mocks__/response-mocks'; import Constants from './constants'; import { removeNotification } from './remove-notification'; @@ -14,7 +12,7 @@ describe('utils/remove-notification.ts', () => { expect(mockedSingleAccountNotifications[0].notifications.length).toBe(1); const result = removeNotification( - { ...mockSettings, delayNotificationState: false }, + { ...mockedSettings, delayNotificationState: false }, notificationId, mockedSingleAccountNotifications, hostname, @@ -31,7 +29,7 @@ describe('utils/remove-notification.ts', () => { expect(mockedSingleAccountNotifications[0].notifications.length).toBe(1); const result = removeNotification( - { ...mockSettings, delayNotificationState: true }, + { ...mockedSettings, delayNotificationState: true }, notificationId, mockedSingleAccountNotifications, hostname, diff --git a/src/utils/remove-notifications.test.ts b/src/utils/remove-notifications.test.ts index 0ec62a900..70a6ec469 100644 --- a/src/utils/remove-notifications.test.ts +++ b/src/utils/remove-notifications.test.ts @@ -1,8 +1,8 @@ import { mockedAccountNotifications, mockedSingleAccountNotifications, - mockedSingleNotification, -} from '../__mocks__/mockedData'; +} from '../__mocks__/notifications-mocks'; +import { mockedSingleNotification } from './api/__mocks__/response-mocks'; import { removeNotifications } from './remove-notifications'; describe('utils/remove-notifications.ts', () => { diff --git a/src/utils/storage.test.ts b/src/utils/storage.test.ts index 34e298a24..0670a0f30 100644 --- a/src/utils/storage.test.ts +++ b/src/utils/storage.test.ts @@ -1,4 +1,4 @@ -import { mockSettings } from '../__mocks__/mock-state'; +import { mockedSettings } from '../__mocks__/state-mocks'; import { clearState, loadState, saveState } from './storage'; describe('utils/storage.ts', () => { @@ -31,7 +31,7 @@ describe('utils/storage.ts', () => { enterpriseAccounts: [], user: null, }, - mockSettings, + mockedSettings, ); expect(localStorage.setItem).toHaveBeenCalledTimes(1); }); diff --git a/src/utils/subject.test.ts b/src/utils/subject.test.ts index 758f13919..eb3733995 100644 --- a/src/utils/subject.test.ts +++ b/src/utils/subject.test.ts @@ -1,11 +1,11 @@ import axios from 'axios'; import nock from 'nock'; -import { mockAccounts } from '../__mocks__/mock-state'; import { - partialMockNotification, - partialMockUser, + partialMockedNotification, + partialMockedUser, } from '../__mocks__/partial-mocks'; +import { mockedAccounts } from '../__mocks__/state-mocks'; import type { Discussion, DiscussionAuthor, @@ -20,8 +20,8 @@ import { getWorkflowRunAttributes, } from './subject'; -const mockAuthor = partialMockUser('some-author'); -const mockCommenter = partialMockUser('some-commenter'); +const mockAuthor = partialMockedUser('some-author'); +const mockCommenter = partialMockedUser('some-commenter'); const mockDiscussionAuthor: DiscussionAuthor = { login: 'discussion-author', url: 'https://github.com/discussion-author', @@ -39,14 +39,14 @@ describe('utils/subject.ts', () => { describe('getGitifySubjectDetails', () => { describe('CheckSuites - GitHub Actions', () => { it('cancelled check suite state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'Demo workflow run cancelled for main branch', type: 'CheckSuite', }); const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -56,14 +56,14 @@ describe('utils/subject.ts', () => { }); it('failed check suite state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'Demo workflow run failed for main branch', type: 'CheckSuite', }); const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -73,14 +73,14 @@ describe('utils/subject.ts', () => { }); it('multiple attempts failed check suite state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'Demo workflow run, Attempt #3 failed for main branch', type: 'CheckSuite', }); const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -90,14 +90,14 @@ describe('utils/subject.ts', () => { }); it('skipped check suite state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'Demo workflow run skipped for main branch', type: 'CheckSuite', }); const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -107,14 +107,14 @@ describe('utils/subject.ts', () => { }); it('successful check suite state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'Demo workflow run succeeded for main branch', type: 'CheckSuite', }); const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -124,28 +124,28 @@ describe('utils/subject.ts', () => { }); it('unknown check suite state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'Demo workflow run unknown-status for main branch', type: 'CheckSuite', }); const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toBeNull(); }); it('unhandled check suite title', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'A title that is not in the structure we expect', type: 'CheckSuite', }); const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toBeNull(); @@ -153,7 +153,7 @@ describe('utils/subject.ts', () => { }); describe('Commits', () => { it('get commit commenter', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'This is a commit with comments', type: 'Commit', url: 'https://api.github.com/repos/gitify-app/notifications-test/commits/d2a86d80e3d24ea9510d5de6c147e53c30f313a8', @@ -173,7 +173,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -188,7 +188,7 @@ describe('utils/subject.ts', () => { }); it('get commit without commenter', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'This is a commit with comments', type: 'Commit', url: 'https://api.github.com/repos/gitify-app/notifications-test/commits/d2a86d80e3d24ea9510d5de6c147e53c30f313a8', @@ -203,7 +203,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -223,7 +223,7 @@ describe('utils/subject.ts', () => { full_name: 'gitify-app/notifications-test', }; - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'This is a mocked discussion', type: 'Discussion', }); @@ -245,7 +245,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -273,7 +273,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -301,7 +301,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -329,7 +329,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -357,7 +357,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -385,7 +385,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -404,7 +404,7 @@ describe('utils/subject.ts', () => { describe('Issues', () => { let mockNotification: Notification; beforeEach(() => { - mockNotification = partialMockNotification({ + mockNotification = partialMockedNotification({ title: 'This is a mocked issue', type: 'Issue', url: 'https://api.github.com/repos/gitify-app/notifications-test/issues/1', @@ -424,7 +424,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -449,7 +449,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -478,7 +478,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -507,7 +507,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -536,7 +536,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -564,7 +564,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -583,7 +583,7 @@ describe('utils/subject.ts', () => { let mockNotification: Notification; beforeEach(() => { - mockNotification = partialMockNotification({ + mockNotification = partialMockedNotification({ title: 'This is a mocked pull request', type: 'PullRequest', url: 'https://api.github.com/repos/gitify-app/notifications-test/pulls/1', @@ -612,7 +612,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -647,7 +647,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -682,7 +682,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -717,7 +717,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -751,7 +751,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -784,7 +784,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -832,7 +832,7 @@ describe('utils/subject.ts', () => { const result = await getLatestReviewForReviewers( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual([ @@ -848,7 +848,7 @@ describe('utils/subject.ts', () => { const result = await getLatestReviewForReviewers( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toBeNull(); @@ -859,7 +859,7 @@ describe('utils/subject.ts', () => { const result = await getLatestReviewForReviewers( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toBeNull(); @@ -869,7 +869,7 @@ describe('utils/subject.ts', () => { describe('Releases', () => { it('release notification', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'This is a mocked release', type: 'Release', url: 'https://api.github.com/repos/gitify-app/notifications-test/releases/1', @@ -883,7 +883,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -900,14 +900,14 @@ describe('utils/subject.ts', () => { describe('WorkflowRuns - GitHub Actions', () => { it('deploy review workflow run state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'some-user requested your review to deploy to an environment', type: 'WorkflowRun', }); const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toEqual({ @@ -917,7 +917,7 @@ describe('utils/subject.ts', () => { }); it('unknown workflow run state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'some-user requested your unknown-state to deploy to an environment', type: 'WorkflowRun', @@ -925,21 +925,21 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toBeNull(); }); it('unhandled workflow run title', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'unhandled workflow run structure', type: 'WorkflowRun', }); const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toBeNull(); @@ -948,7 +948,7 @@ describe('utils/subject.ts', () => { describe('Default', () => { it('unhandled subject details', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'There is no special subject handling for this notification type', type: 'RepositoryInvitation', @@ -956,7 +956,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockAccounts.token, + mockedAccounts.token, ); expect(result).toBeNull(); @@ -970,7 +970,7 @@ describe('utils/subject.ts', () => { .mockImplementation(); const mockError = new Error('Test error'); - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'This issue will throw an error', type: 'Issue', url: 'https://api.github.com/repos/gitify-app/notifications-test/issues/1', @@ -980,7 +980,7 @@ describe('utils/subject.ts', () => { .get('/repos/gitify-app/notifications-test/issues/1') .replyWithError(mockError); - await getGitifySubjectDetails(mockNotification, mockAccounts.token); + await getGitifySubjectDetails(mockNotification, mockedAccounts.token); expect(consoleErrorSpy).toHaveBeenCalledWith( 'Error occurred while fetching details for Issue notification: This issue will throw an error', @@ -992,7 +992,7 @@ describe('utils/subject.ts', () => { describe('getCheckSuiteState', () => { it('cancelled check suite state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'Demo workflow run cancelled for feature/foo branch', type: 'CheckSuite', }); @@ -1009,7 +1009,7 @@ describe('utils/subject.ts', () => { }); it('failed check suite state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'Demo workflow run failed for main branch', type: 'CheckSuite', }); @@ -1026,7 +1026,7 @@ describe('utils/subject.ts', () => { }); it('multiple attempts failed check suite state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'Demo workflow run, Attempt #3 failed for main branch', type: 'CheckSuite', }); @@ -1043,7 +1043,7 @@ describe('utils/subject.ts', () => { }); it('skipped check suite state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'Demo workflow run skipped for main branch', type: 'CheckSuite', }); @@ -1060,7 +1060,7 @@ describe('utils/subject.ts', () => { }); it('successful check suite state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'Demo workflow run succeeded for main branch', type: 'CheckSuite', }); @@ -1077,7 +1077,7 @@ describe('utils/subject.ts', () => { }); it('unknown check suite state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'Demo workflow run unknown-status for main branch', type: 'CheckSuite', }); @@ -1094,7 +1094,7 @@ describe('utils/subject.ts', () => { }); it('unhandled check suite title', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'A title that is not in the structure we expect', type: 'CheckSuite', }); @@ -1107,7 +1107,7 @@ describe('utils/subject.ts', () => { describe('getWorkflowRunState', () => { it('deploy review workflow run state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'some-user requested your review to deploy to an environment', type: 'WorkflowRun', }); @@ -1122,7 +1122,7 @@ describe('utils/subject.ts', () => { }); it('unknown workflow run state', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'some-user requested your unknown-state to deploy to an environment', type: 'WorkflowRun', @@ -1138,7 +1138,7 @@ describe('utils/subject.ts', () => { }); it('unhandled workflow run title', async () => { - const mockNotification = partialMockNotification({ + const mockNotification = partialMockedNotification({ title: 'unhandled workflow run structure', type: 'WorkflowRun', }); From 7f0a17ab99ca2d248d0cdaf4b9f77331aaef3f24 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 27 May 2024 08:30:42 -0400 Subject: [PATCH 2/2] refactor(mocks): rename mocks --- src/__mocks__/notifications-mocks.ts | 16 +- src/__mocks__/partial-mocks.ts | 12 +- src/__mocks__/state-mocks.ts | 12 +- src/components/AccountNotifications.test.tsx | 4 +- src/components/NotificationRow.test.tsx | 56 +++---- src/components/Repository.test.tsx | 4 +- src/components/Sidebar.test.tsx | 14 +- src/context/App.test.tsx | 14 +- src/hooks/useNotifications.test.ts | 112 +++++++------- src/routes/LoginWithOAuthApp.test.tsx | 4 +- src/routes/Notifications.test.tsx | 12 +- src/routes/Settings.test.tsx | 82 +++++----- src/utils/api/__mocks__/response-mocks.ts | 23 ++- src/utils/helpers.test.ts | 136 ++++++++--------- src/utils/notifications.test.ts | 48 +++--- src/utils/remove-notification.test.ts | 26 ++-- src/utils/remove-notifications.test.ts | 20 +-- src/utils/storage.test.ts | 4 +- src/utils/subject.test.ts | 148 +++++++++---------- 19 files changed, 370 insertions(+), 377 deletions(-) diff --git a/src/__mocks__/notifications-mocks.ts b/src/__mocks__/notifications-mocks.ts index 071099b76..a4a359f10 100644 --- a/src/__mocks__/notifications-mocks.ts +++ b/src/__mocks__/notifications-mocks.ts @@ -1,24 +1,24 @@ import type { AccountNotifications } from '../types'; import { - mockedEnterpriseNotifications, - mockedGitHubNotifications, - mockedSingleNotification, + mockEnterpriseNotifications, + mockGitHubNotifications, + mockSingleNotification, } from '../utils/api/__mocks__/response-mocks'; -export const mockedAccountNotifications: AccountNotifications[] = [ +export const mockAccountNotifications: AccountNotifications[] = [ { hostname: 'github.com', - notifications: mockedGitHubNotifications, + notifications: mockGitHubNotifications, }, { hostname: 'github.gitify.io', - notifications: mockedEnterpriseNotifications, + notifications: mockEnterpriseNotifications, }, ]; -export const mockedSingleAccountNotifications: AccountNotifications[] = [ +export const mockSingleAccountNotifications: AccountNotifications[] = [ { hostname: 'github.com', - notifications: [mockedSingleNotification], + notifications: [mockSingleNotification], }, ]; diff --git a/src/__mocks__/partial-mocks.ts b/src/__mocks__/partial-mocks.ts index 1166cc08b..f0d2c0ef6 100644 --- a/src/__mocks__/partial-mocks.ts +++ b/src/__mocks__/partial-mocks.ts @@ -1,24 +1,24 @@ import type { Notification, Subject, User } from '../typesGitHub'; import Constants from '../utils/constants'; -export function partialMockedNotification( +export function partialMockNotification( subject: Partial, ): Notification { - const mockedNotification: Partial = { + const mockNotification: Partial = { hostname: Constants.GITHUB_API_BASE_URL, subject: subject as Subject, }; - return mockedNotification as Notification; + return mockNotification as Notification; } -export function partialMockedUser(login: string): User { - const mockedUser: Partial = { +export function partialMockUser(login: string): User { + const mockUser: Partial = { login: login, html_url: `https://github.com/${login}`, avatar_url: 'https://avatars.githubusercontent.com/u/583231?v=4', type: 'User', }; - return mockedUser as User; + return mockUser as User; } diff --git a/src/__mocks__/state-mocks.ts b/src/__mocks__/state-mocks.ts index e844a3940..4a701fab6 100644 --- a/src/__mocks__/state-mocks.ts +++ b/src/__mocks__/state-mocks.ts @@ -6,26 +6,26 @@ import { Theme, } from '../types'; -export const mockedEnterpriseAccounts: EnterpriseAccount[] = [ +export const mockEnterpriseAccounts: EnterpriseAccount[] = [ { hostname: 'github.gitify.io', token: '1234568790', }, ]; -export const mockedUser: GitifyUser = { +export const mockUser: GitifyUser = { login: 'octocat', name: 'Mona Lisa Octocat', id: 123456789, }; -export const mockedAccounts: AuthState = { +export const mockAccounts: AuthState = { token: 'token-123-456', - enterpriseAccounts: mockedEnterpriseAccounts, - user: mockedUser, + enterpriseAccounts: mockEnterpriseAccounts, + user: mockUser, }; -export const mockedSettings: SettingsState = { +export const mockSettings: SettingsState = { participating: false, playSound: true, showNotifications: true, diff --git a/src/components/AccountNotifications.test.tsx b/src/components/AccountNotifications.test.tsx index 2c1b44db0..f52955e5b 100644 --- a/src/components/AccountNotifications.test.tsx +++ b/src/components/AccountNotifications.test.tsx @@ -1,5 +1,5 @@ import { render } from '@testing-library/react'; -import { mockedGitHubNotifications } from '../utils/api/__mocks__/response-mocks'; +import { mockGitHubNotifications } from '../utils/api/__mocks__/response-mocks'; import { AccountNotifications } from './AccountNotifications'; jest.mock('./Repository', () => ({ @@ -10,7 +10,7 @@ describe('components/AccountNotifications.tsx', () => { it('should render itself (github.com with notifications)', () => { const props = { hostname: 'github.com', - notifications: mockedGitHubNotifications, + notifications: mockGitHubNotifications, showAccountHostname: true, }; diff --git a/src/components/NotificationRow.test.tsx b/src/components/NotificationRow.test.tsx index 52379dcdd..6657a9bad 100644 --- a/src/components/NotificationRow.test.tsx +++ b/src/components/NotificationRow.test.tsx @@ -1,9 +1,9 @@ import { fireEvent, render, screen } from '@testing-library/react'; import { shell } from 'electron'; -import { mockedAccounts, mockedSettings } from '../__mocks__/state-mocks'; +import { mockAccounts, mockSettings } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import type { UserType } from '../typesGitHub'; -import { mockedSingleNotification } from '../utils/api/__mocks__/response-mocks'; +import { mockSingleNotification } from '../utils/api/__mocks__/response-mocks'; import * as helpers from '../utils/helpers'; import { NotificationRow } from './NotificationRow'; @@ -22,7 +22,7 @@ describe('components/NotificationRow.tsx', () => { .mockImplementation(() => new Date('2024').valueOf()); const props = { - notification: mockedSingleNotification, + notification: mockSingleNotification, hostname: 'github.com', }; @@ -35,7 +35,7 @@ describe('components/NotificationRow.tsx', () => { .spyOn(global.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); - const mockNotification = mockedSingleNotification; + const mockNotification = mockSingleNotification; mockNotification.last_read_at = null; const props = { @@ -52,7 +52,7 @@ describe('components/NotificationRow.tsx', () => { .spyOn(global.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); - const mockNotification = mockedSingleNotification; + const mockNotification = mockSingleNotification; mockNotification.subject.user = null; const props = { @@ -70,7 +70,7 @@ describe('components/NotificationRow.tsx', () => { .spyOn(global.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); - const mockNotification = mockedSingleNotification; + const mockNotification = mockSingleNotification; mockNotification.subject.comments = null; const props = { @@ -87,7 +87,7 @@ describe('components/NotificationRow.tsx', () => { .spyOn(global.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); - const mockNotification = mockedSingleNotification; + const mockNotification = mockSingleNotification; mockNotification.subject.comments = 1; const props = { @@ -104,7 +104,7 @@ describe('components/NotificationRow.tsx', () => { .spyOn(global.Date, 'now') .mockImplementation(() => new Date('2024').valueOf()); - const mockNotification = mockedSingleNotification; + const mockNotification = mockSingleNotification; mockNotification.subject.comments = 2; const props = { @@ -122,16 +122,16 @@ describe('components/NotificationRow.tsx', () => { const removeNotificationFromState = jest.fn(); const props = { - notification: mockedSingleNotification, + notification: mockSingleNotification, hostname: 'github.com', }; render( @@ -147,16 +147,16 @@ describe('components/NotificationRow.tsx', () => { const removeNotificationFromState = jest.fn(); const props = { - notification: mockedSingleNotification, + notification: mockSingleNotification, hostname: 'github.com', }; render( @@ -172,16 +172,16 @@ describe('components/NotificationRow.tsx', () => { const markNotificationDone = jest.fn(); const props = { - notification: mockedSingleNotification, + notification: mockSingleNotification, hostname: 'github.com', }; render( @@ -197,15 +197,15 @@ describe('components/NotificationRow.tsx', () => { const markNotificationRead = jest.fn(); const props = { - notification: mockedSingleNotification, + notification: mockSingleNotification, hostname: 'github.com', }; render( @@ -222,15 +222,15 @@ describe('components/NotificationRow.tsx', () => { const markNotificationDone = jest.fn(); const props = { - notification: mockedSingleNotification, + notification: mockSingleNotification, hostname: 'github.com', }; render( @@ -247,7 +247,7 @@ describe('components/NotificationRow.tsx', () => { const unsubscribeNotification = jest.fn(); const props = { - notification: mockedSingleNotification, + notification: mockSingleNotification, hostname: 'github.com', }; @@ -265,9 +265,9 @@ describe('components/NotificationRow.tsx', () => { it('should open notification user profile', () => { const props = { notification: { - ...mockedSingleNotification, + ...mockSingleNotification, subject: { - ...mockedSingleNotification.subject, + ...mockSingleNotification.subject, user: { login: 'some-user', html_url: 'https://github.com/some-user', @@ -284,8 +284,8 @@ describe('components/NotificationRow.tsx', () => { render( diff --git a/src/components/Repository.test.tsx b/src/components/Repository.test.tsx index 54e613931..f35a16f51 100644 --- a/src/components/Repository.test.tsx +++ b/src/components/Repository.test.tsx @@ -1,6 +1,6 @@ import { fireEvent, render, screen } from '@testing-library/react'; import { AppContext } from '../context/App'; -import { mockedGitHubNotifications } from '../utils/api/__mocks__/response-mocks'; +import { mockGitHubNotifications } from '../utils/api/__mocks__/response-mocks'; import { RepositoryNotifications } from './Repository'; const { shell } = require('electron'); @@ -15,7 +15,7 @@ describe('components/Repository.tsx', () => { const props = { hostname: 'github.com', repoName: 'gitify-app/notifications-test', - repoNotifications: mockedGitHubNotifications, + repoNotifications: mockGitHubNotifications, }; beforeEach(() => { diff --git a/src/components/Sidebar.test.tsx b/src/components/Sidebar.test.tsx index 0540f3de4..37fd8e63f 100644 --- a/src/components/Sidebar.test.tsx +++ b/src/components/Sidebar.test.tsx @@ -1,8 +1,8 @@ import { fireEvent, render, screen } from '@testing-library/react'; import { MemoryRouter } from 'react-router-dom'; const { shell, ipcRenderer } = require('electron'); -import { mockedAccountNotifications } from '../__mocks__/notifications-mocks'; -import { mockedSettings } from '../__mocks__/state-mocks'; +import { mockAccountNotifications } from '../__mocks__/notifications-mocks'; +import { mockSettings } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import { Sidebar } from './Sidebar'; @@ -31,8 +31,8 @@ describe('components/Sidebar.tsx', () => { const tree = render( @@ -46,7 +46,7 @@ describe('components/Sidebar.tsx', () => { it('should render itself & its children (logged out)', () => { const tree = render( @@ -131,7 +131,7 @@ describe('components/Sidebar.tsx', () => { @@ -195,7 +195,7 @@ describe('components/Sidebar.tsx', () => { diff --git a/src/context/App.test.tsx b/src/context/App.test.tsx index e6dd964c9..0ab7083f2 100644 --- a/src/context/App.test.tsx +++ b/src/context/App.test.tsx @@ -1,7 +1,7 @@ import { act, fireEvent, render, waitFor } from '@testing-library/react'; import { useContext } from 'react'; -import { mockedAccounts, mockedSettings } from '../__mocks__/state-mocks'; +import { mockAccounts, mockSettings } from '../__mocks__/state-mocks'; import { useNotifications } from '../hooks/useNotifications'; import type { AuthState, SettingsState } from '../types'; import * as apiRequests from '../utils/api/request'; @@ -15,8 +15,8 @@ jest.mock('../hooks/useNotifications'); const customRender = ( ui, - accounts: AuthState = mockedAccounts, - settings: SettingsState = mockedSettings, + accounts: AuthState = mockAccounts, + settings: SettingsState = mockSettings, ) => { return render( @@ -136,7 +136,7 @@ describe('context/App.tsx', () => { token: null, user: null, }, - mockedSettings, + mockSettings, '123-456', 'github.com', ); @@ -165,7 +165,7 @@ describe('context/App.tsx', () => { expect(markNotificationDoneMock).toHaveBeenCalledTimes(1); expect(markNotificationDoneMock).toHaveBeenCalledWith( { enterpriseAccounts: [], token: null, user: null }, - mockedSettings, + mockSettings, '123-456', 'github.com', ); @@ -194,7 +194,7 @@ describe('context/App.tsx', () => { expect(unsubscribeNotificationMock).toHaveBeenCalledTimes(1); expect(unsubscribeNotificationMock).toHaveBeenCalledWith( { enterpriseAccounts: [], token: null, user: null }, - mockedSettings, + mockSettings, '123-456', 'github.com', ); @@ -228,7 +228,7 @@ describe('context/App.tsx', () => { expect(markRepoNotificationsMock).toHaveBeenCalledTimes(1); expect(markRepoNotificationsMock).toHaveBeenCalledWith( { enterpriseAccounts: [], token: null, user: null }, - mockedSettings, + mockSettings, 'gitify-app/notifications-test', 'github.com', ); diff --git a/src/hooks/useNotifications.test.ts b/src/hooks/useNotifications.test.ts index bc7c09acb..0eedb7527 100644 --- a/src/hooks/useNotifications.test.ts +++ b/src/hooks/useNotifications.test.ts @@ -2,13 +2,9 @@ import { act, renderHook, waitFor } from '@testing-library/react'; import axios, { AxiosError } from 'axios'; import nock from 'nock'; -import { - mockedAccounts, - mockedSettings, - mockedUser, -} from '../__mocks__/state-mocks'; +import { mockAccounts, mockSettings, mockUser } from '../__mocks__/state-mocks'; import type { AuthState } from '../types'; -import { mockedNotificationUser } from '../utils/api/__mocks__/response-mocks'; +import { mockNotificationUser } from '../utils/api/__mocks__/response-mocks'; import { Errors } from '../utils/constants'; import { useNotifications } from './useNotifications'; @@ -38,8 +34,8 @@ describe('hooks/useNotifications.ts', () => { const { result } = renderHook(() => useNotifications()); act(() => { - result.current.fetchNotifications(mockedAccounts, { - ...mockedSettings, + result.current.fetchNotifications(mockAccounts, { + ...mockSettings, detailedNotifications: false, }); }); @@ -91,7 +87,7 @@ describe('hooks/useNotifications.ts', () => { const { result } = renderHook(() => useNotifications()); act(() => { - result.current.fetchNotifications(mockedAccounts, mockedSettings); + result.current.fetchNotifications(mockAccounts, mockSettings); }); expect(result.current.status).toBe('loading'); @@ -107,7 +103,7 @@ describe('hooks/useNotifications.ts', () => { describe('enterprise', () => { it('should fetch notifications with success - enterprise only', async () => { const accounts: AuthState = { - ...mockedAccounts, + ...mockAccounts, token: null, }; @@ -124,7 +120,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.fetchNotifications(accounts, { - ...mockedSettings, + ...mockSettings, detailedNotifications: false, }); }); @@ -141,7 +137,7 @@ describe('hooks/useNotifications.ts', () => { it('should fetch notifications with failure - enterprise only', async () => { const accounts: AuthState = { - ...mockedAccounts, + ...mockAccounts, token: null, }; @@ -160,7 +156,7 @@ describe('hooks/useNotifications.ts', () => { const { result } = renderHook(() => useNotifications()); act(() => { - result.current.fetchNotifications(accounts, mockedSettings); + result.current.fetchNotifications(accounts, mockSettings); }); await waitFor(() => { @@ -172,9 +168,9 @@ describe('hooks/useNotifications.ts', () => { describe('github.com', () => { it('should fetch notifications with success - github.com only', async () => { const accounts: AuthState = { - ...mockedAccounts, + ...mockAccounts, enterpriseAccounts: [], - user: mockedUser, + user: mockUser, }; const notifications = [ @@ -190,7 +186,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.fetchNotifications(accounts, { - ...mockedSettings, + ...mockSettings, detailedNotifications: false, }); }); @@ -205,7 +201,7 @@ describe('hooks/useNotifications.ts', () => { it('should fetch notifications with failures - github.com only', async () => { const accounts: AuthState = { - ...mockedAccounts, + ...mockAccounts, enterpriseAccounts: [], }; @@ -224,7 +220,7 @@ describe('hooks/useNotifications.ts', () => { const { result } = renderHook(() => useNotifications()); act(() => { - result.current.fetchNotifications(accounts, mockedSettings); + result.current.fetchNotifications(accounts, mockSettings); }); await waitFor(() => { @@ -237,9 +233,9 @@ describe('hooks/useNotifications.ts', () => { describe('with detailed notifications', () => { it('should fetch notifications with success', async () => { const accounts: AuthState = { - ...mockedAccounts, + ...mockAccounts, enterpriseAccounts: [], - user: mockedUser, + user: mockUser, }; const notifications = [ @@ -371,31 +367,31 @@ describe('hooks/useNotifications.ts', () => { .reply(200, { state: 'closed', merged: true, - user: mockedNotificationUser, + user: mockNotificationUser, }); nock('https://api.github.com') .get('/repos/gitify-app/notifications-test/issues/3/comments') .reply(200, { - user: mockedNotificationUser, + user: mockNotificationUser, }); nock('https://api.github.com') .get('/repos/gitify-app/notifications-test/pulls/4') .reply(200, { state: 'closed', merged: false, - user: mockedNotificationUser, + user: mockNotificationUser, }); nock('https://api.github.com') .get('/repos/gitify-app/notifications-test/issues/4/comments') .reply(200, { - user: mockedNotificationUser, + user: mockNotificationUser, }); const { result } = renderHook(() => useNotifications()); act(() => { result.current.fetchNotifications(accounts, { - ...mockedSettings, + ...mockSettings, detailedNotifications: true, }); }); @@ -430,8 +426,8 @@ describe('hooks/useNotifications.ts', () => { const { result } = renderHook(() => useNotifications()); act(() => { - result.current.fetchNotifications(mockedAccounts, { - ...mockedSettings, + result.current.fetchNotifications(mockAccounts, { + ...mockSettings, detailedNotifications: false, }); }); @@ -442,7 +438,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.removeNotificationFromState( - mockedSettings, + mockSettings, result.current.notifications[0].notifications[0].id, result.current.notifications[0].hostname, ); @@ -456,7 +452,7 @@ describe('hooks/useNotifications.ts', () => { const id = 'notification-123'; describe('github.com', () => { - const accounts = { ...mockedAccounts, enterpriseAccounts: [] }; + const accounts = { ...mockAccounts, enterpriseAccounts: [] }; const hostname = 'github.com'; it('should mark a notification as read with success - github.com', async () => { @@ -469,7 +465,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationRead( accounts, - mockedSettings, + mockSettings, id, hostname, ); @@ -492,7 +488,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationRead( accounts, - mockedSettings, + mockSettings, id, hostname, ); @@ -507,7 +503,7 @@ describe('hooks/useNotifications.ts', () => { }); describe('enterprise', () => { - const accounts = { ...mockedAccounts, token: null }; + const accounts = { ...mockAccounts, token: null }; const hostname = 'github.gitify.io'; it('should mark a notification as read with success - enterprise', async () => { @@ -520,7 +516,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationRead( accounts, - mockedSettings, + mockSettings, id, hostname, ); @@ -543,7 +539,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationRead( accounts, - mockedSettings, + mockSettings, id, hostname, ); @@ -562,7 +558,7 @@ describe('hooks/useNotifications.ts', () => { const id = 'notification-123'; describe('github.com', () => { - const accounts = { ...mockedAccounts, enterpriseAccounts: [] }; + const accounts = { ...mockAccounts, enterpriseAccounts: [] }; const hostname = 'github.com'; it('should mark a notification as done with success - github.com', async () => { @@ -575,7 +571,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationDone( accounts, - mockedSettings, + mockSettings, id, hostname, ); @@ -598,7 +594,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationDone( accounts, - mockedSettings, + mockSettings, id, hostname, ); @@ -613,7 +609,7 @@ describe('hooks/useNotifications.ts', () => { }); describe('enterprise', () => { - const accounts = { ...mockedAccounts, token: null }; + const accounts = { ...mockAccounts, token: null }; const hostname = 'github.gitify.io'; it('should mark a notification as done with success - enterprise', async () => { @@ -626,7 +622,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationDone( accounts, - mockedSettings, + mockSettings, id, hostname, ); @@ -649,7 +645,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markNotificationDone( accounts, - mockedSettings, + mockSettings, id, hostname, ); @@ -668,7 +664,7 @@ describe('hooks/useNotifications.ts', () => { const id = 'notification-123'; describe('github.com', () => { - const accounts = { ...mockedAccounts, enterpriseAccounts: [] }; + const accounts = { ...mockAccounts, enterpriseAccounts: [] }; const hostname = 'github.com'; it('should unsubscribe from a notification with success - github.com', async () => { @@ -687,7 +683,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.unsubscribeNotification( accounts, - mockedSettings, + mockSettings, id, hostname, ); @@ -716,7 +712,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.unsubscribeNotification( accounts, - mockedSettings, + mockSettings, id, hostname, ); @@ -731,7 +727,7 @@ describe('hooks/useNotifications.ts', () => { }); describe('enterprise', () => { - const accounts = { ...mockedAccounts, token: null }; + const accounts = { ...mockAccounts, token: null }; const hostname = 'github.gitify.io'; it('should unsubscribe from a notification with success - enterprise', async () => { @@ -750,7 +746,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.unsubscribeNotification( accounts, - mockedSettings, + mockSettings, id, hostname, ); @@ -779,7 +775,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.unsubscribeNotification( accounts, - mockedSettings, + mockSettings, id, hostname, ); @@ -798,7 +794,7 @@ describe('hooks/useNotifications.ts', () => { const repoSlug = 'gitify-app/notifications-test'; describe('github.com', () => { - const accounts = { ...mockedAccounts, enterpriseAccounts: [] }; + const accounts = { ...mockAccounts, enterpriseAccounts: [] }; const hostname = 'github.com'; it("should mark a repository's notifications as read with success - github.com", async () => { @@ -811,7 +807,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotifications( accounts, - mockedSettings, + mockSettings, repoSlug, hostname, ); @@ -834,7 +830,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotifications( accounts, - mockedSettings, + mockSettings, repoSlug, hostname, ); @@ -849,7 +845,7 @@ describe('hooks/useNotifications.ts', () => { }); describe('enterprise', () => { - const accounts = { ...mockedAccounts, token: null }; + const accounts = { ...mockAccounts, token: null }; const hostname = 'github.gitify.io'; it("should mark a repository's notifications as read with success - enterprise", async () => { @@ -862,7 +858,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotifications( accounts, - mockedSettings, + mockSettings, repoSlug, hostname, ); @@ -885,7 +881,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotifications( accounts, - mockedSettings, + mockSettings, repoSlug, hostname, ); @@ -905,7 +901,7 @@ describe('hooks/useNotifications.ts', () => { const id = 'notification-123'; describe('github.com', () => { - const accounts = { ...mockedAccounts, enterpriseAccounts: [] }; + const accounts = { ...mockAccounts, enterpriseAccounts: [] }; const hostname = 'github.com'; it("should mark a repository's notifications as done with success - github.com", async () => { @@ -918,7 +914,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotificationsDone( accounts, - mockedSettings, + mockSettings, repoSlug, hostname, ); @@ -941,7 +937,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotificationsDone( accounts, - mockedSettings, + mockSettings, repoSlug, hostname, ); @@ -956,7 +952,7 @@ describe('hooks/useNotifications.ts', () => { }); describe('enterprise', () => { - const accounts = { ...mockedAccounts, token: null }; + const accounts = { ...mockAccounts, token: null }; const hostname = 'github.gitify.io'; it("should mark a repository's notifications as done with success - enterprise", async () => { @@ -969,7 +965,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotificationsDone( accounts, - mockedSettings, + mockSettings, repoSlug, hostname, ); @@ -992,7 +988,7 @@ describe('hooks/useNotifications.ts', () => { act(() => { result.current.markRepoNotificationsDone( accounts, - mockedSettings, + mockSettings, repoSlug, hostname, ); diff --git a/src/routes/LoginWithOAuthApp.test.tsx b/src/routes/LoginWithOAuthApp.test.tsx index 6373cf7b4..c9bc29020 100644 --- a/src/routes/LoginWithOAuthApp.test.tsx +++ b/src/routes/LoginWithOAuthApp.test.tsx @@ -2,7 +2,7 @@ import { fireEvent, render, screen } from '@testing-library/react'; import { MemoryRouter } from 'react-router-dom'; const { ipcRenderer } = require('electron'); import { shell } from 'electron'; -import { mockedEnterpriseAccounts } from '../__mocks__/state-mocks'; +import { mockEnterpriseAccounts } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import type { AuthState } from '../types'; import { LoginWithOAuthApp, validate } from './LoginWithOAuthApp'; @@ -125,7 +125,7 @@ describe('routes/LoginWithOAuthApp.tsx', () => { ({ describe('routes/Notifications.tsx', () => { it('should render itself & its children (with notifications)', () => { const tree = render( - + , ); @@ -43,8 +41,8 @@ describe('routes/Notifications.tsx', () => { const tree = render( diff --git a/src/routes/Settings.test.tsx b/src/routes/Settings.test.tsx index 3ef51713a..c9f50584f 100644 --- a/src/routes/Settings.test.tsx +++ b/src/routes/Settings.test.tsx @@ -2,7 +2,7 @@ import { act, fireEvent, render, screen } from '@testing-library/react'; import { MemoryRouter } from 'react-router-dom'; const { ipcRenderer } = require('electron'); import { shell } from 'electron'; -import { mockedAccounts, mockedSettings } from '../__mocks__/state-mocks'; +import { mockAccounts, mockSettings } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import { SettingsRoute } from './Settings'; @@ -24,7 +24,7 @@ describe('routes/Settings.tsx', () => { await act(async () => { render( @@ -41,8 +41,8 @@ describe('routes/Settings.tsx', () => { render( @@ -62,8 +62,8 @@ describe('routes/Settings.tsx', () => { render( @@ -85,8 +85,8 @@ describe('routes/Settings.tsx', () => { render( @@ -115,8 +115,8 @@ describe('routes/Settings.tsx', () => { render( @@ -140,8 +140,8 @@ describe('routes/Settings.tsx', () => { render( @@ -176,11 +176,11 @@ describe('routes/Settings.tsx', () => { @@ -217,11 +217,11 @@ describe('routes/Settings.tsx', () => { @@ -257,8 +257,8 @@ describe('routes/Settings.tsx', () => { render( @@ -282,8 +282,8 @@ describe('routes/Settings.tsx', () => { render( @@ -312,8 +312,8 @@ describe('routes/Settings.tsx', () => { render( @@ -343,8 +343,8 @@ describe('routes/Settings.tsx', () => { render( @@ -368,8 +368,8 @@ describe('routes/Settings.tsx', () => { render( @@ -393,8 +393,8 @@ describe('routes/Settings.tsx', () => { render( @@ -420,8 +420,8 @@ describe('routes/Settings.tsx', () => { render( @@ -445,8 +445,8 @@ describe('routes/Settings.tsx', () => { render( @@ -475,8 +475,8 @@ describe('routes/Settings.tsx', () => { render( @@ -498,9 +498,9 @@ describe('routes/Settings.tsx', () => { render( { render( @@ -546,8 +546,8 @@ describe('routes/Settings.tsx', () => { render( @@ -572,7 +572,7 @@ describe('routes/Settings.tsx', () => { await act(async () => { render( diff --git a/src/utils/api/__mocks__/response-mocks.ts b/src/utils/api/__mocks__/response-mocks.ts index 7ecfd48d7..dcaf441b5 100644 --- a/src/utils/api/__mocks__/response-mocks.ts +++ b/src/utils/api/__mocks__/response-mocks.ts @@ -9,7 +9,7 @@ import type { } from '../../../typesGitHub'; import Constants from '../../constants'; -export const mockedNotificationUser: User = { +export const mockNotificationUser: User = { login: 'octocat', id: 123456789, node_id: 'MDQ6VXNlcjE=', @@ -33,7 +33,7 @@ export const mockedNotificationUser: User = { // 2 Notifications // Hostname : 'github.com' // Repository : 'gitify-app/notifications-test' -export const mockedGitHubNotifications: Notification[] = [ +export const mockGitHubNotifications: Notification[] = [ { hostname: Constants.GITHUB_API_BASE_URL, id: '138661096', @@ -240,7 +240,7 @@ export const mockedGitHubNotifications: Notification[] = [ // 2 Notifications // Hostname : 'github.gitify.io' // Repository : 'myorg/notifications-test' -export const mockedEnterpriseNotifications: Notification[] = [ +export const mockEnterpriseNotifications: Notification[] = [ { hostname: 'https://github.gitify.io/api/v3', id: '3', @@ -351,32 +351,32 @@ export const mockedEnterpriseNotifications: Notification[] = [ }, ]; -const mockedDiscussionAuthor: DiscussionAuthor = { +const mockDiscussionAuthor: DiscussionAuthor = { login: 'comment-user', url: 'https://github.com/comment-user', avatar_url: 'https://avatars.githubusercontent.com/u/123456789?v=4', type: 'User', }; -const mockedDiscussionReplier: DiscussionAuthor = { +const mockDiscussionReplier: DiscussionAuthor = { login: 'reply-user', url: 'https://github.com/reply-user', avatar_url: 'https://avatars.githubusercontent.com/u/123456789?v=4', type: 'User', }; -export const mockedDiscussionComments: DiscussionComments = { +export const mockDiscussionComments: DiscussionComments = { nodes: [ { databaseId: 2258799, createdAt: '2022-02-27T01:22:20Z', - author: mockedDiscussionAuthor, + author: mockDiscussionAuthor, replies: { nodes: [ { databaseId: 2300902, createdAt: '2022-03-05T17:43:52Z', - author: mockedDiscussionReplier, + author: mockDiscussionReplier, }, ], }, @@ -385,7 +385,7 @@ export const mockedDiscussionComments: DiscussionComments = { totalCount: 2, }; -export const mockedGraphQLResponse: GraphQLSearch = { +export const mockGraphQLResponse: GraphQLSearch = { data: { search: { nodes: [ @@ -400,12 +400,11 @@ export const mockedGraphQLResponse: GraphQLSearch = { avatar_url: 'https://avatars.githubusercontent.com/u/123456789?v=4', type: 'User', }, - comments: mockedDiscussionComments, + comments: mockDiscussionComments, }, ], }, }, }; -export const mockedSingleNotification: Notification = - mockedGitHubNotifications[0]; +export const mockSingleNotification: Notification = mockGitHubNotifications[0]; diff --git a/src/utils/helpers.test.ts b/src/utils/helpers.test.ts index b587e6006..533330085 100644 --- a/src/utils/helpers.test.ts +++ b/src/utils/helpers.test.ts @@ -1,9 +1,9 @@ import type { AxiosPromise, AxiosResponse } from 'axios'; -import { mockedAccounts, mockedUser } from '../__mocks__/state-mocks'; +import { mockAccounts, mockUser } from '../__mocks__/state-mocks'; import type { SubjectType } from '../typesGitHub'; import { - mockedGraphQLResponse, - mockedSingleNotification, + mockGraphQLResponse, + mockSingleNotification, } from './api/__mocks__/response-mocks'; import * as apiRequests from './api/request'; import { @@ -19,13 +19,13 @@ describe('utils/helpers.ts', () => { describe('isPersonalAccessTokenLoggedIn', () => { it('logged in', () => { expect( - isPersonalAccessTokenLoggedIn({ ...mockedAccounts, token: '1234' }), + isPersonalAccessTokenLoggedIn({ ...mockAccounts, token: '1234' }), ).toBe(true); }); it('logged out', () => { expect( - isPersonalAccessTokenLoggedIn({ ...mockedAccounts, token: null }), + isPersonalAccessTokenLoggedIn({ ...mockAccounts, token: null }), ).toBe(false); }); }); @@ -34,7 +34,7 @@ describe('utils/helpers.ts', () => { it('logged in', () => { expect( isOAuthAppLoggedIn({ - ...mockedAccounts, + ...mockAccounts, enterpriseAccounts: [{ hostname: 'github.gitify.io', token: '1234' }], }), ).toBe(true); @@ -42,11 +42,11 @@ describe('utils/helpers.ts', () => { it('logged out', () => { expect( - isOAuthAppLoggedIn({ ...mockedAccounts, enterpriseAccounts: null }), + isOAuthAppLoggedIn({ ...mockAccounts, enterpriseAccounts: null }), ).toBe(false); expect( - isOAuthAppLoggedIn({ ...mockedAccounts, enterpriseAccounts: [] }), + isOAuthAppLoggedIn({ ...mockAccounts, enterpriseAccounts: [] }), ).toBe(false); }); }); @@ -66,8 +66,8 @@ describe('utils/helpers.ts', () => { describe('generateNotificationReferrerId', () => { it('should generate the notification_referrer_id', () => { const referrerId = generateNotificationReferrerId( - mockedSingleNotification.id, - mockedUser.id, + mockSingleNotification.id, + mockUser.id, ); expect(referrerId).toBe( 'MDE4Ok5vdGlmaWNhdGlvblRocmVhZDEzODY2MTA5NjoxMjM0NTY3ODk=', @@ -76,9 +76,9 @@ describe('utils/helpers.ts', () => { }); describe('generateGitHubWebUrl', () => { - const mockedHtmlUrl = + const mockHtmlUrl = 'https://github.com/gitify-app/notifications-test/issues/785'; - const mockedNotificationReferrer = + const mockNotificationReferrer = 'notification_referrer_id=MDE4Ok5vdGlmaWNhdGlvblRocmVhZDEzODY2MTA5NjoxMjM0NTY3ODk%3D'; const apiRequestAuthMock = jest.spyOn(apiRequests, 'apiRequestAuth'); @@ -98,7 +98,7 @@ describe('utils/helpers.ts', () => { const requestPromise = new Promise((resolve) => resolve({ data: { - html_url: mockedHtmlUrl, + html_url: mockHtmlUrl, }, } as AxiosResponse), ) as AxiosPromise; @@ -107,19 +107,19 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); expect(apiRequestAuthMock).toHaveBeenCalledWith( subject.latest_comment_url, 'GET', - mockedAccounts.token, + mockAccounts.token, ); - expect(result).toBe(`${mockedHtmlUrl}?${mockedNotificationReferrer}`); + expect(result).toBe(`${mockHtmlUrl}?${mockNotificationReferrer}`); }); it('Subject Url: when no latest comment url available, fetch subject html url', async () => { @@ -133,7 +133,7 @@ describe('utils/helpers.ts', () => { const requestPromise = new Promise((resolve) => resolve({ data: { - html_url: mockedHtmlUrl, + html_url: mockHtmlUrl, }, } as AxiosResponse), ) as AxiosPromise; @@ -142,19 +142,19 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); expect(apiRequestAuthMock).toHaveBeenCalledWith( subject.url, 'GET', - mockedAccounts.token, + mockAccounts.token, ); - expect(result).toBe(`${mockedHtmlUrl}?${mockedNotificationReferrer}`); + expect(result).toBe(`${mockHtmlUrl}?${mockNotificationReferrer}`); }); describe('Check Suite URLs', () => { @@ -168,15 +168,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Asuccess+branch%3Amain&${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Asuccess+branch%3Amain&${mockNotificationReferrer}`, ); }); @@ -190,15 +190,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Afailure+branch%3Amain&${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Afailure+branch%3Amain&${mockNotificationReferrer}`, ); }); @@ -212,15 +212,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Afailure+branch%3Amain&${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Afailure+branch%3Amain&${mockNotificationReferrer}`, ); }); @@ -234,15 +234,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Askipped+branch%3Amain&${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+is%3Askipped+branch%3Amain&${mockNotificationReferrer}`, ); }); @@ -256,15 +256,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?${mockNotificationReferrer}`, ); }); @@ -278,15 +278,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+branch%3Amain&${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?query=workflow%3A%22Demo%22+branch%3Amain&${mockNotificationReferrer}`, ); }); @@ -300,15 +300,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?${mockNotificationReferrer}`, ); }); }); @@ -332,15 +332,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); expect(result).toBe( - `${mockedSingleNotification.repository.html_url}/discussions?${mockedNotificationReferrer}`, + `${mockSingleNotification.repository.html_url}/discussions?${mockNotificationReferrer}`, ); }); @@ -355,7 +355,7 @@ describe('utils/helpers.ts', () => { const requestPromise = new Promise((resolve) => resolve({ data: { - ...mockedGraphQLResponse, + ...mockGraphQLResponse, }, } as AxiosResponse), ) as AxiosPromise; @@ -364,15 +364,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/discussions/612?${mockedNotificationReferrer}#discussioncomment-2300902`, + `https://github.com/gitify-app/notifications-test/discussions/612?${mockNotificationReferrer}#discussioncomment-2300902`, ); }); @@ -392,15 +392,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(1); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/discussions?${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/discussions?${mockNotificationReferrer}`, ); }); }); @@ -416,15 +416,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/invitations?${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/invitations?${mockNotificationReferrer}`, ); }); @@ -439,15 +439,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?query=is%3Awaiting&${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?query=is%3Awaiting&${mockNotificationReferrer}`, ); }); @@ -462,15 +462,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?${mockNotificationReferrer}`, ); }); @@ -484,15 +484,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `https://github.com/gitify-app/notifications-test/actions?${mockedNotificationReferrer}`, + `https://github.com/gitify-app/notifications-test/actions?${mockNotificationReferrer}`, ); }); }); @@ -507,15 +507,15 @@ describe('utils/helpers.ts', () => { const result = await generateGitHubWebUrl( { - ...mockedSingleNotification, + ...mockSingleNotification, subject: subject, }, - mockedAccounts, + mockAccounts, ); expect(apiRequestAuthMock).toHaveBeenCalledTimes(0); expect(result).toBe( - `${mockedSingleNotification.repository.html_url}?${mockedNotificationReferrer}`, + `${mockSingleNotification.repository.html_url}?${mockNotificationReferrer}`, ); }); diff --git a/src/utils/notifications.test.ts b/src/utils/notifications.test.ts index 57596ec16..6488677bc 100644 --- a/src/utils/notifications.test.ts +++ b/src/utils/notifications.test.ts @@ -1,16 +1,16 @@ import { ipcRenderer } from 'electron'; import { - mockedAccountNotifications, - mockedSingleAccountNotifications, + mockAccountNotifications, + mockSingleAccountNotifications, } from '../__mocks__/notifications-mocks'; -import { partialMockedNotification } from '../__mocks__/partial-mocks'; -import { mockedAccounts, mockedSettings } from '../__mocks__/state-mocks'; +import { partialMockNotification } from '../__mocks__/partial-mocks'; +import { mockAccounts, mockSettings } from '../__mocks__/state-mocks'; import { defaultSettings } from '../context/App'; import type { SettingsState } from '../types'; import { - mockedGitHubNotifications, - mockedSingleNotification, + mockGitHubNotifications, + mockSingleNotification, } from './api/__mocks__/response-mocks'; import * as helpers from './helpers'; import * as notificationsHelpers from './notifications'; @@ -33,9 +33,9 @@ describe('utils/notifications.ts', () => { notificationsHelpers.triggerNativeNotifications( [], - mockedAccountNotifications, + mockAccountNotifications, settings, - mockedAccounts, + mockAccounts, ); expect(notificationsHelpers.raiseNativeNotification).toHaveBeenCalledTimes( @@ -58,9 +58,9 @@ describe('utils/notifications.ts', () => { notificationsHelpers.triggerNativeNotifications( [], - mockedAccountNotifications, + mockAccountNotifications, settings, - mockedAccounts, + mockAccounts, ); expect(notificationsHelpers.raiseNativeNotification).not.toHaveBeenCalled(); @@ -78,10 +78,10 @@ describe('utils/notifications.ts', () => { jest.spyOn(notificationsHelpers, 'raiseSoundNotification'); notificationsHelpers.triggerNativeNotifications( - mockedSingleAccountNotifications, - mockedSingleAccountNotifications, + mockSingleAccountNotifications, + mockSingleAccountNotifications, settings, - mockedAccounts, + mockAccounts, ); expect(notificationsHelpers.raiseNativeNotification).not.toHaveBeenCalled(); @@ -102,7 +102,7 @@ describe('utils/notifications.ts', () => { [], [], settings, - mockedAccounts, + mockAccounts, ); expect(notificationsHelpers.raiseNativeNotification).not.toHaveBeenCalled(); @@ -114,23 +114,23 @@ describe('utils/notifications.ts', () => { const nativeNotification: Notification = notificationsHelpers.raiseNativeNotification( - [mockedSingleNotification], - mockedAccounts, + [mockSingleNotification], + mockAccounts, ); nativeNotification.onclick(null); expect(helpers.openInBrowser).toHaveBeenCalledTimes(1); expect(helpers.openInBrowser).toHaveBeenLastCalledWith( - mockedSingleNotification, - mockedAccounts, + mockSingleNotification, + mockAccounts, ); expect(ipcRenderer.send).toHaveBeenCalledWith('hide-window'); }); it('should click on a native notification (with more than 1 notification)', () => { const nativeNotification = notificationsHelpers.raiseNativeNotification( - mockedGitHubNotifications, - mockedAccounts, + mockGitHubNotifications, + mockAccounts, ); nativeNotification.onclick(null); @@ -145,7 +145,7 @@ describe('utils/notifications.ts', () => { describe('filterNotifications', () => { const mockNotifications = [ - partialMockedNotification({ + partialMockNotification({ title: 'User authored notification', user: { login: 'user', @@ -155,7 +155,7 @@ describe('utils/notifications.ts', () => { type: 'User', }, }), - partialMockedNotification({ + partialMockNotification({ title: 'Bot authored notification', user: { login: 'bot', @@ -169,7 +169,7 @@ describe('utils/notifications.ts', () => { it('should hide bot notifications when set to false', async () => { const result = filterNotifications(mockNotifications, { - ...mockedSettings, + ...mockSettings, showBots: false, }); @@ -179,7 +179,7 @@ describe('utils/notifications.ts', () => { it('should show bot notifications when set to true', async () => { const result = filterNotifications(mockNotifications, { - ...mockedSettings, + ...mockSettings, showBots: true, }); diff --git a/src/utils/remove-notification.test.ts b/src/utils/remove-notification.test.ts index 85b51b5ad..28789ac7f 100644 --- a/src/utils/remove-notification.test.ts +++ b/src/utils/remove-notification.test.ts @@ -1,20 +1,20 @@ -import { mockedSingleAccountNotifications } from '../__mocks__/notifications-mocks'; -import { mockedSettings } from '../__mocks__/state-mocks'; -import { mockedSingleNotification } from './api/__mocks__/response-mocks'; +import { mockSingleAccountNotifications } from '../__mocks__/notifications-mocks'; +import { mockSettings } from '../__mocks__/state-mocks'; +import { mockSingleNotification } from './api/__mocks__/response-mocks'; import Constants from './constants'; import { removeNotification } from './remove-notification'; describe('utils/remove-notification.ts', () => { - const notificationId = mockedSingleNotification.id; - const hostname = mockedSingleAccountNotifications[0].hostname; + const notificationId = mockSingleNotification.id; + const hostname = mockSingleAccountNotifications[0].hostname; it('should remove a notification if it exists', () => { - expect(mockedSingleAccountNotifications[0].notifications.length).toBe(1); + expect(mockSingleAccountNotifications[0].notifications.length).toBe(1); const result = removeNotification( - { ...mockedSettings, delayNotificationState: false }, + { ...mockSettings, delayNotificationState: false }, notificationId, - mockedSingleAccountNotifications, + mockSingleAccountNotifications, hostname, ); @@ -23,21 +23,21 @@ describe('utils/remove-notification.ts', () => { it('should set notification as opaque if delayNotificationState enabled', () => { const mockElement = document.createElement('div'); - mockElement.id = mockedSingleAccountNotifications[0].notifications[0].id; + mockElement.id = mockSingleAccountNotifications[0].notifications[0].id; jest.spyOn(document, 'getElementById').mockReturnValue(mockElement); - expect(mockedSingleAccountNotifications[0].notifications.length).toBe(1); + expect(mockSingleAccountNotifications[0].notifications.length).toBe(1); const result = removeNotification( - { ...mockedSettings, delayNotificationState: true }, + { ...mockSettings, delayNotificationState: true }, notificationId, - mockedSingleAccountNotifications, + mockSingleAccountNotifications, hostname, ); expect(result[0].notifications.length).toBe(1); expect(document.getElementById).toHaveBeenCalledWith( - mockedSingleAccountNotifications[0].notifications[0].id, + mockSingleAccountNotifications[0].notifications[0].id, ); expect(mockElement.className).toContain(Constants.READ_CLASS_NAME); }); diff --git a/src/utils/remove-notifications.test.ts b/src/utils/remove-notifications.test.ts index 70a6ec469..181a245f2 100644 --- a/src/utils/remove-notifications.test.ts +++ b/src/utils/remove-notifications.test.ts @@ -1,20 +1,20 @@ import { - mockedAccountNotifications, - mockedSingleAccountNotifications, + mockAccountNotifications, + mockSingleAccountNotifications, } from '../__mocks__/notifications-mocks'; -import { mockedSingleNotification } from './api/__mocks__/response-mocks'; +import { mockSingleNotification } from './api/__mocks__/response-mocks'; import { removeNotifications } from './remove-notifications'; describe('utils/remove-notifications.ts', () => { - const repoSlug = mockedSingleNotification.repository.full_name; - const hostname = mockedSingleAccountNotifications[0].hostname; + const repoSlug = mockSingleNotification.repository.full_name; + const hostname = mockSingleAccountNotifications[0].hostname; it("should remove a repo's notifications - single", () => { - expect(mockedSingleAccountNotifications[0].notifications.length).toBe(1); + expect(mockSingleAccountNotifications[0].notifications.length).toBe(1); const result = removeNotifications( repoSlug, - mockedSingleAccountNotifications, + mockSingleAccountNotifications, hostname, ); @@ -22,12 +22,12 @@ describe('utils/remove-notifications.ts', () => { }); it("should remove a repo's notifications - multiple", () => { - expect(mockedAccountNotifications[0].notifications.length).toBe(2); - expect(mockedAccountNotifications[1].notifications.length).toBe(2); + expect(mockAccountNotifications[0].notifications.length).toBe(2); + expect(mockAccountNotifications[1].notifications.length).toBe(2); const result = removeNotifications( repoSlug, - mockedAccountNotifications, + mockAccountNotifications, hostname, ); diff --git a/src/utils/storage.test.ts b/src/utils/storage.test.ts index 0670a0f30..37fdafc6a 100644 --- a/src/utils/storage.test.ts +++ b/src/utils/storage.test.ts @@ -1,4 +1,4 @@ -import { mockedSettings } from '../__mocks__/state-mocks'; +import { mockSettings } from '../__mocks__/state-mocks'; import { clearState, loadState, saveState } from './storage'; describe('utils/storage.ts', () => { @@ -31,7 +31,7 @@ describe('utils/storage.ts', () => { enterpriseAccounts: [], user: null, }, - mockedSettings, + mockSettings, ); expect(localStorage.setItem).toHaveBeenCalledTimes(1); }); diff --git a/src/utils/subject.test.ts b/src/utils/subject.test.ts index eb3733995..4864732d7 100644 --- a/src/utils/subject.test.ts +++ b/src/utils/subject.test.ts @@ -2,10 +2,10 @@ import axios from 'axios'; import nock from 'nock'; import { - partialMockedNotification, - partialMockedUser, + partialMockNotification, + partialMockUser, } from '../__mocks__/partial-mocks'; -import { mockedAccounts } from '../__mocks__/state-mocks'; +import { mockAccounts } from '../__mocks__/state-mocks'; import type { Discussion, DiscussionAuthor, @@ -20,8 +20,8 @@ import { getWorkflowRunAttributes, } from './subject'; -const mockAuthor = partialMockedUser('some-author'); -const mockCommenter = partialMockedUser('some-commenter'); +const mockAuthor = partialMockUser('some-author'); +const mockCommenter = partialMockUser('some-commenter'); const mockDiscussionAuthor: DiscussionAuthor = { login: 'discussion-author', url: 'https://github.com/discussion-author', @@ -39,14 +39,14 @@ describe('utils/subject.ts', () => { describe('getGitifySubjectDetails', () => { describe('CheckSuites - GitHub Actions', () => { it('cancelled check suite state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'Demo workflow run cancelled for main branch', type: 'CheckSuite', }); const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -56,14 +56,14 @@ describe('utils/subject.ts', () => { }); it('failed check suite state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'Demo workflow run failed for main branch', type: 'CheckSuite', }); const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -73,14 +73,14 @@ describe('utils/subject.ts', () => { }); it('multiple attempts failed check suite state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'Demo workflow run, Attempt #3 failed for main branch', type: 'CheckSuite', }); const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -90,14 +90,14 @@ describe('utils/subject.ts', () => { }); it('skipped check suite state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'Demo workflow run skipped for main branch', type: 'CheckSuite', }); const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -107,14 +107,14 @@ describe('utils/subject.ts', () => { }); it('successful check suite state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'Demo workflow run succeeded for main branch', type: 'CheckSuite', }); const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -124,28 +124,28 @@ describe('utils/subject.ts', () => { }); it('unknown check suite state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'Demo workflow run unknown-status for main branch', type: 'CheckSuite', }); const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toBeNull(); }); it('unhandled check suite title', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'A title that is not in the structure we expect', type: 'CheckSuite', }); const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toBeNull(); @@ -153,7 +153,7 @@ describe('utils/subject.ts', () => { }); describe('Commits', () => { it('get commit commenter', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'This is a commit with comments', type: 'Commit', url: 'https://api.github.com/repos/gitify-app/notifications-test/commits/d2a86d80e3d24ea9510d5de6c147e53c30f313a8', @@ -173,7 +173,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -188,7 +188,7 @@ describe('utils/subject.ts', () => { }); it('get commit without commenter', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'This is a commit with comments', type: 'Commit', url: 'https://api.github.com/repos/gitify-app/notifications-test/commits/d2a86d80e3d24ea9510d5de6c147e53c30f313a8', @@ -203,7 +203,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -223,8 +223,8 @@ describe('utils/subject.ts', () => { full_name: 'gitify-app/notifications-test', }; - const mockNotification = partialMockedNotification({ - title: 'This is a mocked discussion', + const mockNotification = partialMockNotification({ + title: 'This is a mock discussion', type: 'Discussion', }); mockNotification.updated_at = '2024-01-01T00:00:00Z'; @@ -245,7 +245,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -273,7 +273,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -301,7 +301,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -329,7 +329,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -357,7 +357,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -385,7 +385,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -404,8 +404,8 @@ describe('utils/subject.ts', () => { describe('Issues', () => { let mockNotification: Notification; beforeEach(() => { - mockNotification = partialMockedNotification({ - title: 'This is a mocked issue', + mockNotification = partialMockNotification({ + title: 'This is a mock issue', type: 'Issue', url: 'https://api.github.com/repos/gitify-app/notifications-test/issues/1', latest_comment_url: @@ -424,7 +424,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -449,7 +449,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -478,7 +478,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -507,7 +507,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -536,7 +536,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -564,7 +564,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -583,8 +583,8 @@ describe('utils/subject.ts', () => { let mockNotification: Notification; beforeEach(() => { - mockNotification = partialMockedNotification({ - title: 'This is a mocked pull request', + mockNotification = partialMockNotification({ + title: 'This is a mock pull request', type: 'PullRequest', url: 'https://api.github.com/repos/gitify-app/notifications-test/pulls/1', latest_comment_url: @@ -612,7 +612,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -647,7 +647,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -682,7 +682,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -717,7 +717,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -751,7 +751,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -784,7 +784,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -832,7 +832,7 @@ describe('utils/subject.ts', () => { const result = await getLatestReviewForReviewers( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual([ @@ -848,7 +848,7 @@ describe('utils/subject.ts', () => { const result = await getLatestReviewForReviewers( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toBeNull(); @@ -859,7 +859,7 @@ describe('utils/subject.ts', () => { const result = await getLatestReviewForReviewers( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toBeNull(); @@ -869,8 +869,8 @@ describe('utils/subject.ts', () => { describe('Releases', () => { it('release notification', async () => { - const mockNotification = partialMockedNotification({ - title: 'This is a mocked release', + const mockNotification = partialMockNotification({ + title: 'This is a mock release', type: 'Release', url: 'https://api.github.com/repos/gitify-app/notifications-test/releases/1', latest_comment_url: @@ -883,7 +883,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -900,14 +900,14 @@ describe('utils/subject.ts', () => { describe('WorkflowRuns - GitHub Actions', () => { it('deploy review workflow run state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'some-user requested your review to deploy to an environment', type: 'WorkflowRun', }); const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toEqual({ @@ -917,7 +917,7 @@ describe('utils/subject.ts', () => { }); it('unknown workflow run state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'some-user requested your unknown-state to deploy to an environment', type: 'WorkflowRun', @@ -925,21 +925,21 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toBeNull(); }); it('unhandled workflow run title', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'unhandled workflow run structure', type: 'WorkflowRun', }); const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toBeNull(); @@ -948,7 +948,7 @@ describe('utils/subject.ts', () => { describe('Default', () => { it('unhandled subject details', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'There is no special subject handling for this notification type', type: 'RepositoryInvitation', @@ -956,7 +956,7 @@ describe('utils/subject.ts', () => { const result = await getGitifySubjectDetails( mockNotification, - mockedAccounts.token, + mockAccounts.token, ); expect(result).toBeNull(); @@ -970,7 +970,7 @@ describe('utils/subject.ts', () => { .mockImplementation(); const mockError = new Error('Test error'); - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'This issue will throw an error', type: 'Issue', url: 'https://api.github.com/repos/gitify-app/notifications-test/issues/1', @@ -980,7 +980,7 @@ describe('utils/subject.ts', () => { .get('/repos/gitify-app/notifications-test/issues/1') .replyWithError(mockError); - await getGitifySubjectDetails(mockNotification, mockedAccounts.token); + await getGitifySubjectDetails(mockNotification, mockAccounts.token); expect(consoleErrorSpy).toHaveBeenCalledWith( 'Error occurred while fetching details for Issue notification: This issue will throw an error', @@ -992,7 +992,7 @@ describe('utils/subject.ts', () => { describe('getCheckSuiteState', () => { it('cancelled check suite state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'Demo workflow run cancelled for feature/foo branch', type: 'CheckSuite', }); @@ -1009,7 +1009,7 @@ describe('utils/subject.ts', () => { }); it('failed check suite state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'Demo workflow run failed for main branch', type: 'CheckSuite', }); @@ -1026,7 +1026,7 @@ describe('utils/subject.ts', () => { }); it('multiple attempts failed check suite state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'Demo workflow run, Attempt #3 failed for main branch', type: 'CheckSuite', }); @@ -1043,7 +1043,7 @@ describe('utils/subject.ts', () => { }); it('skipped check suite state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'Demo workflow run skipped for main branch', type: 'CheckSuite', }); @@ -1060,7 +1060,7 @@ describe('utils/subject.ts', () => { }); it('successful check suite state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'Demo workflow run succeeded for main branch', type: 'CheckSuite', }); @@ -1077,7 +1077,7 @@ describe('utils/subject.ts', () => { }); it('unknown check suite state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'Demo workflow run unknown-status for main branch', type: 'CheckSuite', }); @@ -1094,7 +1094,7 @@ describe('utils/subject.ts', () => { }); it('unhandled check suite title', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'A title that is not in the structure we expect', type: 'CheckSuite', }); @@ -1107,7 +1107,7 @@ describe('utils/subject.ts', () => { describe('getWorkflowRunState', () => { it('deploy review workflow run state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'some-user requested your review to deploy to an environment', type: 'WorkflowRun', }); @@ -1122,7 +1122,7 @@ describe('utils/subject.ts', () => { }); it('unknown workflow run state', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'some-user requested your unknown-state to deploy to an environment', type: 'WorkflowRun', @@ -1138,7 +1138,7 @@ describe('utils/subject.ts', () => { }); it('unhandled workflow run title', async () => { - const mockNotification = partialMockedNotification({ + const mockNotification = partialMockNotification({ title: 'unhandled workflow run structure', type: 'WorkflowRun', }); @@ -1155,7 +1155,7 @@ function mockDiscussionNode( isAnswered: boolean, ): Discussion { return { - title: 'This is a mocked discussion', + title: 'This is a mock discussion', url: 'https://github.com/gitify-app/notifications-test/discussions/1', stateReason: state, isAnswered: isAnswered,