Skip to content

Commit 87470d5

Browse files
committed
further type refactoring
Signed-off-by: Adam Setch <[email protected]>
1 parent cd64fe0 commit 87470d5

File tree

10 files changed

+39
-28
lines changed

10 files changed

+39
-28
lines changed

src/renderer/__mocks__/user-mocks.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ export function createPartialMockUser(login: string): RawUser {
1919
return mockUser as RawUser;
2020
}
2121

22-
export function createMockAuthorFragment(
22+
export function createMockNotificationUser(
2323
login: string,
2424
): GitifyNotificationUser {
2525
return {
26-
__typename: 'User',
2726
login: login,
28-
htmlUrl: `https://github.com/${login}`,
29-
avatarUrl: 'https://avatars.githubusercontent.com/u/583231?v=4',
27+
htmlUrl: `https://github.com/${login}` as Link,
28+
avatarUrl: 'https://avatars.githubusercontent.com/u/583231?v=4' as Link,
3029
type: 'User',
3130
};
3231
}

src/renderer/components/notifications/NotificationFooter.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import userEvent from '@testing-library/user-event';
33

44
import { renderWithAppContext } from '../../__helpers__/test-utils';
55
import { mockGitHubCloudAccount } from '../../__mocks__/account-mocks';
6-
import type { Link, UserType } from '../../types';
6+
import type { GitifyNotificationUser, Link } from '../../types';
77
import { mockSingleNotification } from '../../utils/api/__mocks__/response-mocks';
88
import * as comms from '../../utils/comms';
99
import { NotificationFooter } from './NotificationFooter';
@@ -83,7 +83,7 @@ describe('renderer/components/notifications/NotificationFooter.tsx', () => {
8383
htmlUrl: 'https://github.com/some-user' as Link,
8484
avatarUrl:
8585
'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
86-
type: 'User' as UserType,
86+
type: 'User' as GitifyNotificationUser['type'],
8787
},
8888
reviews: null,
8989
},

src/renderer/types.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { FC } from 'react';
33
import type { OcticonProps } from '@primer/octicons-react';
44

55
import type {
6-
AuthorFieldsFragment,
76
DiscussionStateReason,
87
IssueState,
98
IssueStateReason,
@@ -349,7 +348,19 @@ export interface GitifyOwner {
349348
type: UserType;
350349
}
351350

352-
export type GitifyNotificationUser = AuthorFieldsFragment;
351+
/**
352+
* Minimal notification user information.
353+
*/
354+
export interface GitifyNotificationUser {
355+
/** Notification user login name */
356+
login: string;
357+
/** Notification user avatar URL */
358+
avatarUrl: Link;
359+
/** Notification user html URL */
360+
htmlUrl: Link;
361+
/** Notification user type (User, Organization, Bot, etc.) */
362+
type: UserType;
363+
}
353364

354365
export type GitifyMilestone = MilestoneFieldsFragment;
355366

src/renderer/utils/links.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mockGitHubCloudAccount } from '../__mocks__/account-mocks';
2-
import { createMockAuthorFragment } from '../__mocks__/user-mocks';
2+
import { createMockNotificationUser } from '../__mocks__/user-mocks';
33
import { Constants } from '../constants';
44
import type {
55
GitifyNotificationUser,
@@ -75,7 +75,7 @@ describe('renderer/utils/links.ts', () => {
7575
});
7676

7777
it('openUserProfile', () => {
78-
const mockUser = createMockAuthorFragment(
78+
const mockUser = createMockNotificationUser(
7979
'mock-user',
8080
) as GitifyNotificationUser;
8181

src/renderer/utils/notifications/handlers/commit.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
GitifyNotificationState,
99
GitifyNotificationUser,
1010
GitifySubject,
11+
Link,
1112
SettingsState,
1213
} from '../../../types';
1314
import { getCommit, getCommitComment } from '../../api/client';
@@ -41,8 +42,8 @@ class CommitHandler extends DefaultHandler {
4142

4243
user = {
4344
login: commitComment.user.login,
44-
avatarUrl: commitComment.user.avatar_url,
45-
htmlUrl: commitComment.user.html_url,
45+
avatarUrl: commitComment.user.avatar_url as Link,
46+
htmlUrl: commitComment.user.html_url as Link,
4647
type: commitComment.user.type as GitifyNotificationUser['type'],
4748
};
4849
} else {
@@ -52,8 +53,8 @@ class CommitHandler extends DefaultHandler {
5253

5354
user = {
5455
login: commit.author.login,
55-
avatarUrl: commit.author.avatar_url,
56-
htmlUrl: commit.author.html_url,
56+
avatarUrl: commit.author.avatar_url as Link,
57+
htmlUrl: commit.author.html_url as Link,
5758
type: commit.author.type as GitifyNotificationUser['type'],
5859
};
5960
}

src/renderer/utils/notifications/handlers/discussion.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
createPartialMockNotification,
77
} from '../../../__mocks__/notifications-mocks';
88
import { mockSettings } from '../../../__mocks__/state-mocks';
9-
import { createMockAuthorFragment } from '../../../__mocks__/user-mocks';
9+
import { createMockNotificationUser } from '../../../__mocks__/user-mocks';
1010
import type { GitifyNotification } from '../../../types';
1111
import {
1212
type GitifyDiscussionState,
@@ -20,9 +20,9 @@ import type {
2020
} from '../../api/graphql/generated/graphql';
2121
import { discussionHandler } from './discussion';
2222

23-
const mockAuthor = createMockAuthorFragment('discussion-author');
24-
const mockCommenter = createMockAuthorFragment('discussion-commenter');
25-
const mockReplier = createMockAuthorFragment('discussion-replier');
23+
const mockAuthor = createMockNotificationUser('discussion-author');
24+
const mockCommenter = createMockNotificationUser('discussion-commenter');
25+
const mockReplier = createMockNotificationUser('discussion-replier');
2626

2727
describe('renderer/utils/notifications/handlers/discussion.ts', () => {
2828
describe('enrich', () => {

src/renderer/utils/notifications/handlers/issue.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
createPartialMockNotification,
77
} from '../../../__mocks__/notifications-mocks';
88
import { mockSettings } from '../../../__mocks__/state-mocks';
9-
import { createMockAuthorFragment } from '../../../__mocks__/user-mocks';
9+
import { createMockNotificationUser } from '../../../__mocks__/user-mocks';
1010
import type { GitifyNotification } from '../../../types';
1111
import {
1212
type GitifyIssueState,
@@ -21,8 +21,8 @@ import type {
2121
} from '../../api/graphql/generated/graphql';
2222
import { issueHandler } from './issue';
2323

24-
const mockAuthor = createMockAuthorFragment('issue-author');
25-
const mockCommenter = createMockAuthorFragment('issue-commenter');
24+
const mockAuthor = createMockNotificationUser('issue-author');
25+
const mockCommenter = createMockNotificationUser('issue-commenter');
2626

2727
describe('renderer/utils/notifications/handlers/issue.ts', () => {
2828
describe('enrich', () => {

src/renderer/utils/notifications/handlers/pullRequest.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
createPartialMockNotification,
77
} from '../../../__mocks__/notifications-mocks';
88
import { mockSettings } from '../../../__mocks__/state-mocks';
9-
import { createMockAuthorFragment } from '../../../__mocks__/user-mocks';
9+
import { createMockNotificationUser } from '../../../__mocks__/user-mocks';
1010
import type { GitifyNotification } from '../../../types';
1111
import {
1212
type GitifyPullRequestState,
@@ -21,8 +21,8 @@ import type {
2121
} from '../../api/graphql/generated/graphql';
2222
import { getLatestReviewForReviewers, pullRequestHandler } from './pullRequest';
2323

24-
const mockAuthor = createMockAuthorFragment('some-author');
25-
const mockCommenter = createMockAuthorFragment('some-commenter');
24+
const mockAuthor = createMockNotificationUser('some-author');
25+
const mockCommenter = createMockNotificationUser('some-commenter');
2626

2727
describe('renderer/utils/notifications/handlers/pullRequest.ts', () => {
2828
let mockNotification: GitifyNotification;

src/renderer/utils/notifications/handlers/release.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class ReleaseHandler extends DefaultHandler {
3737
const user: GitifyNotificationUser = release.author
3838
? {
3939
login: release.author.login,
40-
avatarUrl: release.author.avatar_url,
41-
htmlUrl: release.author.html_url,
40+
avatarUrl: release.author.avatar_url as Link,
41+
htmlUrl: release.author.html_url as Link,
4242
type: release.author.type as GitifyNotificationUser['type'],
4343
}
4444
: null;

src/renderer/utils/notifications/handlers/utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { createMockAuthorFragment } from '../../../__mocks__/user-mocks';
1+
import { createMockNotificationUser } from '../../../__mocks__/user-mocks';
22
import { formatForDisplay, getNotificationAuthor } from './utils';
33

44
describe('renderer/utils/notifications/handlers/utils.ts', () => {
55
describe('getNotificationAuthor', () => {
6-
const mockAuthor = createMockAuthorFragment('some-author');
6+
const mockAuthor = createMockNotificationUser('some-author');
77

88
it('returns null when all users are null', () => {
99
const result = getNotificationAuthor([null, null]);

0 commit comments

Comments
 (0)