Skip to content

Commit 2fe2718

Browse files
[TASKSCLOUD-284] - Added tests for task document format, task links and task extended attributes endpoints.
1 parent 1af8e6d commit 2fe2718

File tree

3 files changed

+735
-0
lines changed

3 files changed

+735
-0
lines changed

test/taskDocumentFormatTests.ts

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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 { GetTaskDocumentWithFormatRequest, ProjectFileFormat, PostTaskDocumentWithFormatRequest } from "../src/model/model";
29+
import * as BaseTest from "./baseTest";
30+
31+
describe("getTaskDocumentWithFormat function", () => {
32+
it("should return response with code 200 and correct data", async () => {
33+
34+
const tasksApi = BaseTest.initializeTasksApi();
35+
const fileName = "Home_move_plan.mpp";
36+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
37+
const remotePath = BaseTest.remoteBaseTestDataFolder;
38+
const remoteFullPath = remotePath + "/" + fileName;
39+
40+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
41+
42+
const request = new GetTaskDocumentWithFormatRequest();
43+
request.name = fileName;
44+
request.folder = remotePath;
45+
request.format = ProjectFileFormat.Csv;
46+
47+
const result = await tasksApi.getTaskDocumentWithFormat(request);
48+
49+
expect(result.response.statusCode).to.equal(200);
50+
expect(result.body.buffer).is.not.undefined.and.not.null;
51+
52+
const strings = BaseTest.convertArrayBufferToStrings(result.body.buffer);
53+
expect(strings[0]).to.equal("ID;Task_Name;Outline_Level;Duration;Start_Date;Finish_Date;Percent_Comp;Cost;Work");
54+
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");
55+
});
56+
it("should return response with code 200 and correct data as zipped html", async () => {
57+
58+
const tasksApi = BaseTest.initializeTasksApi();
59+
const fileName = "Home_move_plan.mpp";
60+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
61+
const remotePath = BaseTest.remoteBaseTestDataFolder;
62+
const remoteFullPath = remotePath + "/" + fileName;
63+
64+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
65+
66+
const request = new GetTaskDocumentWithFormatRequest();
67+
request.name = fileName;
68+
request.folder = remotePath;
69+
request.format = ProjectFileFormat.Html;
70+
request.returnAsZipArchive = true;
71+
72+
const result = await tasksApi.getTaskDocumentWithFormat(request);
73+
74+
expect(result.response.statusCode).to.equal(200);
75+
expect(result.body.buffer).is.not.undefined.and.not.null;
76+
expect(result.body.length).to.be.at.least(1);
77+
});
78+
});
79+
80+
describe("postTaskDocumentWithFormat function", () => {
81+
it("should return response with code 200 and correct data", async () => {
82+
83+
const tasksApi = BaseTest.initializeTasksApi();
84+
const fileName = "Home_move_plan.mpp";
85+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
86+
const remotePath = BaseTest.remoteBaseTestDataFolder;
87+
const remoteFullPath = remotePath + "/" + fileName;
88+
89+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
90+
91+
// SaveOptions parameters is a json-serialized representation of
92+
// Aspose.Tasks's SaveOptions class or its format-specific inheritors (Like CsvOptions, etc):
93+
// See Aspose.Tasks reference: https://apireference.aspose.com/net/tasks/aspose.tasks.saving/saveoptions
94+
const saveOptionsSerialized = "{ \"TextDelimiter\":\"Comma\", \"IncludeHeaders\":false,\"NonExistingTestProperty\":false," +
95+
"\"View\":{ \"Columns\":[{\"Type\":\"GanttChartColumn\",\"Name\":\"TestColumn1\",\"Property\":\"Name\",\"Width\":120}," +
96+
"{\"Type\":\"GanttChartColumn\",\"Name\":\"TestColumn2\",\"Property\":\"Duration\",\"Width\":120}]}}";
97+
const request = new PostTaskDocumentWithFormatRequest();
98+
request.name = fileName;
99+
request.folder = remotePath;
100+
request.format = ProjectFileFormat.Csv;
101+
request.saveOptions = JSON.parse(saveOptionsSerialized);
102+
103+
const result = await tasksApi.postTaskDocumentWithFormat(request);
104+
105+
expect(result.response.statusCode).to.equal(200);
106+
expect(result.body.buffer).is.not.undefined.and.not.null;
107+
108+
const strings = BaseTest.convertArrayBufferToStrings(result.body.buffer);
109+
expect(strings[0]).to.equal("Five to Eight Weeks Before Moving,16 days");
110+
});
111+
});

