-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.test.ts
68 lines (62 loc) · 1.91 KB
/
sample.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import fs from "node:fs";
import { expect, test } from "@jest/globals";
import {
compileRuleFn,
patchFromGitHubPullRequest,
RuleFnSourceLang,
RuleLogMode,
runRule,
emptyChangeSetMetadata,
} from "@fensak-io/reng";
import type { Repository } from "@fensak-io/reng";
import { Octokit } from "@octokit/rest";
const ruleFnSrc = fs.readFileSync(`${__dirname}/sample.ts`, "utf8");
const ruleFn = compileRuleFn(ruleFnSrc, RuleFnSourceLang.Typescript);
const octokit = new Octokit({
auth: process.env.GITHUB_API_TOKEN,
});
const testRepo: Repository = {
owner: "fensak-io",
name: "dotfensak-deno-template",
};
const opts = { logMode: RuleLogMode.Console };
test("No changes should be approved", async () => {
const result = await runRule(ruleFn, [], emptyChangeSetMetadata, opts);
expect(result.approve).toBe(true);
});
test("Changes only to README should be approved", async () => {
// View PR at
// https://github.com/fensak-io/dotfensak-deno-template/pull/1
const patches = await patchFromGitHubPullRequest(octokit, testRepo, 1);
const result = await runRule(
ruleFn,
patches.patchList,
patches.metadata,
opts,
);
expect(result.approve).toBe(true);
});
test("Changes to non-README files should be rejected", async () => {
// View PR at
// https://github.com/fensak-io/dotfensak-deno-template/pull/2
const patches = await patchFromGitHubPullRequest(octokit, testRepo, 2);
const result = await runRule(
ruleFn,
patches.patchList,
patches.metadata,
opts,
);
expect(result.approve).toBe(false);
});
test("Change containing more than one file should be rejected", async () => {
// View PR at
// https://github.com/fensak-io/dotfensak-deno-template/pull/4
const patches = await patchFromGitHubPullRequest(octokit, testRepo, 4);
const result = await runRule(
ruleFn,
patches.patchList,
patches.metadata,
opts,
);
expect(result.approve).toBe(false);
});