UNPKG

@zosconnect/zosconnect-zowe-cli

Version:
86 lines 5.43 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const zosconnect_node_1 = require("@zosconnect/zosconnect-node"); const Service_1 = require("@zosconnect/zosconnect-node/lib/Service"); const ZosConnectService_1 = require("../../../api/service/ZosConnectService"); const ZosConnectSession_1 = require("../../../ZosConnectSession"); describe("ZosConnectService tests", () => { const session = new ZosConnectSession_1.ZosConnectSession("http://example.com:9080"); const options = {}; const serviceObj = new Service_1.Service("http://example.com:9080/zosConnect/services/foo", options, "foo", "bar", "baz"); it("should install the Service", () => __awaiter(void 0, void 0, void 0, function* () { zosconnect_node_1.ZosConnect.prototype.createService = jest.fn().mockReturnValue(serviceObj); const service = yield ZosConnectService_1.ZosConnectService.install(session, Buffer.from("sar")); expect(service.name).toEqual("foo"); expect(service.description).toEqual("bar"); expect(service.serviceProvider).toEqual("baz"); })); it("should delete the Service", () => __awaiter(void 0, void 0, void 0, function* () { zosconnect_node_1.ZosConnect.prototype.getService = jest.fn().mockReturnValue(serviceObj); serviceObj.stop = jest.fn(); serviceObj.delete = jest.fn(); yield ZosConnectService_1.ZosConnectService.delete(session, "foo", true); expect(serviceObj.stop).toBeCalledTimes(1); expect(serviceObj.delete).toBeCalledTimes(1); })); it("should not stop the Service before deleting", () => __awaiter(void 0, void 0, void 0, function* () { zosconnect_node_1.ZosConnect.prototype.getService = jest.fn().mockReturnValue(serviceObj); serviceObj.stop = jest.fn(); serviceObj.delete = jest.fn(); yield ZosConnectService_1.ZosConnectService.delete(session, "foo", false); expect(serviceObj.stop).toHaveBeenCalledTimes(0); expect(serviceObj.delete).toHaveBeenCalledTimes(1); })); it("should list the Services", () => __awaiter(void 0, void 0, void 0, function* () { zosconnect_node_1.ZosConnect.prototype.getServices = jest.fn().mockReturnValue([serviceObj]); const services = yield ZosConnectService_1.ZosConnectService.list(session); expect(services).toHaveLength(1); expect(services[0].name).toEqual("foo"); expect(services[0].description).toEqual("bar"); expect(services[0].serviceProvider).toEqual("baz"); })); it("should update the Service", () => __awaiter(void 0, void 0, void 0, function* () { zosconnect_node_1.ZosConnect.prototype.getService = jest.fn().mockReturnValue(serviceObj); serviceObj.update = jest.fn(); const service = yield ZosConnectService_1.ZosConnectService.update(session, "foo", Buffer.from("sar")); expect(serviceObj.update).toHaveBeenCalledTimes(1); expect(service.name).toEqual("foo"); expect(service.description).toEqual("bar"); expect(service.serviceProvider).toEqual("baz"); })); it("should stop the Service", () => __awaiter(void 0, void 0, void 0, function* () { zosconnect_node_1.ZosConnect.prototype.getService = jest.fn().mockReturnValue(serviceObj); serviceObj.stop = jest.fn(); yield ZosConnectService_1.ZosConnectService.stop(session, "foo"); expect(serviceObj.stop).toHaveBeenCalledTimes(1); })); it("should start the Service", () => __awaiter(void 0, void 0, void 0, function* () { zosconnect_node_1.ZosConnect.prototype.getService = jest.fn().mockReturnValue(serviceObj); serviceObj.start = jest.fn(); yield ZosConnectService_1.ZosConnectService.start(session, "foo"); expect(serviceObj.start).toHaveBeenCalledTimes(1); })); it("should return info on the Service", () => __awaiter(void 0, void 0, void 0, function* () { zosconnect_node_1.ZosConnect.prototype.getService = jest.fn().mockReturnValue(serviceObj); serviceObj.getServiceInvokeUrl = jest.fn().mockReturnValue("invokeUrl"); serviceObj.getStatus = jest.fn().mockReturnValue("Started"); const service = yield ZosConnectService_1.ZosConnectService.info(session, "foo"); expect(service.name).toEqual("foo"); expect(service.description).toEqual("bar"); expect(service.serviceProvider).toEqual("baz"); expect(serviceObj.getServiceInvokeUrl).toHaveBeenCalledTimes(1); expect(service.invokeUrl).toEqual("invokeUrl"); expect(serviceObj.getStatus).toHaveBeenCalledTimes(1); expect(service.status).toEqual("Started"); })); }); //# sourceMappingURL=ZosConnectService.test.js.map