Skip to content

Commit

Permalink
refactor: rename isEnterpriseHost helper (#1413)
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy authored Jul 26, 2024
1 parent 5ee1586 commit e61abc0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/utils/api/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Hostname } from '../../types';
import Constants from '../constants';
import { isEnterpriseHost } from '../helpers';
import { isEnterpriseServerHost } from '../helpers';

export function getGitHubAPIBaseUrl(hostname: Hostname): URL {
const url = new URL(Constants.GITHUB_API_BASE_URL);

if (isEnterpriseHost(hostname)) {
if (isEnterpriseServerHost(hostname)) {
url.hostname = hostname;
url.pathname = '/api/v3/';
}
Expand All @@ -15,7 +15,7 @@ export function getGitHubAPIBaseUrl(hostname: Hostname): URL {
export function getGitHubGraphQLUrl(hostname: Hostname): URL {
const url = new URL(Constants.GITHUB_API_GRAPHQL_URL);

if (isEnterpriseHost(hostname)) {
if (isEnterpriseServerHost(hostname)) {
url.hostname = hostname;
url.pathname = '/api/graphql';
}
Expand Down
16 changes: 10 additions & 6 deletions src/utils/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
generateNotificationReferrerId,
getFilterCount,
getPlatformFromHostname,
isEnterpriseHost,
isEnterpriseServerHost,
} from './helpers';

describe('utils/helpers.ts', () => {
Expand All @@ -40,15 +40,19 @@ describe('utils/helpers.ts', () => {
});
});

describe('isEnterpriseHost', () => {
describe('isEnterpriseServerHost', () => {
it('should return true for enterprise host', () => {
expect(isEnterpriseHost('github.gitify.app' as Hostname)).toBe(true);
expect(isEnterpriseHost('api.github.gitify.app' as Hostname)).toBe(true);
expect(isEnterpriseServerHost('github.gitify.app' as Hostname)).toBe(
true,
);
expect(isEnterpriseServerHost('api.github.gitify.app' as Hostname)).toBe(
true,
);
});

it('should return false for non-enterprise host', () => {
expect(isEnterpriseHost('github.com' as Hostname)).toBe(false);
expect(isEnterpriseHost('api.github.com' as Hostname)).toBe(false);
expect(isEnterpriseServerHost('github.com' as Hostname)).toBe(false);
expect(isEnterpriseServerHost('api.github.com' as Hostname)).toBe(false);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function getPlatformFromHostname(hostname: string): PlatformType {
: 'GitHub Enterprise Server';
}

export function isEnterpriseHost(hostname: Hostname): boolean {
export function isEnterpriseServerHost(hostname: Hostname): boolean {
return !hostname.endsWith(Constants.DEFAULT_AUTH_OPTIONS.hostname);
}

Expand Down

0 comments on commit e61abc0

Please sign in to comment.