test/taskLinksTests.ts

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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 { GetTaskLinksRequest, PostTaskLinkRequest, TaskLink, TaskLinkType, TimeUnitType, PutTaskLinkRequest, DeleteTaskLinkRequest } from "../src/model/model";
29+
import * as BaseTest from "./baseTest";
30+
31+
describe("getTaskLinks function", () => {
32+
it("should return response with code 200 and correct data", async () => {
33+
34+
const tasksApi = BaseTest.initializeTasksApi();
35+
const fileName = "NewProductDev.mpp";
36+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
37+
const remotePath = BaseTest.remoteBaseTestDataFolder;
38+
const remoteFullPath = remotePath + "/" + fileName;
39+
40+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
41+
42+
const request = new GetTaskLinksRequest();
43+
request.name = fileName;
44+
request.folder = remotePath;
45+
46+
const result = await tasksApi.getTaskLinks(request);
47+
48+
expect(result.response.statusCode).to.equal(200);
49+
expect(result.body.taskLinks).is.not.undefined.and.not.null;
50+
expect(result.body.taskLinks.length).to.equal(24);
51+
});
52+
});
53+
54+
describe("postTaskLink function", () => {
55+
it("should return response with code 200", async () => {
56+
57+
const tasksApi = BaseTest.initializeTasksApi();
58+
const fileName = "NewProductDev.mpp";
59+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
60+
const remotePath = BaseTest.remoteBaseTestDataFolder;
61+
const remoteFullPath = remotePath + "/" + fileName;
62+
63+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
64+
65+
const taskLink = new TaskLink()
66+
taskLink.predecessorUid = 28;
67+
taskLink.successorUid = 30;
68+
taskLink.linkType = TaskLinkType.StartToStart;
69+
taskLink.lag = 9600;
70+
taskLink.lagFormat = TimeUnitType.Day;
71+
const request = new PostTaskLinkRequest();
72+
request.name = fileName;
73+
request.folder = remotePath;
74+
request.taskLink = taskLink;
75+
76+
const result = await tasksApi.postTaskLink(request);
77+
78+
expect(result.response.statusCode).to.equal(200);
79+
});
80+
});
81+
82+
describe("putTaskLinks function", () => {
83+
it("should return response with code 200 and correct data", async () => {
84+
85+
const tasksApi = BaseTest.initializeTasksApi();
86+
const fileName = "NewProductDev.mpp";
87+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
88+
const remotePath = BaseTest.remoteBaseTestDataFolder;
89+
const remoteFullPath = remotePath + "/" + fileName;
90+
91+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
92+
93+
const getRequest = new GetTaskLinksRequest();
94+
getRequest.name = fileName;
95+
getRequest.folder = remotePath;
96+
97+
let getResult = await tasksApi.getTaskLinks(getRequest);
98+
const taskLinkToEdit = getResult.body.taskLinks[0];
99+
100+
// Modification of PredecessorUid and SuccessorUid fields is not supported.
101+
taskLinkToEdit.linkType = TaskLinkType.StartToFinish;
102+
taskLinkToEdit.lag = 9600;
103+
taskLinkToEdit.lagFormat = TimeUnitType.Day;
104+
105+
const putRequest = new PutTaskLinkRequest();
106+
putRequest.name = fileName;
107+
putRequest.folder = remotePath;
108+
putRequest.index = 1;
109+
putRequest.taskLink = taskLinkToEdit;
110+
111+
const putResult = await tasksApi.putTaskLink(putRequest);
112+
113+
expect(putResult.response.statusCode).to.equal(200);
114+
115+
getResult = await tasksApi.getTaskLinks(getRequest);
116+
117+
expect(getResult.body.taskLinks[0].linkType).to.equal(TaskLinkType.StartToFinish);
118+
expect(getResult.body.taskLinks[0].lag).to.equal(9600);
119+
expect(getResult.body.taskLinks[0].lagFormat).to.equal(TimeUnitType.Day);
120+
});
121+
});
122+
123+
describe("deleteTaskLink function", () => {
124+
it("should return response with code 200 and correct data", async () => {
125+
126+
const tasksApi = BaseTest.initializeTasksApi();
127+
const fileName = "NewProductDev.mpp";
128+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
129+
const remotePath = BaseTest.remoteBaseTestDataFolder;
130+
const remoteFullPath = remotePath + "/" + fileName;
131+
132+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
133+
134+
const deleteRequest = new DeleteTaskLinkRequest();
135+
deleteRequest.name = fileName;
136+
deleteRequest.folder = remotePath;
137+
deleteRequest.index = 1;
138+
139+
const deleteResult = await tasksApi.deleteTaskLink(deleteRequest);
140+
141+
expect(deleteResult.response.statusCode).to.equal(200);
142+
143+
const getRequest = new GetTaskLinksRequest();
144+
getRequest.name = fileName;
145+
getRequest.folder = remotePath;
146+
147+
const getResult = await tasksApi.getTaskLinks(getRequest);
148+
149+
expect(getResult.response.statusCode).to.equal(200);
150+
expect(getResult.body.taskLinks).is.not.undefined.and.not.null;
151+
expect(getResult.body.taskLinks.length).to.equal(23);
152+
});
153+
});

0 commit comments

Comments
 (0)