@asposecloud/aspose-tasks-cloud
Version:
Aspose.Tasks Cloud SDK for Node.js
166 lines (162 loc) • 8.57 kB
JavaScript
/*
* 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 fs = require("fs");
require("mocha");
const chai_1 = require("chai");
const BaseTest = require("../baseTest");
const testFolder = "project";
describe("Storage file operations", () => {
describe("Test for uploading file", () => {
it("should return response with code 200 and name of uploaded file", () => __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 + testFolder;
const request = {
file: fs.readFileSync(localPath),
path: remotePath + "/" + fileName,
storageName: undefined,
};
return tasksApi.uploadFile(request)
.then((result) => {
chai_1.expect(result.response.statusCode).to.equal(200);
chai_1.expect(result.body.uploaded.length).to.equal(1);
});
}));
});
describe("Test for copy file", () => {
it("should return response with code 200 and exist in both src and dest", () => __awaiter(void 0, void 0, void 0, function* () {
const tasksApi = BaseTest.initializeTasksApi();
const fileName = "Home_move_plan.mpp";
const newFileName = "Home_move_plan_copied.mpp";
const localPath = BaseTest.localBaseTestDataFolder + fileName;
const remoteBasePathSrc = BaseTest.remoteBaseTestDataFolder + fileName;
const remoteBasePathDest = BaseTest.remoteBaseTestDataFolder + newFileName;
return tasksApi.uploadFileToStorage(remoteBasePathSrc, localPath)
.then((result) => {
chai_1.expect(result.response.statusCode).to.equal(200);
const request = {
destPath: remoteBasePathDest,
destStorageName: undefined,
srcPath: remoteBasePathSrc,
srcStorageName: undefined,
versionId: undefined,
};
return tasksApi.copyFile(request)
.then((result1) => {
chai_1.expect(result1.statusCode).to.equal(200);
const downloadRequest = {
path: remoteBasePathDest,
storageName: undefined,
versionId: undefined,
};
return tasksApi.downloadFile(downloadRequest)
.then((result2) => {
chai_1.expect(result2.response.statusCode).to.equals(200);
chai_1.expect(result2.body.length).to.greaterThan(0);
downloadRequest.path = remoteBasePathSrc;
return tasksApi.downloadFile(downloadRequest)
.then((result3) => {
chai_1.expect(result3.response.statusCode).to.equals(200);
chai_1.expect(result3.body.length).to.be.greaterThan(0);
});
});
});
});
}));
});
describe("Test for move file", () => {
it("should return response with code 200 and exists on dest only", () => __awaiter(void 0, void 0, void 0, function* () {
const tasksApi = BaseTest.initializeTasksApi();
const fileName = "Home_move_plan.mpp";
const newFileName = "Home_move_plan_copied.mpp";
const localPath = BaseTest.localBaseTestDataFolder + fileName;
const remoteBasePathSrc = BaseTest.remoteBaseTestDataFolder + fileName;
const remoteBasePathDest = BaseTest.remoteBaseTestDataFolder + newFileName;
return tasksApi.uploadFileToStorage(remoteBasePathSrc, localPath)
.then((result) => {
chai_1.expect(result.response.statusCode).to.equal(200);
const request = {
destPath: remoteBasePathDest,
destStorageName: undefined,
srcPath: remoteBasePathSrc,
srcStorageName: undefined,
versionId: undefined,
};
return tasksApi.moveFile(request)
.then((result1) => {
chai_1.expect(result1.statusCode).to.equal(200);
const downloadRequest = {
path: remoteBasePathDest,
storageName: undefined,
versionId: undefined,
};
return tasksApi.downloadFile(downloadRequest)
.then((result2) => {
chai_1.expect(result2.response.statusCode).to.equal(200);
downloadRequest.path = remoteBasePathSrc;
return tasksApi.downloadFile(downloadRequest)
.catch((error) => {
chai_1.expect(error.response.statusCode).to.equal(404);
});
});
});
});
}));
});
describe("Test for deleting file", () => {
it("should return response with code 200 and name of uploaded file", () => __awaiter(void 0, void 0, void 0, function* () {
const tasksApi = BaseTest.initializeTasksApi();
const fileName = "CalendarWorkWeeks.mpp";
const localPath = BaseTest.localBaseTestDataFolder + fileName;
const remotePath = BaseTest.remoteBaseTestDataFolder + testFolder;
const request = {
file: fs.readFileSync(localPath),
path: remotePath + "/" + fileName,
storageName: undefined,
};
return tasksApi.uploadFile(request)
.then((result) => {
chai_1.expect(result.response.statusCode).to.equal(200);
const deleteRequest = {
path: remotePath + "/" + fileName,
storageName: undefined,
versionId: undefined,
};
return tasksApi.deleteFile(deleteRequest)
.then((result1) => {
chai_1.expect(result1.statusCode).to.equals(200);
});
});
}));
});
});
//# sourceMappingURL=fileTests.js.map
;