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 = '/admin/property/:applicationUUID/category'; // private getUrl = '/admin/property/:applicationUUID/category/:categoryname'; // private updateUrl = '/admin/property/:applicationUUID/category'; // private deleteUrl = '/admin/property/:applicationUUID/category/:categoryname'; // private deletePropertyUrl = '/admin/property/:applicationUUID/category/:categoryname/name/:propertyname'; if (match[1] === '/admin/property/TestApplicationUUID/category') { return ({ body: {"responseStatus": {"status":"SUCCESS","message":"Loaded","properties":{"number":0,"size":10,"totalPages":1,"numberOfElements":1,"totalElements":1,"previousPage":false,"firstPage":true,"nextPage":false,"lastPage":true,"content":[{"propertyname":"root","email":null,"tenancyUUID":"648bd4bf-d7b8-4c9f-9b51-433460dda0ae","lastLogin":1494309643,"dateCreated":1494309643,"provisionToken":"","locked":false,"preProvisioned":false}]}}} }); } if (match[1] === '/admin/property/TestApplicationUUID/category/testcategory') { return ({ body: {"responseStatus": {"status":"SUCCESS","message":"Loaded","properties":{"number":1,"size":1,"totalPages":1,"numberOfElements":1,"totalElements":1,"previousPage":false,"firstPage":true,"nextPage":false,"lastPage":true,"content":[{"propertyname":"root","email":null,"tenancyUUID":"648bd4bf-d7b8-4c9f-9b51-433460dda0ae","lastLogin":1494309643,"dateCreated":1494309643,"provisionToken":"","locked":false,"preProvisioned":false}]}}} }); } if (match[1] === '/admin/property/TestApplicationUUID/category/testcategory/name/testproperty') { return ({ body: {"responseStatus": {"status":"SUCCESS"}} }); } 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 properties", async () => { var superagentMock = mockRequest(request, mockConfig, logger); let ha = new HaventecCloudPortal("http://mytest.com", true); let ld : LocalData = new LocalData("testuser", null, null, null, null, "TestApplicationUUID", null, null, null, null, null); ha.getAuthService().getLocalDataService().setLocalData("testuser", ld); let ret = await ha.listCategories(); expect(ret['responseStatus']['status']).to.be.equal("SUCCESS"); superagentMock.unset(); }); tap.test("it should test HaventecCloudPortal get property", async () => { var superagentMock = mockRequest(request, mockConfig, logger); let ha = new HaventecCloudPortal("http://mytest.com", true); let ld : LocalData = new LocalData("testuser", null, null, null, null, "TestApplicationUUID", null, null, null, null, null); ha.getAuthService().getLocalDataService().setLocalData("testuser", ld); let ret = await ha.getPropertiesForCategory('testcategory'); expect(ret['responseStatus']['status']).to.be.equal("SUCCESS"); superagentMock.unset(); }); tap.test("it should test HaventecCloudPortal delete a property", async () => { var superagentMock = mockRequest(request, mockConfig, logger); let ha = new HaventecCloudPortal("http://mytest.com", true); let ld : LocalData = new LocalData("testuser", null, null, null, null, "TestApplicationUUID", null, null, null, null, null); ha.getAuthService().getLocalDataService().setLocalData("testuser", ld); let ret = await ha.deletePropertyForCategory('testcategory', 'testproperty'); expect(ret['responseStatus']['status']).to.be.equal("SUCCESS"); superagentMock.unset(); }); tap.test("it should test HaventecCloudPortal delete a category", async () => { var superagentMock = mockRequest(request, mockConfig, logger); let ha = new HaventecCloudPortal("http://mytest.com", true); let ld : LocalData = new LocalData("testuser", null, null, null, null, "TestApplicationUUID", null, null, null, null, null); ha.getAuthService().getLocalDataService().setLocalData("testuser", ld); let ret = await ha.deleteCategory('testcategory'); expect(ret['responseStatus']['status']).to.be.equal("SUCCESS"); superagentMock.unset(); }); tap.test("it should test HaventecCloudPortal update a property", async () => { var superagentMock = mockRequest(request, mockConfig, logger); let ha = new HaventecCloudPortal("http://mytest.com", true); let ld : LocalData = new LocalData("testuser", null, null, null, null, "TestApplicationUUID", null, null, null, null, null); ha.getAuthService().getLocalDataService().setLocalData("testuser", ld); let ret = await ha.updatePropertyForCategory('testcategory', 'test property', 'propval'); expect(ret['responseStatus']['status']).to.be.equal("SUCCESS"); superagentMock.unset(); }); tap.start()