Skip to content

Commit

Permalink
feat: add util to check whether type is valid GitHub alert type
Browse files Browse the repository at this point in the history
  • Loading branch information
jobveldhuis committed Apr 11, 2024
1 parent 7be2e5b commit de20d72
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/is-github-alert-type.test.ts
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);
});
})
5 changes: 5 additions & 0 deletions src/is-github-alert-type.ts
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);
}

0 comments on commit de20d72

Please sign in to comment.