Merge branch '15814-wb2-secrets' refs #15814
[arvados.git] / services / workbench2 / src / store / run-process-panel / run-process-panel-actions.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { runProcess } from "./run-process-panel-actions";
6
7 jest.mock("../navigation/navigation-action", () => ({
8     navigateTo: (link: any) => link,
9 }));
10
11 jest.mock("models/process", () => ({
12     createWorkflowMounts: jest.fn(),
13     createWorkflowSecretMounts: jest.fn(),
14 }));
15
16 jest.mock("redux-form", () => ({
17     reduxForm: () => (c: any) => c,
18     getFormValues: (name: string) => () => {
19         switch (name) {
20             case "runProcessBasicForm":
21                 return {
22                     name: "basicFormTestName",
23                     description: "basicFormTestDescription",
24                 };
25             case "runProcessInputsForm":
26                 return {};
27             default:
28                 return null;
29         }
30     },
31 }));
32
33 describe("run-process-panel-actions", () => {
34     describe("runProcess", () => {
35         const newProcessUUID = 'newProcessUUID';
36         let dispatch: any, getState: any, services: any;
37
38         beforeEach(() => {
39             dispatch = jest.fn();
40             services = {
41                 containerRequestService: {
42                     create: jest.fn().mockImplementation(async () => ({
43                         uuid: newProcessUUID,
44                     })),
45                 },
46             };
47         });
48
49         it("should return when userUuid is null", async () => {
50             // given
51             getState = () => ({
52                 auth: {},
53             });
54
55             // when
56             await runProcess(dispatch, getState, services);
57
58             // then
59             expect(dispatch).not.toHaveBeenCalled();
60         });
61
62         it("should run workflow with project-uuid", async () => {
63             // given
64             getState = () => ({
65                 auth: {
66                     user: {
67                         email: "test@gmail.com",
68                         firstName: "TestFirstName",
69                         lastName: "TestLastName",
70                         uuid: "zzzzz-tpzed-yid70bw31f51234",
71                         ownerUuid: "zzzzz-tpzed-000000000000000",
72                         isAdmin: false,
73                         isActive: true,
74                         username: "testfirstname",
75                         prefs: {
76                             profile: {},
77                         },
78                     },
79                 },
80                 runProcessPanel: {
81                     processPathname: "/projects/zzzzz-tpzed-yid70bw31f51234",
82                     processOwnerUuid: "zzzzz-tpzed-yid70bw31f51234",
83                     selectedWorkflow: {
84                         href: "/workflows/zzzzz-7fd4e-2tlnerdkxnl4fjt",
85                         kind: "arvados#workflow",
86                         etag: "8gh5xlhlgo61yqscyl1spw8tc",
87                         uuid: "zzzzz-7fd4e-2tlnerdkxnl4fjt",
88                         ownerUuid: "zzzzz-tpzed-o4njwilpp4ov321",
89                         createdAt: "2020-07-15T19:40:50.296041000Z",
90                         modifiedByClientUuid: "zzzzz-ozdt8-libnr89sc5nq111",
91                         modifiedByUserUuid: "zzzzz-tpzed-o4njwilpp4ov321",
92                         modifiedAt: "2020-07-15T19:40:50.296376000Z",
93                         name: "revsort.cwl",
94                         description:
95                             "Reverse the lines in a document, then sort those lines.",
96                         definition:
97                             '{\n    "$graph": [\n        {\n            "class": "Workflow",\n            "doc": "Reverse the lines in a document, then sort those lines.",\n            "id": "#main",\n            "hints":[{"class":"http://arvados.org/cwl#WorkflowRunnerResources","acrContainerImage":"arvados/jobs:2.0.4", "ramMin": 16000}], "inputs": [\n                {\n                    "default": null,\n                    "doc": "The input file to be processed.",\n                    "id": "#main/input",\n                    "type": "File"\n                },\n                {\n                    "default": true,\n                    "doc": "If true, reverse (decending) sort",\n                    "id": "#main/reverse_sort",\n                    "type": "boolean"\n                }\n            ],\n            "outputs": [\n                {\n                    "doc": "The output with the lines reversed and sorted.",\n                    "id": "#main/output",\n                    "outputSource": "#main/sorted/output",\n                    "type": "File"\n                }\n            ],\n            "steps": [\n                {\n                    "id": "#main/rev",\n                    "in": [\n                        {\n                            "id": "#main/rev/input",\n                            "source": "#main/input"\n                        }\n                    ],\n                    "out": [\n                        "#main/rev/output"\n                    ],\n                    "run": "#revtool.cwl"\n                },\n                {\n                    "id": "#main/sorted",\n                    "in": [\n                        {\n                            "id": "#main/sorted/input",\n                            "source": "#main/rev/output"\n                        },\n                        {\n                            "id": "#main/sorted/reverse",\n                            "source": "#main/reverse_sort"\n                        }\n                    ],\n                    "out": [\n                        "#main/sorted/output"\n                    ],\n                    "run": "#sorttool.cwl"\n                }\n            ]\n        },\n        {\n            "baseCommand": "rev",\n            "class": "CommandLineTool",\n            "doc": "Reverse each line using the `rev` command",\n            "hints": [\n                {\n                    "class": "ResourceRequirement",\n                    "ramMin": 8\n                }\n            ],\n            "id": "#revtool.cwl",\n            "inputs": [\n                {\n                    "id": "#revtool.cwl/input",\n                    "inputBinding": {},\n                    "type": "File"\n                }\n            ],\n            "outputs": [\n                {\n                    "id": "#revtool.cwl/output",\n                    "outputBinding": {\n                        "glob": "output.txt"\n                    },\n                    "type": "File"\n                }\n            ],\n            "stdout": "output.txt"\n        },\n        {\n            "baseCommand": "sort",\n            "class": "CommandLineTool",\n            "doc": "Sort lines using the `sort` command",\n            "hints": [\n                {\n                    "class": "ResourceRequirement",\n                    "ramMin": 8\n                }\n            ],\n            "id": "#sorttool.cwl",\n            "inputs": [\n                {\n                    "id": "#sorttool.cwl/reverse",\n                    "inputBinding": {\n                        "position": 1,\n                        "prefix": "-r"\n                    },\n                    "type": "boolean"\n                },\n                {\n                    "id": "#sorttool.cwl/input",\n                    "inputBinding": {\n                        "position": 2\n                    },\n                    "type": "File"\n                }\n            ],\n            "outputs": [\n                {\n                    "id": "#sorttool.cwl/output",\n                    "outputBinding": {\n                        "glob": "output.txt"\n                    },\n                    "type": "File"\n                }\n            ],\n            "stdout": "output.txt"\n        }\n    ],\n    "cwlVersion": "v1.0"\n}',
98                     },
99                 },
100             });
101
102             // when
103             await runProcess(dispatch, getState, services);
104
105             // then
106             expect(services.containerRequestService.create).toHaveBeenCalledWith({
107                 command: [
108                     "arvados-cwl-runner",
109                     "--local",
110                     "--api=containers",
111                     "--no-log-timestamps",
112                     "--disable-color",
113                     "--project-uuid=zzzzz-tpzed-yid70bw31f51234",
114                     "/var/lib/cwl/workflow.json#main",
115                     "/var/lib/cwl/cwl.input.json",
116                 ],
117                 containerImage: "arvados/jobs:2.0.4",
118                 cwd: "/var/spool/cwl",
119                 description: "basicFormTestDescription",
120                 mounts: undefined,
121                 secret_mounts: undefined,
122                 name: "basicFormTestName",
123                 outputName: "Output from basicFormTestName",
124                 outputPath: "/var/spool/cwl",
125                 ownerUuid: "zzzzz-tpzed-yid70bw31f51234",
126                 priority: 500,
127                 properties: {
128                     workflowName: "revsort.cwl",
129                     template_uuid: "zzzzz-7fd4e-2tlnerdkxnl4fjt",
130                 },
131                 runtimeConstraints: {
132                     API: true,
133                     ram: 16256 * (1024 * 1024),
134                     vcpus: 1,
135                 },
136                 schedulingParameters: { max_run_time: undefined },
137                 state: "Committed",
138                 useExisting: false
139             });
140
141             // and
142             expect(dispatch).toHaveBeenCalledWith(newProcessUUID);
143         });
144     });
145 });