UNPKG

@asposecloud/aspose-tasks-cloud

Version:
201 lines (197 loc) 12.3 kB
"use strict"; /* * MIT License * Copyright (c) 2019 Aspose Pty Ltd * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ 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 chai_1 = require("chai"); require("mocha"); const model_1 = require("../src/model/model"); const BaseTest = require("./baseTest"); describe("getExtendedAttributes function", () => { it("should return response with code 200 and correct data", () => __awaiter(void 0, void 0, void 0, function* () { const tasksApi = BaseTest.initializeTasksApi(); const fileName = "NewProductDev.mpp"; const localPath = BaseTest.localBaseTestDataFolder + fileName; const remotePath = BaseTest.remoteBaseTestDataFolder; const remoteFullPath = remotePath + "/" + fileName; yield tasksApi.uploadFileToStorage(remoteFullPath, localPath); const request = new model_1.GetExtendedAttributesRequest(); request.name = fileName; request.folder = remotePath; const result = yield tasksApi.getExtendedAttributes(request); chai_1.expect(result.response.statusCode).to.equal(200); chai_1.expect(result.body.extendedAttributes).not.undefined.and.not.null; chai_1.expect(result.body.extendedAttributes.list.length).to.equal(2); })); }); describe("getExtendedAttributeByIndex function", () => { it("should return response with code 200 and correct data", () => __awaiter(void 0, void 0, void 0, function* () { const tasksApi = BaseTest.initializeTasksApi(); const fileName = "NewProductDev.mpp"; const localPath = BaseTest.localBaseTestDataFolder + fileName; const remotePath = BaseTest.remoteBaseTestDataFolder; const remoteFullPath = remotePath + "/" + fileName; yield tasksApi.uploadFileToStorage(remoteFullPath, localPath); const request = new model_1.GetExtendedAttributeByIndexRequest(); request.name = fileName; request.folder = remotePath; request.index = 1; const result = yield tasksApi.getExtendedAttributeByIndex(request); chai_1.expect(result.response.statusCode).to.equal(200); chai_1.expect(result.body.extendedAttribute).not.undefined.and.not.null; chai_1.expect(result.body.extendedAttribute.fieldName).to.equal("Text1"); chai_1.expect(result.body.extendedAttribute.calculationType).to.equal(model_1.CalculationType.Lookup); chai_1.expect(result.body.extendedAttribute.valueList.length).to.equal(1); chai_1.expect(result.body.extendedAttribute.valueList[0].description).to.equal("descr"); chai_1.expect(result.body.extendedAttribute.valueList[0].id).to.equal(1); })); }); describe("putExtendedAttribute function", () => { it("should add new ExtendedAttribute and return correct data", () => __awaiter(void 0, void 0, void 0, function* () { const tasksApi = BaseTest.initializeTasksApi(); const fileName = "NewProductDev.mpp"; const localPath = BaseTest.localBaseTestDataFolder + fileName; const remotePath = BaseTest.remoteBaseTestDataFolder; const remoteFullPath = remotePath + "/" + fileName; yield tasksApi.uploadFileToStorage(remoteFullPath, localPath); const firstValue = new model_1.Value(); firstValue.description = "descr1"; firstValue.val = "Internal"; firstValue.id = 111; const secondValue = new model_1.Value(); secondValue.description = "descr2"; secondValue.val = "External"; secondValue.id = 112; const newExtendedAttribute = new model_1.ExtendedAttributeDefinition; newExtendedAttribute.calculationType = model_1.CalculationType.Lookup, newExtendedAttribute.cfType = model_1.CustomFieldType.Text, newExtendedAttribute.fieldName = "Text3", newExtendedAttribute.elementType = model_1.ElementType.Task, newExtendedAttribute.alias = "New Field", newExtendedAttribute.valueList = [firstValue, secondValue]; const request1 = new model_1.PutExtendedAttributeRequest(); request1.name = fileName; request1.folder = remotePath; request1.extendedAttribute = newExtendedAttribute; const result1 = yield tasksApi.putExtendedAttribute(request1); chai_1.expect(result1.response.statusCode).to.equal(200); chai_1.expect(result1.body.extendedAttribute).not.undefined.and.not.null; chai_1.expect(result1.body.extendedAttribute.fieldName).to.equal("Text3"); chai_1.expect(result1.body.extendedAttribute.alias).to.equal("New Field"); chai_1.expect(result1.body.extendedAttribute.fieldId).to.equal("188743737"); const addedAttributeIndex = result1.body.extendedAttribute.index; const request2 = new model_1.GetExtendedAttributeByIndexRequest(); request2.name = fileName; request2.folder = remotePath; request2.index = addedAttributeIndex; const result2 = yield tasksApi.getExtendedAttributeByIndex(request2); chai_1.expect(result2.response.statusCode).to.equal(200); chai_1.expect(result2.body.extendedAttribute).not.undefined.and.not.null; chai_1.expect(result2.body.extendedAttribute.fieldId).to.equal("188743737"); chai_1.expect(result2.body.extendedAttribute.fieldName).to.equal("Text3"); chai_1.expect(result2.body.extendedAttribute.cfType).to.equal(model_1.CustomFieldType.Text); chai_1.expect(result2.body.extendedAttribute.alias).to.equal("New Field"); const valueList = result2.body.extendedAttribute.valueList; chai_1.expect(valueList.length).to.equal(2); chai_1.expect(valueList[0].id).to.equal(111); chai_1.expect(valueList[0].val).to.equal("Internal"); chai_1.expect(valueList[0].description).to.equal("descr1"); chai_1.expect(valueList[1].id).to.equal(112); chai_1.expect(valueList[1].val).to.equal("External"); chai_1.expect(valueList[1].description).to.equal("descr2"); })); it("should edit ExtendedAttribute and return correct data", () => __awaiter(void 0, void 0, void 0, function* () { const tasksApi = BaseTest.initializeTasksApi(); const fileName = "NewProductDev.mpp"; const localPath = BaseTest.localBaseTestDataFolder + fileName; const remotePath = BaseTest.remoteBaseTestDataFolder; const remoteFullPath = remotePath + "/" + fileName; yield tasksApi.uploadFileToStorage(remoteFullPath, localPath); const request1 = new model_1.GetExtendedAttributeByIndexRequest(); request1.name = fileName; request1.folder = remotePath; request1.index = 1; const result1 = yield tasksApi.getExtendedAttributeByIndex(request1); chai_1.expect(result1.response.statusCode).to.equal(200); chai_1.expect(result1.body.extendedAttribute).not.undefined.and.not.null; const extendedAttributeToEdit = result1.body.extendedAttribute; extendedAttributeToEdit.calculationType = model_1.CalculationType.None; extendedAttributeToEdit.valueList.length = 0; extendedAttributeToEdit.cfType = model_1.CustomFieldType.Text; extendedAttributeToEdit.fieldName = "Text1"; extendedAttributeToEdit.elementType = model_1.ElementType.Task; extendedAttributeToEdit.alias = "Edited field"; const request2 = new model_1.PutExtendedAttributeRequest(); request2.name = fileName; request2.folder = remotePath; request2.extendedAttribute = extendedAttributeToEdit; const result2 = yield tasksApi.putExtendedAttribute(request2); chai_1.expect(result2.response.statusCode).to.equal(200); chai_1.expect(result2.body.extendedAttribute).not.undefined.and.not.null; chai_1.expect(result2.body.extendedAttribute.fieldName).to.equal("Text1"); chai_1.expect(result2.body.extendedAttribute.alias).to.equal("Edited field"); chai_1.expect(result2.body.extendedAttribute.fieldId).to.equal("188743731"); const addedAttributeIndex = result2.body.extendedAttribute.index; const request3 = new model_1.GetExtendedAttributeByIndexRequest(); request3.name = fileName; request3.folder = remotePath; request3.index = addedAttributeIndex; const result3 = yield tasksApi.getExtendedAttributeByIndex(request3); chai_1.expect(result3.response.statusCode).to.equal(200); chai_1.expect(result3.body.extendedAttribute).not.undefined.and.not.null; chai_1.expect(result3.body.extendedAttribute.fieldId).to.equal("188743731"); chai_1.expect(result3.body.extendedAttribute.fieldName).to.equal("Text1"); chai_1.expect(result3.body.extendedAttribute.cfType).to.equal(model_1.CustomFieldType.Text); chai_1.expect(result3.body.extendedAttribute.alias).to.equal("Edited field"); chai_1.expect(result3.body.extendedAttribute.valueList.length).to.equal(0); })); }); describe("deleteExtendedAttributeByIndex function", () => { it("should return response with code 200 and correct data", () => __awaiter(void 0, void 0, void 0, function* () { const tasksApi = BaseTest.initializeTasksApi(); const fileName = "NewProductDev.mpp"; const localPath = BaseTest.localBaseTestDataFolder + fileName; const remotePath = BaseTest.remoteBaseTestDataFolder; const remoteFullPath = remotePath + "/" + fileName; yield tasksApi.uploadFileToStorage(remoteFullPath, localPath); const request1 = new model_1.DeleteExtendedAttributeByIndexRequest(); request1.name = fileName; request1.folder = remotePath; request1.index = 1; const result1 = yield tasksApi.deleteExtendedAttributeByIndex(request1); chai_1.expect(result1.response.statusCode).to.equal(200); const request2 = new model_1.GetExtendedAttributesRequest(); request2.name = fileName; request2.folder = remotePath; const result2 = yield tasksApi.getExtendedAttributes(request2); chai_1.expect(result2.response.statusCode).to.equal(200); chai_1.expect(result2.body.extendedAttributes).not.undefined.and.not.null; chai_1.expect(result2.body.extendedAttributes.list.length).to.equal(1); })); }); //# sourceMappingURL=extendedAttributesTests.js.map