|
| 1 | +/* |
| 2 | +* MIT License |
| 3 | +
|
| 4 | +* Copyright (c) 2019 Aspose Pty Ltd |
| 5 | +
|
| 6 | +* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +* of this software and associated documentation files (the "Software"), to deal |
| 8 | +* in the Software without restriction, including without limitation the rights |
| 9 | +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +* copies of the Software, and to permit persons to whom the Software is |
| 11 | +* furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +* The above copyright notice and this permission notice shall be included in all |
| 14 | +* copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +* SOFTWARE. |
| 23 | +*/ |
| 24 | + |
| 25 | +import fs = require("fs"); |
| 26 | +import "mocha"; |
| 27 | + |
| 28 | +import { expect } from "chai"; |
| 29 | +import { CopyFileRequest, DeleteFileRequest, DownloadFileRequest, MoveFileRequest, UploadFileRequest } from "../../src/model/model"; |
| 30 | +import * as BaseTest from "../baseTest"; |
| 31 | + |
| 32 | +const testFolder = "project"; |
| 33 | + |
| 34 | +describe("Storage file operations", () => { |
| 35 | + describe("Test for uploading file", () => { |
| 36 | + it("should return response with code 200 and name of uploaded file", async () => { |
| 37 | + |
| 38 | + const tasksApi = BaseTest.initializeTasksApi(); |
| 39 | + |
| 40 | + const fileName = "Home_move_plan.mpp"; |
| 41 | + const localPath = BaseTest.localBaseTestDataFolder + fileName; |
| 42 | + const remotePath = BaseTest.remoteBaseTestDataFolder + testFolder; |
| 43 | + |
| 44 | + const request: UploadFileRequest = { |
| 45 | + file: fs.readFileSync(localPath), |
| 46 | + path: remotePath + "/" + fileName, |
| 47 | + storageName: undefined, |
| 48 | + }; |
| 49 | + |
| 50 | + return tasksApi.uploadFile(request) |
| 51 | + .then((result) => { |
| 52 | + expect(result.response.statusCode).to.equal(200); |
| 53 | + expect(result.body.uploaded.length).to.equal(1); |
| 54 | + }); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + describe("Test for copy file", () => { |
| 59 | + it("should return response with code 200 and exist in both src and dest", async () => { |
| 60 | + |
| 61 | + const tasksApi = BaseTest.initializeTasksApi(); |
| 62 | + |
| 63 | + const fileName = "Home_move_plan.mpp"; |
| 64 | + const newFileName = "Home_move_plan_copied.mpp"; |
| 65 | + const localPath = BaseTest.localBaseTestDataFolder + fileName; |
| 66 | + const remoteBasePathSrc = BaseTest.remoteBaseTestDataFolder + fileName; |
| 67 | + const remoteBasePathDest = BaseTest.remoteBaseTestDataFolder + newFileName; |
| 68 | + |
| 69 | + return tasksApi.uploadFileToStorage(remoteBasePathSrc, localPath) |
| 70 | + .then((result) => { |
| 71 | + expect(result.response.statusCode).to.equal(200); |
| 72 | + |
| 73 | + const request: CopyFileRequest = { |
| 74 | + destPath: remoteBasePathDest, |
| 75 | + destStorageName: undefined, |
| 76 | + srcPath: remoteBasePathSrc, |
| 77 | + srcStorageName: undefined, |
| 78 | + versionId: undefined, |
| 79 | + }; |
| 80 | + |
| 81 | + return tasksApi.copyFile(request) |
| 82 | + .then((result1) => { |
| 83 | + expect(result1.statusCode).to.equal(200); |
| 84 | + |
| 85 | + const downloadRequest: DownloadFileRequest = { |
| 86 | + path: remoteBasePathDest, |
| 87 | + storageName: undefined, |
| 88 | + versionId: undefined, |
| 89 | + }; |
| 90 | + |
| 91 | + return tasksApi.downloadFile(downloadRequest) |
| 92 | + .then((result2) => { |
| 93 | + expect(result2.response.statusCode).to.equals(200); |
| 94 | + expect(result2.body.length).to.greaterThan(0); |
| 95 | + |
| 96 | + downloadRequest.path = remoteBasePathSrc; |
| 97 | + |
| 98 | + return tasksApi.downloadFile(downloadRequest) |
| 99 | + .then((result3) => { |
| 100 | + expect(result3.response.statusCode).to.equals(200); |
| 101 | + expect(result3.body.length).to.be.greaterThan(0); |
| 102 | + }); |
| 103 | + }); |
| 104 | + }); |
| 105 | + }); |
| 106 | + }); |
| 107 | + }); |
| 108 | + |
| 109 | + describe("Test for move file", () => { |
| 110 | + it("should return response with code 200 and exists on dest only", async () => { |
| 111 | + |
| 112 | + const tasksApi = BaseTest.initializeTasksApi(); |
| 113 | + |
| 114 | + const fileName = "Home_move_plan.mpp"; |
| 115 | + const newFileName = "Home_move_plan_copied.mpp"; |
| 116 | + const localPath = BaseTest.localBaseTestDataFolder + fileName; |
| 117 | + const remoteBasePathSrc = BaseTest.remoteBaseTestDataFolder + fileName; |
| 118 | + const remoteBasePathDest = BaseTest.remoteBaseTestDataFolder + newFileName; |
| 119 | + |
| 120 | + return tasksApi.uploadFileToStorage(remoteBasePathSrc, localPath) |
| 121 | + .then((result) => { |
| 122 | + expect(result.response.statusCode).to.equal(200); |
| 123 | + |
| 124 | + const request: MoveFileRequest = { |
| 125 | + destPath: remoteBasePathDest, |
| 126 | + destStorageName: undefined, |
| 127 | + srcPath: remoteBasePathSrc, |
| 128 | + srcStorageName: undefined, |
| 129 | + versionId: undefined, |
| 130 | + }; |
| 131 | + |
| 132 | + return tasksApi.moveFile(request) |
| 133 | + .then((result1) => { |
| 134 | + expect(result1.statusCode).to.equal(200); |
| 135 | + |
| 136 | + const downloadRequest: DownloadFileRequest = { |
| 137 | + path: remoteBasePathDest, |
| 138 | + storageName: undefined, |
| 139 | + versionId: undefined, |
| 140 | + }; |
| 141 | + |
| 142 | + return tasksApi.downloadFile(downloadRequest) |
| 143 | + .then((result2) => { |
| 144 | + expect(result2.response.statusCode).to.equal(200); |
| 145 | + |
| 146 | + downloadRequest.path = remoteBasePathSrc; |
| 147 | + |
| 148 | + return tasksApi.downloadFile(downloadRequest) |
| 149 | + .catch((error) => { |
| 150 | + expect(error.response.statusCode).to.equal(404); |
| 151 | + }); |
| 152 | + }); |
| 153 | + }); |
| 154 | + }); |
| 155 | + }); |
| 156 | + }); |
| 157 | + |
| 158 | + describe("Test for deleting file", () => { |
| 159 | + it("should return response with code 200 and name of uploaded file", async () => { |
| 160 | + |
| 161 | + const tasksApi = BaseTest.initializeTasksApi(); |
| 162 | + |
| 163 | + const fileName = "CalendarWorkWeeks.mpp"; |
| 164 | + const localPath = BaseTest.localBaseTestDataFolder + fileName; |
| 165 | + const remotePath = BaseTest.remoteBaseTestDataFolder + testFolder; |
| 166 | + |
| 167 | + const request: UploadFileRequest = { |
| 168 | + file: fs.readFileSync(localPath), |
| 169 | + path: remotePath + "/" + fileName, |
| 170 | + storageName: undefined, |
| 171 | + }; |
| 172 | + |
| 173 | + return tasksApi.uploadFile(request) |
| 174 | + .then((result) => { |
| 175 | + expect(result.response.statusCode).to.equal(200); |
| 176 | + |
| 177 | + const deleteRequest: DeleteFileRequest = { |
| 178 | + path: remotePath + "/" + fileName, |
| 179 | + storageName: undefined, |
| 180 | + versionId: undefined, |
| 181 | + }; |
| 182 | + |
| 183 | + return tasksApi.deleteFile(deleteRequest) |
| 184 | + .then((result1) => { |
| 185 | + expect(result1.statusCode).to.equals(200); |
| 186 | + }); |
| 187 | + }); |
| 188 | + }); |
| 189 | + }); |
| 190 | +}); |
0 commit comments