This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
/
Urimap.handler.unit.test.ts
132 lines (120 loc) · 4.26 KB
/
Urimap.handler.unit.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* This program and the accompanying materials are made available under the terms of the *
* Eclipse Public License v2.0 which accompanies this distribution, and is available at *
* https://www.eclipse.org/legal/epl-v20.html *
* *
* SPDX-License-Identifier: EPL-2.0 *
* *
* Copyright Contributors to the Zowe Project. *
* *
*/
import { CommandProfiles, IHandlerParameters, IProfile, Session } from "@zowe/imperative";
import { ICMCIApiResponse } from "../../../../src";
import { UrimapDefinition } from "../../../../src/cli/discard/urimap/Urimap.definition";
import UrimapHandler from "../../../../src/cli/discard/urimap/Urimap.handler";
jest.mock("../../../../src/api/methods/discard");
const Discard = require("../../../../src/api/methods/discard");
const host = "somewhere.com";
const port = "43443";
const user = "someone";
const password = "somesecret";
const protocol = "http";
const rejectUnauthorized = false;
const PROFILE_MAP = new Map<string, IProfile[]>();
PROFILE_MAP.set(
"cics", [{
name: "cics",
type: "cics",
host,
port,
user,
password,
protocol,
rejectUnauthorized
}]
);
const PROFILES: CommandProfiles = new CommandProfiles(PROFILE_MAP);
const DEFAULT_PARAMETERS: IHandlerParameters = {
arguments: {$0: "", _: []}, // Please provide arguments later on
positionals: ["cics", "discard", "urimap"],
response: {
data: {
setMessage: jest.fn((setMsgArgs) => {
expect(setMsgArgs).toMatchSnapshot();
}),
setObj: jest.fn((setObjArgs) => {
expect(setObjArgs).toMatchSnapshot();
}),
setExitCode: jest.fn()
},
console: {
log: jest.fn((logs) => {
expect(logs.toString()).toMatchSnapshot();
}),
error: jest.fn((errors) => {
expect(errors.toString()).toMatchSnapshot();
}),
errorHeader: jest.fn(() => undefined)
},
progress: {
startBar: jest.fn((parms) => undefined),
endBar: jest.fn(() => undefined)
},
format: {
output: jest.fn((parms) => {
expect(parms).toMatchSnapshot();
})
}
},
definition: UrimapDefinition,
fullDefinition: UrimapDefinition,
profiles: PROFILES
};
describe("DiscardUrimapHandler", () => {
const urimapName = "testUrimap";
const regionName = "testRegion";
const defaultReturn: ICMCIApiResponse = {
response: {
resultsummary: {api_response1: "1024", api_response2: "0", recordcount: "0", displayed_recordcount: "0"},
records: "testing"
}
};
const functionSpy = jest.spyOn(Discard, "discardUrimap");
beforeEach(() => {
functionSpy.mockClear();
functionSpy.mockImplementation(async () => defaultReturn);
});
it("should call the discardUrimap api", async () => {
const handler = new UrimapHandler();
const commandParameters = {...DEFAULT_PARAMETERS};
commandParameters.arguments = {
...commandParameters.arguments,
urimapName,
regionName,
host,
port,
user,
password,
protocol,
rejectUnauthorized
};
await handler.process(commandParameters);
expect(functionSpy).toHaveBeenCalledTimes(1);
const testProfile = PROFILE_MAP.get("cics")[0];
expect(functionSpy).toHaveBeenCalledWith(
new Session({
type: "basic",
hostname: testProfile.host,
port: testProfile.port,
user: testProfile.user,
password: testProfile.password,
rejectUnauthorized,
protocol
}),
{
name: urimapName,
regionName
}
);
});
});