generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.test.js
80 lines (58 loc) · 2.24 KB
/
index.test.js
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
70
71
72
73
74
75
76
77
78
79
80
/*global test*/
const assert = require("assert");
const {
getUsersToNotifyForLabel,
getCommentLabels,
makeMessage,
} = require("./subscribe-to-label");
test("test getUsersToNotifyForLabel", () => {
const config = {
fitzgen: ["fuzzing"],
bob: ["wasmtime", "fuzzing"],
};
const fuzzingUsers = getUsersToNotifyForLabel(config, "fuzzing");
assert.deepEqual(fuzzingUsers, ["fitzgen", "bob"]);
const wasmtimeUsers = getUsersToNotifyForLabel(config, "wasmtime");
assert.deepEqual(wasmtimeUsers, ["bob"]);
const zzzUsers = getUsersToNotifyForLabel(config, "zzz");
assert.deepEqual(zzzUsers, []);
});
test("test makeMessage", () => {
const expected = `
#### Subscribe to Label Action
cc @bnjbvr, @fitzgen
<details>
This issue or pull request has been labeled: "awesome", "cranelift", "fuzzing"
Thus the following users have been cc'd because of the following labels:
* bnjbvr: cranelift, fuzzing
* fitzgen: fuzzing
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
[Learn more.](https://github.com/bytecodealliance/subscribe-to-label-action)
</details>
`.trim();
let userToLabel = new Map();
userToLabel.set("bnjbvr", ["fuzzing", "cranelift"]);
userToLabel.set("fitzgen", ["fuzzing"]);
let labels = ["fuzzing", "awesome", "cranelift"];
let configPath = ".github/subscribe-to-label.json";
const observed = makeMessage(userToLabel, labels, configPath);
assert.equal(expected, observed);
});
test("test getCommentLabels", () => {
let userToLabel = new Map();
userToLabel.set("fitzgen", ["fuzzing"]);
let providedLabels = ["fuzzing", "cranelift"];
let configPath = ".github/subscribe-to-label.json";
const comment = makeMessage(userToLabel, providedLabels, configPath);
const labels = getCommentLabels(comment);
assert.deepEqual(labels, ["fuzzing", "cranelift"].sort());
});
test("test getCommentLabels with single label", () => {
let userToLabel = new Map();
userToLabel.set("fitzgen", ["fuzzing"]);
let providedLabels = ["fuzzing"];
let configPath = ".github/subscribe-to-label.json";
const comment = makeMessage(userToLabel, providedLabels, configPath);
const labels = getCommentLabels(comment);
assert.deepEqual(labels, ["fuzzing"]);
});