-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample_test.ts
69 lines (64 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
69
import { assert } from "https://deno.land/[email protected]/testing/asserts.ts";
import {
compileRuleFn,
emptyChangeSetMetadata,
patchFromGitHubPullRequest,
Repository,
RuleFnSourceLang,
RuleLogMode,
runRule,
} from "npm:@fensak-io/reng@^2.0.0";
import { Octokit } from "npm:@octokit/rest@^20.0.0";
const __dirname = new URL(".", import.meta.url).pathname;
const ruleFn = compileRuleFn(
await Deno.readTextFile(`${__dirname}/sample.ts`),
RuleFnSourceLang.Typescript,
);
const octokit = new Octokit({
auth: Deno.env.get("GITHUB_API_TOKEN"),
});
const testRepo: Repository = {
owner: "fensak-io",
name: "dotfensak-deno-template",
};
const opts = { logMode: RuleLogMode.Console };
Deno.test("No changes should be approved", async () => {
const result = await runRule(ruleFn, [], emptyChangeSetMetadata, opts);
assert(result.approve);
});
Deno.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,
);
assert(result.approve);
});
Deno.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,
);
assert(!result.approve);
});
Deno.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,
);
assert(!result.approve);
});