Skip to content

Commit 586a9b5

Browse files
[TASKSCLOUD-285] - Added tests for tasks, timephased data, vba and wbs endpoints.
1 parent 2fe2718 commit 586a9b5

File tree

5 files changed

+592
-12
lines changed

5 files changed

+592
-12
lines changed

src/internal/objectSerializer.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,30 @@ export class ObjectSerializer {
118118
for (const index in attributeTypes) {
119119
if (attributeTypes.hasOwnProperty(index)) {
120120
const attributeType = attributeTypes[index];
121-
if(data.hasOwnProperty(attributeType.baseName)) { // if baseName is pascalCase
122-
instance[attributeType.name] = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type);
123-
continue;
124-
}
125-
126-
const baseName = this.firstCharAsUpperCase(attributeType.baseName);
127-
if (data.hasOwnProperty(baseName)) {
128-
const type = this.firstCharAsUpperCase(attributeType.type);
129-
instance[attributeType.name] = ObjectSerializer.deserialize(data[baseName], type);
121+
const baseName = this.GetPropertyCaseInsensitive(data, attributeType.baseName)
122+
if(baseName != null) {
123+
instance[attributeType.name] = ObjectSerializer.deserialize(data[baseName], attributeType.type);
130124
}
131125
}
132126
}
133127
return instance;
134128
}
135129
}
136-
137-
private static firstCharAsUpperCase(string: string) {
138-
return string.substring(0,1).toUpperCase() + string.substring(1);
130+
131+
private static GetPropertyCaseInsensitive(obj: any, property: string): string {
132+
let props :string[]= [];
133+
for (var i in obj) {
134+
if (obj.hasOwnProperty(i)) {
135+
props.push(i);
136+
}
137+
}
138+
let prop: string;
139+
while (prop = props.pop()) {
140+
if (prop.toLowerCase() === property.toLowerCase()) {
141+
return prop;
142+
}
143+
}
144+
return null;
139145
}
140146

141147
private static findCorrectType(data: any, expectedType: string) {

test/tasksTests.ts

Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
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 { GetTasksRequest, GetTaskRequest, DeleteTaskRequest, PostTaskRequest, PutTaskRequest, CalculationMode, GetTaskAssignmentsRequest, PutMoveTaskRequest, PutMoveTaskToSiblingRequest } from "../src/model/model";
29+
import * as BaseTest from "./baseTest";
30+
31+
describe("getTasks function", () => {
32+
it("should return response with code 200 and correct data", async () => {
33+
34+
const tasksApi = BaseTest.initializeTasksApi();
35+
const fileName = "Project2016.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 GetTasksRequest();
43+
request.name = fileName;
44+
request.folder = remotePath;
45+
46+
const result = await tasksApi.getTasks(request);
47+
48+
expect(result.response.statusCode).to.equal(200);
49+
expect(result.body.tasks).is.not.undefined.and.not.null;
50+
expect(result.body.tasks.taskItem.length).to.equal(6);
51+
52+
const firstTask = result.body.tasks.taskItem.find(t => t.uid == 5);
53+
expect(firstTask).is.not.undefined.and.not.null;
54+
expect(firstTask.name).to.equal("Summary Task 1");
55+
expect(firstTask.start).to.eql(new Date(2015, 7, 3, 8, 0, 0));
56+
expect(firstTask.finish).to.eql(new Date(2015, 7, 6, 17, 0, 0));
57+
expect(firstTask.link.href).to.eql("/5");
58+
});
59+
});
60+
61+
describe("getTask function", () => {
62+
it("should return response with code 200 and correct data", async () => {
63+
64+
const tasksApi = BaseTest.initializeTasksApi();
65+
const fileName = "Project2016.mpp";
66+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
67+
const remotePath = BaseTest.remoteBaseTestDataFolder;
68+
const remoteFullPath = remotePath + "/" + fileName;
69+
70+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
71+
72+
const request = new GetTaskRequest();
73+
request.name = fileName;
74+
request.folder = remotePath;
75+
request.taskUid = 5;
76+
77+
const result = await tasksApi.getTask(request);
78+
79+
expect(result.response.statusCode).to.equal(200);
80+
expect(result.body.task).is.not.undefined.and.not.null;
81+
expect(result.body.task.uid).to.equal(5);
82+
expect(result.body.task.subtasksUids).to.eql([1, 2, 3, 4]);
83+
expect(result.body.task.name).to.equal("Summary Task 1");
84+
expect(result.body.task.start).to.eql(new Date(2015, 7, 3, 8, 0, 0));
85+
expect(result.body.task.finish).to.eql(new Date(2015, 7, 6, 17, 0, 0));
86+
expect(result.body.task.remainingWork).to.equal("1.08:00:00");
87+
expect(result.body.task.workVariance).to.equal(1920);
88+
});
89+
});
90+
91+
describe("deleteTask function", () => {
92+
it("should return response with code 200 and correct data", async () => {
93+
94+
const tasksApi = BaseTest.initializeTasksApi();
95+
const fileName = "Project2016.mpp";
96+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
97+
const remotePath = BaseTest.remoteBaseTestDataFolder;
98+
const remoteFullPath = remotePath + "/" + fileName;
99+
100+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
101+
102+
const deleteRequest = new DeleteTaskRequest();
103+
deleteRequest.name = fileName;
104+
deleteRequest.folder = remotePath;
105+
deleteRequest.taskUid = 4;
106+
107+
const deleteResult = await tasksApi.deleteTask(deleteRequest);
108+
109+
expect(deleteResult.response.statusCode).to.equal(200);
110+
111+
const getRequest = new GetTasksRequest();
112+
getRequest.name = fileName;
113+
getRequest.folder = remotePath;
114+
115+
const getResult = await tasksApi.getTasks(getRequest);
116+
117+
expect(getResult.response.statusCode).to.equal(200);
118+
expect(getResult.body.tasks).is.not.undefined.and.not.null;
119+
expect(getResult.body.tasks.taskItem.length).to.equal(5);
120+
121+
const task = getResult.body.tasks.taskItem.find(t => t.uid == 4);
122+
expect(task).is.undefined;
123+
});
124+
});
125+
126+
describe("postTask function", () => {
127+
it("should return response with code 200 and correct data", async () => {
128+
129+
const tasksApi = BaseTest.initializeTasksApi();
130+
const fileName = "Project2016.mpp";
131+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
132+
const remotePath = BaseTest.remoteBaseTestDataFolder;
133+
const remoteFullPath = remotePath + "/" + fileName;
134+
135+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
136+
137+
const postRequest = new PostTaskRequest();
138+
postRequest.name = fileName;
139+
postRequest.folder = remotePath;
140+
postRequest.beforeTaskId = 4;
141+
postRequest.taskName = "New task name";
142+
143+
const postResult = await tasksApi.postTask(postRequest);
144+
145+
expect(postResult.body.code).to.equal(201);
146+
expect(postResult.body.taskItem).is.not.undefined.and.not.null;
147+
148+
const getRequest = new GetTaskRequest();
149+
getRequest.name = fileName;
150+
getRequest.folder = remotePath;
151+
getRequest.taskUid = postResult.body.taskItem.uid;
152+
153+
const getResult = await tasksApi.getTask(getRequest);
154+
155+
expect(getResult.response.statusCode).to.equal(200);
156+
expect(getResult.body.task).is.not.undefined.and.not.null;
157+
});
158+
});
159+
160+
describe("putTask function", () => {
161+
it("should return response with code 200 and correct data", async () => {
162+
163+
const tasksApi = BaseTest.initializeTasksApi();
164+
const fileName = "Project2016.mpp";
165+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
166+
const remotePath = BaseTest.remoteBaseTestDataFolder;
167+
const remoteFullPath = remotePath + "/" + fileName;
168+
169+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
170+
171+
const getRequest = new GetTaskRequest();
172+
getRequest.name = fileName;
173+
getRequest.folder = remotePath;
174+
getRequest.taskUid = 4;
175+
176+
let getResult = await tasksApi.getTask(getRequest);
177+
178+
const task = getResult.body.task;
179+
task.name = "Modified task name";
180+
task.isManual = true;
181+
task.manualStart = new Date(Date.UTC(2015, 9, 1, 9, 15, 0));
182+
task.manualFinish = new Date(Date.UTC(2015, 9, 1, 17, 15, 0));
183+
184+
const putRequest = new PutTaskRequest();
185+
putRequest.name = fileName;
186+
putRequest.folder = remotePath;
187+
putRequest.taskUid = 4;
188+
putRequest.recalculate = false;
189+
putRequest.mode = CalculationMode.None;
190+
putRequest.task = task;
191+
192+
const putResult = await tasksApi.putTask(putRequest);
193+
194+
expect(putResult.body.code).to.equal(200);
195+
196+
getResult = await tasksApi.getTask(getRequest);
197+
198+
expect(getResult.response.statusCode).to.equal(200);
199+
expect(getResult.body.task).is.not.undefined.and.not.null;
200+
expect(getResult.body.task.name).to.equal("Modified task name");
201+
expect(getResult.body.task.isManual).is.true;
202+
expect(getResult.body.task.manualStart).to.eql(new Date(2015, 9, 1, 9, 15, 0));
203+
expect(getResult.body.task.manualFinish).to.eql(new Date(2015, 9, 1, 17, 15, 0));
204+
});
205+
});
206+
207+
describe("getTaskAssignments function", () => {
208+
it("should return response with code 200 and correct data", async () => {
209+
210+
const tasksApi = BaseTest.initializeTasksApi();
211+
const fileName = "Home_move_plan.mpp";
212+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
213+
const remotePath = BaseTest.remoteBaseTestDataFolder;
214+
const remoteFullPath = remotePath + "/" + fileName;
215+
216+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
217+
218+
const request = new GetTaskAssignmentsRequest();
219+
request.name = fileName;
220+
request.folder = remotePath;
221+
request.taskUid = 1;
222+
223+
const result = await tasksApi.getTaskAssignments(request);
224+
225+
expect(result.response.statusCode).to.equal(200);
226+
expect(result.body.assignments).is.not.undefined.and.not.null;
227+
});
228+
});
229+
230+
describe("putMoveTask function", () => {
231+
it("should return response with code 200 and correct data", async () => {
232+
233+
const tasksApi = BaseTest.initializeTasksApi();
234+
const fileName = "sample.mpp";
235+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
236+
const remotePath = BaseTest.remoteBaseTestDataFolder;
237+
const remoteFullPath = remotePath + "/" + fileName;
238+
239+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
240+
241+
const getRequest = new GetTaskRequest();
242+
getRequest.name = fileName;
243+
getRequest.folder = remotePath;
244+
getRequest.taskUid = 6;
245+
246+
let getResult = await tasksApi.getTask(getRequest);
247+
248+
expect(getResult.response.statusCode).to.equal(200);
249+
expect(getResult.body.task.subtasksUids.find(t => t == 10)).is.undefined;
250+
251+
const putMoveRequest = new PutMoveTaskRequest();
252+
putMoveRequest.name = fileName;
253+
putMoveRequest.folder = remotePath;
254+
putMoveRequest.parentTaskUid = 6;
255+
putMoveRequest.taskUid = 10;
256+
257+
const putMoveResult = await tasksApi.putMoveTask(putMoveRequest);
258+
259+
expect(putMoveResult.body.code).to.equal(200);
260+
261+
getResult = await tasksApi.getTask(getRequest);
262+
263+
expect(getResult.response.statusCode).to.equal(200);
264+
expect(getResult.body.task.subtasksUids.find(t => t == 10)).is.not.undefined.and.not.null;
265+
});
266+
});
267+
268+
describe("putMoveTaskToSibling function", () => {
269+
it("should return response with code 200 and correct data", async () => {
270+
271+
const tasksApi = BaseTest.initializeTasksApi();
272+
const fileName = "NewProductDev.mpp";
273+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
274+
const remotePath = BaseTest.remoteBaseTestDataFolder;
275+
const remoteFullPath = remotePath + "/" + fileName;
276+
277+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
278+
279+
const putMoveToSiblingRequest = new PutMoveTaskToSiblingRequest();
280+
putMoveToSiblingRequest.name = fileName;
281+
putMoveToSiblingRequest.folder = remotePath;
282+
putMoveToSiblingRequest.beforeTaskUid = 41;
283+
putMoveToSiblingRequest.taskUid = 40;
284+
285+
const putMoveToSiblingResult = await tasksApi.putMoveTaskToSibling(putMoveToSiblingRequest);
286+
287+
expect(putMoveToSiblingResult.body.code).to.equal(200);
288+
289+
const getRequest = new GetTaskRequest();
290+
getRequest.name = fileName;
291+
getRequest.folder = remotePath;
292+
getRequest.taskUid = 38;
293+
294+
const getResult = await tasksApi.getTask(getRequest);
295+
296+
expect(getResult.response.statusCode).to.equal(200);
297+
expect(getResult.body.task.subtasksUids).to.eql([39, 40, 41]);;
298+
});
299+
it("should return response with code 404 if input uid is not found", async () => {
300+
301+
const tasksApi = BaseTest.initializeTasksApi();
302+
const fileName = "NewProductDev.mpp";
303+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
304+
const remotePath = BaseTest.remoteBaseTestDataFolder;
305+
const remoteFullPath = remotePath + "/" + fileName;
306+
307+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
308+
309+
const putMoveToSiblingRequest = new PutMoveTaskToSiblingRequest();
310+
putMoveToSiblingRequest.name = fileName;
311+
putMoveToSiblingRequest.folder = remotePath;
312+
putMoveToSiblingRequest.beforeTaskUid = -1;
313+
putMoveToSiblingRequest.taskUid = 99999;
314+
315+
try{
316+
expect(await tasksApi.putMoveTaskToSibling(putMoveToSiblingRequest)).throw();
317+
} catch (e) {
318+
expect(e.message).to.equal("Not Found");
319+
expect(e.response.body.Error.Code).to.equal("TaskDoesntExist");
320+
expect(e.response.body.Error.Message).to.equal("Task with 99999 Uid doesn't exist");
321+
}
322+
});
323+
});

0 commit comments

Comments
 (0)