UNPKG

@asposecloud/aspose-tasks-cloud

Version:
102 lines (98 loc) 6.38 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("getTaskDocumentWithFormat 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 = "Home_move_plan.mpp"; const localPath = BaseTest.localBaseTestDataFolder + fileName; const remotePath = BaseTest.remoteBaseTestDataFolder; const remoteFullPath = remotePath + "/" + fileName; yield tasksApi.uploadFileToStorage(remoteFullPath, localPath); const request = new model_1.GetTaskDocumentWithFormatRequest(); request.name = fileName; request.folder = remotePath; request.format = model_1.ProjectFileFormat.Csv; const result = yield tasksApi.getTaskDocumentWithFormat(request); chai_1.expect(result.response.statusCode).to.equal(200); chai_1.expect(result.body.buffer).is.not.undefined.and.not.null; const strings = BaseTest.convertArrayBufferToStrings(result.body.buffer); chai_1.expect(strings[0]).to.equal("ID;Task_Name;Outline_Level;Duration;Start_Date;Finish_Date;Percent_Comp;Cost;Work"); chai_1.expect(strings[1]).to.equal("1;Five to Eight Weeks Before Moving;1;16 days;Thu 01.01.04 08:00;Thu 22.01.04 17:00;0%;$0;0 hrs"); })); it("should return response with code 200 and correct data as zipped html", () => __awaiter(void 0, void 0, void 0, function* () { const tasksApi = BaseTest.initializeTasksApi(); const fileName = "Home_move_plan.mpp"; const localPath = BaseTest.localBaseTestDataFolder + fileName; const remotePath = BaseTest.remoteBaseTestDataFolder; const remoteFullPath = remotePath + "/" + fileName; yield tasksApi.uploadFileToStorage(remoteFullPath, localPath); const request = new model_1.GetTaskDocumentWithFormatRequest(); request.name = fileName; request.folder = remotePath; request.format = model_1.ProjectFileFormat.Html; request.returnAsZipArchive = true; const result = yield tasksApi.getTaskDocumentWithFormat(request); chai_1.expect(result.response.statusCode).to.equal(200); chai_1.expect(result.body.buffer).is.not.undefined.and.not.null; chai_1.expect(result.body.length).to.be.at.least(1); })); }); describe("postTaskDocumentWithFormat 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 = "Home_move_plan.mpp"; const localPath = BaseTest.localBaseTestDataFolder + fileName; const remotePath = BaseTest.remoteBaseTestDataFolder; const remoteFullPath = remotePath + "/" + fileName; yield tasksApi.uploadFileToStorage(remoteFullPath, localPath); // SaveOptions parameters is a json-serialized representation of // Aspose.Tasks's SaveOptions class or its format-specific inheritors (Like CsvOptions, etc): // See Aspose.Tasks reference: https://apireference.aspose.com/net/tasks/aspose.tasks.saving/saveoptions const saveOptionsSerialized = "{ \"TextDelimiter\":\"Comma\", \"IncludeHeaders\":false,\"NonExistingTestProperty\":false," + "\"View\":{ \"Columns\":[{\"Type\":\"GanttChartColumn\",\"Name\":\"TestColumn1\",\"Property\":\"Name\",\"Width\":120}," + "{\"Type\":\"GanttChartColumn\",\"Name\":\"TestColumn2\",\"Property\":\"Duration\",\"Width\":120}]}}"; const request = new model_1.PostTaskDocumentWithFormatRequest(); request.name = fileName; request.folder = remotePath; request.format = model_1.ProjectFileFormat.Csv; request.saveOptions = JSON.parse(saveOptionsSerialized); const result = yield tasksApi.postTaskDocumentWithFormat(request); chai_1.expect(result.response.statusCode).to.equal(200); chai_1.expect(result.body.buffer).is.not.undefined.and.not.null; const strings = BaseTest.convertArrayBufferToStrings(result.body.buffer); chai_1.expect(strings[0]).to.equal("Five to Eight Weeks Before Moving,16 days"); })); }); //# sourceMappingURL=taskDocumentFormatTests.js.map