-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract feature based utils (#1672)
Signed-off-by: Adam Setch <adam.setch@outlook.com>
- Loading branch information
Showing
8 changed files
with
147 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { | ||
mockGitHubCloudAccount, | ||
mockGitHubEnterpriseServerAccount, | ||
} from '../__mocks__/state-mocks'; | ||
|
||
import { | ||
isAnsweredDiscussionFeatureSupported, | ||
isMarkAsDoneFeatureSupported, | ||
} from './features'; | ||
|
||
describe('renderer/utils/features.ts', () => { | ||
describe('isMarkAsDoneFeatureSupported', () => { | ||
it('should return true for GitHub Cloud', () => { | ||
expect(isMarkAsDoneFeatureSupported(mockGitHubCloudAccount)).toBe(true); | ||
}); | ||
|
||
it('should return false for GitHub Enterprise Server < v3.13', () => { | ||
const account = { | ||
...mockGitHubEnterpriseServerAccount, | ||
version: '3.12.0', | ||
}; | ||
|
||
expect(isMarkAsDoneFeatureSupported(account)).toBe(false); | ||
}); | ||
|
||
it('should return true for GitHub Enterprise Server >= v3.13', () => { | ||
const account = { | ||
...mockGitHubEnterpriseServerAccount, | ||
version: '3.13.3', | ||
}; | ||
|
||
expect(isMarkAsDoneFeatureSupported(account)).toBe(true); | ||
}); | ||
|
||
it('should return false for GitHub Enterprise Server when partial version available', () => { | ||
const account = { | ||
...mockGitHubEnterpriseServerAccount, | ||
version: '3', | ||
}; | ||
|
||
expect(isMarkAsDoneFeatureSupported(account)).toBe(false); | ||
}); | ||
|
||
it('should return false for GitHub Enterprise Server when no version available', () => { | ||
const account = { | ||
...mockGitHubEnterpriseServerAccount, | ||
version: null, | ||
}; | ||
|
||
expect(isMarkAsDoneFeatureSupported(account)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isAnsweredDiscussionFeatureSupported', () => { | ||
it('should return true for GitHub Cloud', () => { | ||
expect(isAnsweredDiscussionFeatureSupported(mockGitHubCloudAccount)).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
it('should return false for GitHub Enterprise Server < v3.12', () => { | ||
const account = { | ||
...mockGitHubEnterpriseServerAccount, | ||
version: '3.11.0', | ||
}; | ||
|
||
expect(isAnsweredDiscussionFeatureSupported(account)).toBe(false); | ||
}); | ||
|
||
it('should return true for GitHub Enterprise Server >= v3.12', () => { | ||
const account = { | ||
...mockGitHubEnterpriseServerAccount, | ||
version: '3.12.3', | ||
}; | ||
|
||
expect(isAnsweredDiscussionFeatureSupported(account)).toBe(true); | ||
}); | ||
|
||
it('should return false for GitHub Enterprise Server when partial version available', () => { | ||
const account = { | ||
...mockGitHubEnterpriseServerAccount, | ||
version: '3', | ||
}; | ||
|
||
expect(isAnsweredDiscussionFeatureSupported(account)).toBe(false); | ||
}); | ||
|
||
it('should return false for GitHub Enterprise Server when no version available', () => { | ||
const account = { | ||
...mockGitHubEnterpriseServerAccount, | ||
version: null, | ||
}; | ||
|
||
expect(isMarkAsDoneFeatureSupported(account)).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { Account } from '../types'; | ||
import { isEnterpriseServerHost } from './helpers'; | ||
|
||
/** | ||
* Check if the "Mark as done" feature is supported for the given account. | ||
* | ||
* GitHub Cloud or GitHub Enterprise Server 3.13 or newer is required to support this feature. | ||
*/ | ||
|
||
export function isMarkAsDoneFeatureSupported(account: Account): boolean { | ||
if (isEnterpriseServerHost(account.hostname)) { | ||
if (account.version) { | ||
const version = account?.version.split('.').map(Number); | ||
return version[0] >= 3 && version[1] >= 13; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
/** | ||
* Check if the "answered" discussions are supported for the given account. | ||
* | ||
* GitHub Cloud or GitHub Enterprise Server 3.12 or newer is required to support this feature. | ||
*/ | ||
|
||
export function isAnsweredDiscussionFeatureSupported( | ||
account: Account, | ||
): boolean { | ||
if (isEnterpriseServerHost(account.hostname)) { | ||
if (account.version) { | ||
const version = account?.version.split('.').map(Number); | ||
return version[0] >= 3 && version[1] >= 12; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters