Skip to content

Commit 90cd0bc

Browse files
[TASKSCLOUD-287] - Added tests for file storage endpoints.
1 parent 6d08910 commit 90cd0bc

File tree

3 files changed

+455
-0
lines changed

3 files changed

+455
-0
lines changed

test/storage/fileTests.ts

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
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+
});

test/storage/folderTests.ts

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
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 { expect } from "chai";
26+
import "mocha";
27+
28+
import { CopyFolderRequest, CreateFolderRequest, DeleteFolderRequest, GetFilesListRequest, MoveFolderRequest } from "../../src/model/model";
29+
import * as BaseTest from "../baseTest";
30+
31+
const storageFolder = BaseTest.remoteBaseTestDataFolder + "Storage";
32+
33+
describe("Storage folder operations", () => {
34+
describe("Test for Create folder", () => {
35+
it("should return response with code 200", async () => {
36+
const tasksApi = BaseTest.initializeTasksApi();
37+
38+
const request: CreateFolderRequest = {
39+
path: storageFolder + "/TestCreateFolder",
40+
storageName: undefined,
41+
};
42+
43+
return tasksApi.createFolder(request)
44+
.then((result) => {
45+
expect(result.statusCode).to.equal(200);
46+
});
47+
});
48+
});
49+
50+
describe("Test for Delete folder", () => {
51+
it("should return response with code 200", async () => {
52+
const tasksApi = BaseTest.initializeTasksApi();
53+
54+
const folderName = storageFolder + "/TestDeleteFolder";
55+
56+
const request: CreateFolderRequest = {
57+
path: folderName,
58+
storageName: undefined,
59+
};
60+
61+
return tasksApi.createFolder(request)
62+
.then((result) => {
63+
expect(result.statusCode).to.equals(200);
64+
65+
const deleteRequset: DeleteFolderRequest = {
66+
path: folderName,
67+
storageName: undefined,
68+
recursive: undefined,
69+
};
70+
71+
return tasksApi.deleteFolder(deleteRequset)
72+
.then((result1) => {
73+
expect(result1.statusCode).to.equal(200);
74+
});
75+
});
76+
});
77+
});
78+
79+
describe("Test for get file list of folder", () => {
80+
it("should return response with code 200 and non empty list", async () => {
81+
const tasksApi = BaseTest.initializeTasksApi();
82+
83+
const request: GetFilesListRequest = {
84+
path: storageFolder,
85+
storageName: undefined,
86+
};
87+
88+
return tasksApi.getFilesList(request)
89+
.then((result) => {
90+
expect(result.response.statusCode).to.equal(200);
91+
expect(result.body.value.length).to.be.greaterThan(0);
92+
});
93+
});
94+
});
95+
96+
describe("Test for copy folder", () => {
97+
it("should return response with code 200 and new folder exists", async () => {
98+
const tasksApi = BaseTest.initializeTasksApi();
99+
100+
const src = storageFolder + "/TestCopyFolderSrc";
101+
const dest = storageFolder + "/TestCopyFolderDest";
102+
103+
const request: CreateFolderRequest = {
104+
path: src,
105+
storageName: undefined,
106+
};
107+
108+
return tasksApi.createFolder(request)
109+
.then((result) => {
110+
expect(result.statusCode).to.equal(200);
111+
112+
const copyFolderRequest: CopyFolderRequest = {
113+
srcPath: src,
114+
destPath: dest,
115+
srcStorageName: undefined,
116+
destStorageName: undefined,
117+
};
118+
119+
return tasksApi.copyFolder(copyFolderRequest)
120+
.then((result1) => {
121+
expect(result1.statusCode).to.equal(200);
122+
123+
const getFilesRequest: GetFilesListRequest = {
124+
path: storageFolder,
125+
storageName: undefined,
126+
};
127+
128+
return tasksApi.getFilesList(getFilesRequest)
129+
.then((result2) => {
130+
expect(result2.response.statusCode).to.equal(200);
131+
132+
expect(result2.body.value.some((file) => file.path === "/" + dest + "/")).to.be.true;
133+
});
134+
});
135+
});
136+
});
137+
});
138+
139+
describe("Test for move folder", () => {
140+
it("should return response with code 200 and new folder exists, but old one doesn't", async () => {
141+
const tasksApi = BaseTest.initializeTasksApi();
142+
143+
const src = storageFolder + "/TestMoveFolderSrc";
144+
const dest = storageFolder + "/TestMoveFolderDest";
145+
146+
const request: CreateFolderRequest = {
147+
path: src,
148+
storageName: undefined,
149+
};
150+
151+
return tasksApi.createFolder(request)
152+
.then((result) => {
153+
expect(result.statusCode).to.equal(200);
154+
155+
const moveFolderRequest: MoveFolderRequest = {
156+
srcPath: src,
157+
destPath: dest,
158+
srcStorageName: undefined,
159+
destStorageName: undefined,
160+
};
161+
162+
return tasksApi.moveFolder(moveFolderRequest)
163+
.then((result1) => {
164+
expect(result1.statusCode).to.equal(200);
165+
166+
const getFilesRequest: GetFilesListRequest = {
167+
path: storageFolder,
168+
storageName: undefined,
169+
};
170+
171+
return tasksApi.getFilesList(getFilesRequest)
172+
.then((result2) => {
173+
expect(result2.response.statusCode).to.equal(200);
174+
175+
expect(result2.body.value.some((file) => file.path === "/" + dest + "/")).to.be.true;
176+
expect(result2.body.value.some((file) => file.path === "/" + src + "/")).to.be.false;
177+
});
178+
});
179+
});
180+
});
181+
});
182+
});

0 commit comments

Comments
 (0)