-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathaction-input.test.ts
More file actions
88 lines (72 loc) · 2.89 KB
/
action-input.test.ts
File metadata and controls
88 lines (72 loc) · 2.89 KB
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
81
82
83
84
85
86
87
88
import {StringToken} from "@actions/workflow-parser/templates/tokens/string-token";
import {Octokit} from "@octokit/rest";
import fetchMock from "fetch-mock";
import {actionsCheckoutMetadata} from "../test-utils/action-metadata.js";
import {createWorkflowContext} from "../test-utils/workflow-context.js";
import {TTLCache} from "../utils/cache.js";
import {getActionInputDescription} from "./action-input.js";
const workflow = `
name: Hello World
on: workflow_dispatch
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
`;
async function getDescription(input: string, mock: fetchMock.FetchMockSandbox) {
const workflowContext = await createWorkflowContext(workflow, "build", 0);
return await getActionInputDescription(
new Octokit({
request: {
fetch: mock
}
}),
new TTLCache(),
workflowContext.step!, // eslint-disable-line @typescript-eslint/no-non-null-assertion
new StringToken(undefined, undefined, input, undefined)
);
}
describe("action input descriptions", () => {
it("optional input", async () => {
const mock = fetchMock
.sandbox()
.getOnce("https://api.github.com/repos/actions/checkout/contents/action.yml?ref=v3", actionsCheckoutMetadata);
expect(await getDescription("repository", mock)).toEqual(
"Repository name with owner. For example, actions/checkout"
);
});
it("required input", async () => {
const mock = fetchMock
.sandbox()
.getOnce("https://api.github.com/repos/actions/checkout/contents/action.yml?ref=v3", actionsCheckoutMetadata);
expect(await getDescription("ref", mock)).toEqual("The branch, tag or SHA to checkout.\n\n**Required**");
});
it("deprecated input", async () => {
const mock = fetchMock
.sandbox()
.getOnce("https://api.github.com/repos/actions/checkout/contents/action.yml?ref=v3", actionsCheckoutMetadata);
expect(await getDescription("repo", mock)).toEqual(
"Repository name with owner. For example, actions/checkout\n\n**Deprecated**"
);
});
it("invalid input", async () => {
const mock = fetchMock
.sandbox()
.getOnce("https://api.github.com/repos/actions/checkout/contents/action.yml?ref=v3", actionsCheckoutMetadata);
expect(await getDescription("typo", mock)).toBeUndefined();
});
it("action does not exist", async () => {
const mock = fetchMock
.sandbox()
.getOnce("https://api.github.com/repos/actions/checkout/contents/action.yml?ref=v3", 404)
.getOnce("https://api.github.com/repos/actions/checkout/contents/action.yaml?ref=v3", 404);
expect(await getDescription("repository", mock)).toBeUndefined();
});
it("invalid permissions", async () => {
const mock = fetchMock
.sandbox()
.getOnce("https://api.github.com/repos/actions/checkout/contents/action.yml?ref=v3", 403);
expect(await getDescription("repository", mock)).toBeUndefined();
});
});