-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add util to check whether type is valid GitHub alert type
- Loading branch information
1 parent
7be2e5b
commit de20d72
Showing
2 changed files
with
34 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import {isGithubAlertType} from "./is-github-alert-type.js"; | ||
import {GithubAlertType} from "./github-alert.type.js"; | ||
|
||
describe('is-github-alert-type', () => { | ||
it('should return false for an undefined value', () => { | ||
expect(isGithubAlertType(undefined)).toEqual(false); | ||
}); | ||
|
||
it('should return false for a null value', () => { | ||
expect(isGithubAlertType(null)).toEqual(false); | ||
}); | ||
|
||
it('should return false for a string value not equal to a GitHub alert type', () => { | ||
expect(isGithubAlertType("test")).toEqual(false); | ||
}); | ||
|
||
it('should return true for a value directly taken from the GitHub alert type enum', () => { | ||
expect(isGithubAlertType(GithubAlertType.WARNING)).toEqual(true); | ||
}); | ||
|
||
it('should return true for a string value that equals an alert type', () => { | ||
expect(isGithubAlertType("IMPORTANT")).toEqual(true); | ||
}); | ||
|
||
it('should return false for a string value with the wrong capitalization', () => { | ||
expect(isGithubAlertType("important")).toEqual(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,5 @@ | ||
import {GITHUB_ALERT_TYPES, type GithubAlertType} from "./github-alert.type.js"; | ||
|
||
export function isGithubAlertType(type: unknown): type is GithubAlertType { | ||
return GITHUB_ALERT_TYPES.includes(type as GithubAlertType); | ||
} |