import {expect, tap} from "tapbundle"; import {HaventecCloudPortal} from "../dist/index"; import * as request from "superagent"; import * as mockRequest from "superagent-mock"; import {LocalData} from "@haventec/common-js"; var mockConfig = [ { pattern: 'http://mytest.com(.*)', fixtures: function (match, params, headers) { // private listUrl = '/application/:tenancyUUID?page=:page&size=:size'; // private getUrl = '/application/:tenancyUUID/name/:name'; // private updateUrl = '/application/:tenancyUUID'; if (match[1] === '/application/TestConnectorUuid?page=0&size=10') { return ({ body: {"responseStatus": {"status":"SUCCESS","message":"Loaded","applications":{"number":0,"size":10,"totalPages":1,"numberOfElements":1,"totalElements":1,"previousPage":false,"firstPage":true,"nextPage":false,"lastPage":true,"content":[{"applicationname":"root","email":null,"tenancyUUID":"648bd4bf-d7b8-4c9f-9b51-433460dda0ae","lastLogin":1494309643,"dateCreated":1494309643,"provisionToken":"","locked":false,"preProvisioned":false}]}}} }); } if (match[1] === '/application/TestConnectorUuid/name/testapplication') { return ({ body: {"responseStatus": {"status":"SUCCESS","message":"Loaded","applications":{"number":1,"size":1,"totalPages":1,"numberOfElements":1,"totalElements":1,"previousPage":false,"firstPage":true,"nextPage":false,"lastPage":true,"content":[{"applicationname":"root","email":null,"tenancyUUID":"648bd4bf-d7b8-4c9f-9b51-433460dda0ae","lastLogin":1494309643,"dateCreated":1494309643,"provisionToken":"","locked":false,"preProvisioned":false}]}}} }); } if (match[1] === '/application/TestConnectorUuid') { return ({ body: {"responseStatus": {"status":"SUCCESS","message":"Loaded","applications":{"number":1,"size":1,"totalPages":1,"numberOfElements":1,"totalElements":1,"previousPage":false,"firstPage":true,"nextPage":false,"lastPage":true,"content":[{"applicationname":"root","email":null,"tenancyUUID":"648bd4bf-d7b8-4c9f-9b51-433460dda0ae","lastLogin":1494309643,"dateCreated":1494309643,"provisionToken":"","locked":false,"preProvisioned":false}]}}} }); } return 'foo'; }, get: function (match, data) { return data; }, delete: function (match, data) { return data; }, post: function (match, data) { return data; } }, { pattern: 'http://myerrortest.com(.*)', fixtures: function (match, params, headers) { return 'foo'; }, get: function (match, data) { return data; }, post: function (match, data) { return data; } } ]; var logger = function(log) { console.log('superagent call', log); }; tap.test("it should test HaventecCloudPortal list applications", async () => { var superagentMock = mockRequest(request, mockConfig, logger); let ha = new HaventecCloudPortal("http://mytest.com", true); let ld : LocalData = new LocalData("testuser", null, null, null, "TestConnectorUuid", "TestApplicationUUID", null, null, null, null, null); ha.getAuthService().getLocalDataService().setLocalData("testuser", ld); let ret = await ha.listApplications(0, 10); expect(ret['responseStatus']['status']).to.be.equal("SUCCESS"); superagentMock.unset(); }); tap.test("it should test HaventecCloudPortal get application", async () => { var superagentMock = mockRequest(request, mockConfig, logger); let ha = new HaventecCloudPortal("http://mytest.com", true); let ld : LocalData = new LocalData("testuser", null, null, null, "TestConnectorUuid", "TestApplicationUUID", null, null, null, null, null); ha.getAuthService().getLocalDataService().setLocalData("testuser", ld); let ret = await ha.getApplication('testapplication'); expect(ret['responseStatus']['status']).to.be.equal("SUCCESS"); superagentMock.unset(); }); tap.test("it should test HaventecCloudPortal update a application", async () => { var superagentMock = mockRequest(request, mockConfig, logger); let ha = new HaventecCloudPortal("http://mytest.com", true); let ld : LocalData = new LocalData("testuser", null, null, null, "TestConnectorUuid", "TestApplicationUUID", null, null, null, null, null); ha.getAuthService().getLocalDataService().setLocalData("testuser", ld); let ret = await ha.updateApplication('testapplication', 'test application', '123456789', 'APIKEY06743267482687'); expect(ret['responseStatus']['status']).to.be.equal("SUCCESS"); superagentMock.unset(); }); tap.start()