Skip to content

Commit 303cd1e

Browse files
[TASKSCLOUD-282] - Added tests for report endpoints.
1 parent 319f449 commit 303cd1e

File tree

4 files changed

+140
-32
lines changed

4 files changed

+140
-32
lines changed

test/calendarExceptionsTests.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ describe("postCalendarException function", () => {
8484
exception.daysOfWeek = [];
8585
exception.name = "Non-working day exception";
8686
exception.dayWorking = false;
87-
exception.fromDate = new Date(2014, 9, 27, 8);
88-
exception.toDate = new Date(2015, 7, 5, 8);
87+
exception.fromDate = new Date(Date.UTC(2014, 9, 27, 8));
88+
exception.toDate = new Date(Date.UTC(2015, 7, 5, 8));
8989
exception.occurrences = 10;
9090
exception.type = CalendarExceptionType.MonthlyByDay;
9191
exception.enteredByOccurrences = true;
@@ -134,17 +134,17 @@ describe("putCalendarException function", () => {
134134

135135
const exception = result1.body.calendarExceptions[0];
136136
const workingTime = new WorkingTime()
137-
workingTime.fromTime = new Date(10, 0, 1, 9, 8);
138-
workingTime.toTime = new Date(10, 0, 1, 17, 8);
137+
workingTime.fromTime = new Date(Date.UTC(10, 0, 1, 9, 8));
138+
workingTime.toTime = new Date(Date.UTC(10, 0, 1, 17, 8));
139139
exception.daysOfWeek = [ DayType.Thursday, DayType.Friday ];
140140
exception.workingTimes = [workingTime];
141141
exception.occurrences = 10;
142142
exception.enteredByOccurrences = true;
143143
exception.period = 1;
144144
exception.name = "Non-working day exception";
145145
exception.dayWorking = true;
146-
exception.fromDate = new Date(2014, 9, 27, 8);
147-
exception.toDate = new Date(2015, 7, 5, 8);
146+
exception.fromDate = new Date(Date.UTC(2014, 9, 27, 8));
147+
exception.toDate = new Date(Date.UTC(2015, 7, 5, 8));
148148

149149
const request2 = new PutCalendarExceptionRequest();
150150
request2.name = fileName;

test/calendarWorkWeeksTests.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ describe("getCalendarWorkWeeks function", () => {
6464
expect(workWeek.weekDays[0].dayWorking).is.true;
6565
expect(workWeek.weekDays[0].dayType).to.equal(DayType.Monday);
6666
expect(workWeek.weekDays[0].workingTimes.length).to.equal(1);
67-
expect(BaseTest.getTimeOnly(workWeek.weekDays[0].workingTimes[0].fromTime)).to.eql(new Date(0, 0, 0, 11, 30, 0));
68-
expect(BaseTest.getTimeOnly(workWeek.weekDays[0].workingTimes[0].toTime)).to.eql(new Date(0, 0, 0, 12, 30, 0));
67+
expect(BaseTest.getTimeOnly(workWeek.weekDays[0].workingTimes[0].fromTime)).to.eql(new Date(Date.UTC(0, 0, 0, 11, 30, 0)));
68+
expect(BaseTest.getTimeOnly(workWeek.weekDays[0].workingTimes[0].toTime)).to.eql(new Date(Date.UTC(0, 0, 0, 12, 30, 0)));
6969

7070
expect(workWeek.weekDays[1].dayWorking).is.false;
7171
expect(workWeek.weekDays[1].dayType).to.equal(DayType.Tuesday);
@@ -74,15 +74,15 @@ describe("getCalendarWorkWeeks function", () => {
7474
expect(workWeek.weekDays[2].dayWorking).is.true;
7575
expect(workWeek.weekDays[2].dayType).to.equal(DayType.Wednesday);
7676
expect(workWeek.weekDays[2].workingTimes.length).to.equal(2);
77-
expect(BaseTest.getTimeOnly(workWeek.weekDays[2].workingTimes[0].fromTime)).to.eql(new Date(0, 0, 0, 9, 30, 0));
78-
expect(BaseTest.getTimeOnly(workWeek.weekDays[2].workingTimes[0].toTime)).to.eql(new Date(0, 0, 0, 13, 23, 0));
79-
expect(BaseTest.getTimeOnly(workWeek.weekDays[2].workingTimes[1].fromTime)).to.eql(new Date(0, 0, 0, 14, 45, 0));
80-
expect(BaseTest.getTimeOnly(workWeek.weekDays[2].workingTimes[1].toTime)).to.eql(new Date(0, 0, 0, 18, 45, 0));
77+
expect(BaseTest.getTimeOnly(workWeek.weekDays[2].workingTimes[0].fromTime)).to.eql(new Date(Date.UTC(0, 0, 0, 9, 30, 0)));
78+
expect(BaseTest.getTimeOnly(workWeek.weekDays[2].workingTimes[0].toTime)).to.eql(new Date(Date.UTC(0, 0, 0, 13, 23, 0)));
79+
expect(BaseTest.getTimeOnly(workWeek.weekDays[2].workingTimes[1].fromTime)).to.eql(new Date(Date.UTC(0, 0, 0, 14, 45, 0)));
80+
expect(BaseTest.getTimeOnly(workWeek.weekDays[2].workingTimes[1].toTime)).to.eql(new Date(Date.UTC(0, 0, 0, 18, 45, 0)));
8181

8282
expect(workWeek.weekDays[3].dayWorking).is.true;
8383
expect(workWeek.weekDays[3].dayType).to.equal(DayType.Saturday);
8484
expect(workWeek.weekDays[3].workingTimes.length).to.equal(1);
85-
expect(BaseTest.getTimeOnly(workWeek.weekDays[3].workingTimes[0].fromTime)).to.eql(new Date(0, 0, 0, 9, 0, 0));
86-
expect(BaseTest.getTimeOnly(workWeek.weekDays[3].workingTimes[0].toTime)).to.eql(new Date(0, 0, 0, 10, 0, 0));
85+
expect(BaseTest.getTimeOnly(workWeek.weekDays[3].workingTimes[0].fromTime)).to.eql(new Date(Date.UTC(0, 0, 0, 9, 0, 0)));
86+
expect(BaseTest.getTimeOnly(workWeek.weekDays[3].workingTimes[0].toTime)).to.eql(new Date(Date.UTC(0, 0, 0, 10, 0, 0)));
8787
});
8888
})

test/calendarsTests.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ describe("postCalendar function", () => {
102102
secondDay.fromDate = new Date(0, 0, 0, 8);
103103
secondDay.toDate = new Date(0, 0, 0, 17);
104104
const firstWorkingTime = new WorkingTime()
105-
firstWorkingTime.fromTime = new Date(0, 0, 0, 8);
106-
firstWorkingTime.toTime = new Date(0, 0, 0, 13);
105+
firstWorkingTime.fromTime = new Date(Date.UTC(0, 0, 0, 8));
106+
firstWorkingTime.toTime = new Date(Date.UTC(0, 0, 0, 13));
107107
const secondWorkingTime = new WorkingTime()
108-
secondWorkingTime.fromTime = new Date(0, 0, 0, 14);
109-
secondWorkingTime.toTime = new Date(0, 0, 0, 17);
108+
secondWorkingTime.fromTime = new Date(Date.UTC(0, 0, 0, 14));
109+
secondWorkingTime.toTime = new Date(Date.UTC(0, 0, 0, 17));
110110
secondDay.workingTimes = [firstWorkingTime, secondWorkingTime];
111111
request1.calendar.days = [firstDay, secondDay];
112112
request1.calendar.isBaseCalendar = false;
@@ -130,10 +130,10 @@ describe("postCalendar function", () => {
130130
const monday = result2.body.calendar.days.find(d => d.dayType === DayType.Monday);
131131
expect(monday).is.not.null.and.not.undefined;
132132
expect(monday.workingTimes.length).to.equal(2);
133-
expect(BaseTest.getTimeOnly(monday.workingTimes[0].fromTime)).to.eql(BaseTest.getTimeOnly(new Date(0, 0, 0, 8)));
134-
expect(BaseTest.getTimeOnly(monday.workingTimes[0].toTime)).to.eql(BaseTest.getTimeOnly(new Date(0, 0, 0, 13)));
135-
expect(BaseTest.getTimeOnly(monday.workingTimes[1].fromTime)).to.eql(BaseTest.getTimeOnly(new Date(0, 0, 0, 14)));
136-
expect(BaseTest.getTimeOnly(monday.workingTimes[1].toTime)).to.eql(BaseTest.getTimeOnly(new Date(0, 0, 0, 17)));
133+
expect(BaseTest.getTimeOnly(monday.workingTimes[0].fromTime)).to.eql(BaseTest.getTimeOnly(firstWorkingTime.fromTime));
134+
expect(BaseTest.getTimeOnly(monday.workingTimes[0].toTime)).to.eql(BaseTest.getTimeOnly(firstWorkingTime.toTime));
135+
expect(BaseTest.getTimeOnly(monday.workingTimes[1].fromTime)).to.eql(BaseTest.getTimeOnly(secondWorkingTime.fromTime));
136+
expect(BaseTest.getTimeOnly(monday.workingTimes[1].toTime)).to.eql(BaseTest.getTimeOnly(secondWorkingTime.toTime));
137137
});
138138

139139
it("should return response with code 400 if workingTimes is empty for any working day", async () => {
@@ -198,14 +198,14 @@ describe("putCalendar function", () => {
198198
const secondDay = new WeekDay();
199199
secondDay.dayType = DayType.Monday;
200200
secondDay.dayWorking = true;
201-
secondDay.fromDate = new Date(0, 0, 0, 8);
202-
secondDay.toDate = new Date(0, 0, 0, 17);
201+
secondDay.fromDate = new Date(Date.UTC(0, 0, 0, 8));
202+
secondDay.toDate = new Date(Date.UTC(0, 0, 0, 17));
203203
const firstWorkingTime = new WorkingTime()
204-
firstWorkingTime.fromTime = new Date(0, 0, 0, 8);
205-
firstWorkingTime.toTime = new Date(0, 0, 0, 13);
204+
firstWorkingTime.fromTime = new Date(Date.UTC(0, 0, 0, 8));
205+
firstWorkingTime.toTime = new Date(Date.UTC(0, 0, 0, 13));
206206
const secondWorkingTime = new WorkingTime()
207-
secondWorkingTime.fromTime = new Date(0, 0, 0, 14);
208-
secondWorkingTime.toTime = new Date(0, 0, 0, 17);
207+
secondWorkingTime.fromTime = new Date(Date.UTC(0, 0, 0, 14));
208+
secondWorkingTime.toTime = new Date(Date.UTC(0, 0, 0, 17));
209209
secondDay.workingTimes = [firstWorkingTime, secondWorkingTime];
210210
request1.calendar.days = [firstDay, secondDay];
211211
request1.calendar.isBaseCalendar = false;
@@ -228,10 +228,10 @@ describe("putCalendar function", () => {
228228
const monday = result2.body.calendar.days.find(d => d.dayType === DayType.Monday);
229229
expect(monday).is.not.null.and.not.undefined;
230230
expect(monday.workingTimes.length).to.equal(2);
231-
expect(BaseTest.getTimeOnly(monday.workingTimes[0].fromTime)).to.eql(BaseTest.getTimeOnly(new Date(0, 0, 0, 8)));
232-
expect(BaseTest.getTimeOnly(monday.workingTimes[0].toTime)).to.eql(BaseTest.getTimeOnly(new Date(0, 0, 0, 13)));
233-
expect(BaseTest.getTimeOnly(monday.workingTimes[1].fromTime)).to.eql(BaseTest.getTimeOnly(new Date(0, 0, 0, 14)));
234-
expect(BaseTest.getTimeOnly(monday.workingTimes[1].toTime)).to.eql(BaseTest.getTimeOnly(new Date(0, 0, 0, 17)));
231+
expect(BaseTest.getTimeOnly(monday.workingTimes[0].fromTime)).to.eql(BaseTest.getTimeOnly(firstWorkingTime.fromTime));
232+
expect(BaseTest.getTimeOnly(monday.workingTimes[0].toTime)).to.eql(BaseTest.getTimeOnly(firstWorkingTime.toTime));
233+
expect(BaseTest.getTimeOnly(monday.workingTimes[1].fromTime)).to.eql(BaseTest.getTimeOnly(secondWorkingTime.fromTime));
234+
expect(BaseTest.getTimeOnly(monday.workingTimes[1].toTime)).to.eql(BaseTest.getTimeOnly(secondWorkingTime.toTime));
235235
});
236236
});
237237

test/reportTests.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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 { GetReportPdfRequest, ReportType, GetCriticalPathRequest, GetRiskAnalysisReportRequest, ProbabilityDistributionType, ConfidenceLevel } from "../src/model/model";
29+
import * as BaseTest from "./baseTest";
30+
31+
describe("getReportPdf 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 GetReportPdfRequest();
43+
request.name = fileName;
44+
request.folder = remotePath;
45+
request.type = ReportType.Milestones;
46+
47+
const result = await tasksApi.getReportPdf(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("%PDF-1.5");
54+
});
55+
});
56+
57+
describe("getCriticalPath function", () => {
58+
it("should return response with code 200 and correct data", async () => {
59+
60+
const tasksApi = BaseTest.initializeTasksApi();
61+
const fileName = "Home_move_plan.mpp";
62+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
63+
const remotePath = BaseTest.remoteBaseTestDataFolder;
64+
const remoteFullPath = remotePath + "/" + fileName;
65+
66+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
67+
68+
const request = new GetCriticalPathRequest();
69+
request.name = fileName;
70+
request.folder = remotePath;
71+
72+
const result = await tasksApi.getCriticalPath(request);
73+
74+
expect(result.response.statusCode).to.equal(200);
75+
expect(result.body.tasks.taskItem.length).to.equal(76);
76+
});
77+
});
78+
79+
describe("getRiskAnalysisReport function", () => {
80+
it("should return response with code 200 and correct data", async () => {
81+
82+
const tasksApi = BaseTest.initializeTasksApi();
83+
const fileName = "Home_move_plan.mpp";
84+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
85+
const remotePath = BaseTest.remoteBaseTestDataFolder;
86+
const remoteFullPath = remotePath + "/" + fileName;
87+
88+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
89+
90+
const request = new GetRiskAnalysisReportRequest();
91+
request.name = fileName;
92+
request.folder = remotePath;
93+
request.distributionType = ProbabilityDistributionType.Normal;
94+
request.confidenceLevel = ConfidenceLevel.CL85;
95+
request.optimistic = 80;
96+
request.pessimistic = 130;
97+
request.iterations = 200;
98+
request.taskUid = 1;
99+
100+
const result = await tasksApi.getRiskAnalysisReport(request);
101+
102+
expect(result.response.statusCode).to.equal(200);
103+
expect(result.body.buffer).is.not.undefined.and.not.null;
104+
105+
const strings = BaseTest.convertArrayBufferToStrings(result.body.buffer);
106+
expect(strings[0]).to.equal("%PDF-1.5");
107+
});
108+
});

0 commit comments

Comments
 (0)