@asposecloud/aspose-tasks-cloud
Version:
Aspose.Tasks Cloud SDK for Node.js
198 lines (194 loc) • 11.9 kB
JavaScript
"use strict";
/*
* MIT License
* Copyright (c) 2019 Aspose Pty Ltd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
require("mocha");
const model_1 = require("../src/model/model");
const BaseTest = require("./baseTest");
describe("getCalendarExceptions function", () => {
it("should return response with code 200 and correct data", () => __awaiter(void 0, void 0, void 0, function* () {
const tasksApi = BaseTest.initializeTasksApi();
const fileName = "Calenar_with_exception.mpp";
const localPath = BaseTest.localBaseTestDataFolder + fileName;
const remotePath = BaseTest.remoteBaseTestDataFolder;
const remoteFullPath = remotePath + "/" + fileName;
yield tasksApi.uploadFileToStorage(remoteFullPath, localPath);
const request = new model_1.GetCalendarExceptionsRequest();
request.name = fileName;
request.folder = remotePath;
request.calendarUid = 1;
const result = yield tasksApi.getCalendarExceptions(request);
chai_1.expect(result.response.statusCode).to.equal(200);
chai_1.expect(result.body.calendarExceptions).is.not.undefined.and.not.null;
chai_1.expect(result.body.calendarExceptions.length).to.equal(1);
const calendarException = result.body.calendarExceptions[0];
chai_1.expect(calendarException.dayWorking).is.true;
chai_1.expect(calendarException.daysOfWeek).to.eql([model_1.DayType.Monday]);
chai_1.expect(calendarException.fromDate).to.eql(new Date(2018, 1, 13));
chai_1.expect(calendarException.toDate).to.eql(new Date(2018, 3, 9, 23, 59));
chai_1.expect(calendarException.month).to.eql(model_1.Month.Undefined);
chai_1.expect(calendarException.monthItem).to.eql(model_1.MonthItemType.Undefined);
chai_1.expect(calendarException.monthPosition).to.eql(model_1.MonthPosition.Undefined);
chai_1.expect(calendarException.type).to.eql(model_1.CalendarExceptionType.Weekly);
chai_1.expect(calendarException.occurrences).to.eql(8);
chai_1.expect(calendarException.period).to.eql(1);
chai_1.expect(calendarException.workingTimes.length).to.eql(2);
chai_1.expect(BaseTest.getTimeOnly(calendarException.workingTimes[0].fromTime)).to.eql(new Date(0, 0, 0, 13, 2, 33));
chai_1.expect(BaseTest.getTimeOnly(calendarException.workingTimes[0].toTime)).to.eql(new Date(0, 0, 0, 16, 36, 33));
chai_1.expect(BaseTest.getTimeOnly(calendarException.workingTimes[1].fromTime)).to.eql(new Date(0, 0, 0, 19, 13, 33));
chai_1.expect(BaseTest.getTimeOnly(calendarException.workingTimes[1].toTime)).to.eql(new Date(0, 0, 0, 21, 32, 33));
}));
});
describe("postCalendarException function", () => {
it("should return response with code 200 and correct data", () => __awaiter(void 0, void 0, void 0, function* () {
const tasksApi = BaseTest.initializeTasksApi();
const fileName = "New_project_2013.mpp";
const localPath = BaseTest.localBaseTestDataFolder + fileName;
const remotePath = BaseTest.remoteBaseTestDataFolder;
const remoteFullPath = remotePath + "/" + fileName;
yield tasksApi.uploadFileToStorage(remoteFullPath, localPath);
const exception = new model_1.CalendarException();
exception.workingTimes = [];
exception.daysOfWeek = [];
exception.name = "Non-working day exception";
exception.dayWorking = false;
exception.fromDate = new Date(Date.UTC(2014, 9, 27, 8));
exception.toDate = new Date(Date.UTC(2015, 7, 5, 8));
exception.occurrences = 10;
exception.type = model_1.CalendarExceptionType.MonthlyByDay;
exception.enteredByOccurrences = true;
exception.monthDay = 5;
exception.period = 1;
const request1 = new model_1.PostCalendarExceptionRequest();
request1.name = fileName;
request1.folder = remotePath;
request1.calendarUid = 1;
request1.calendarException = exception;
const result1 = yield tasksApi.postCalendarException(request1);
chai_1.expect(result1.body.code).to.equal(201);
const request2 = new model_1.GetCalendarExceptionsRequest();
request2.name = fileName;
request2.folder = remotePath;
request2.calendarUid = 1;
const result2 = yield tasksApi.getCalendarExceptions(request2);
chai_1.expect(result2.response.statusCode).to.equal(200);
chai_1.expect(result2.body.calendarExceptions).is.not.undefined.and.not.null;
chai_1.expect(result2.body.calendarExceptions.length).to.equal(1);
assertCalendarExceptionsAreEqual(exception, result2.body.calendarExceptions[0]);
}));
});
describe("putCalendarException function", () => {
it("should return response with code 200 and correct data", () => __awaiter(void 0, void 0, void 0, function* () {
const tasksApi = BaseTest.initializeTasksApi();
const fileName = "Calenar_with_exception.mpp";
const localPath = BaseTest.localBaseTestDataFolder + fileName;
const remotePath = BaseTest.remoteBaseTestDataFolder;
const remoteFullPath = remotePath + "/" + fileName;
yield tasksApi.uploadFileToStorage(remoteFullPath, localPath);
const request1 = new model_1.GetCalendarExceptionsRequest();
request1.name = fileName;
request1.folder = remotePath;
request1.calendarUid = 1;
let result1 = yield tasksApi.getCalendarExceptions(request1);
chai_1.expect(result1.response.statusCode).to.equal(200);
const exception = result1.body.calendarExceptions[0];
const workingTime = new model_1.WorkingTime();
workingTime.fromTime = new Date(Date.UTC(10, 0, 1, 9, 8));
workingTime.toTime = new Date(Date.UTC(10, 0, 1, 17, 8));
exception.daysOfWeek = [model_1.DayType.Thursday, model_1.DayType.Friday];
exception.workingTimes = [workingTime];
exception.occurrences = 10;
exception.enteredByOccurrences = true;
exception.period = 1;
exception.name = "Non-working day exception";
exception.dayWorking = true;
exception.fromDate = new Date(Date.UTC(2014, 9, 27, 8));
exception.toDate = new Date(Date.UTC(2015, 7, 5, 8));
const request2 = new model_1.PutCalendarExceptionRequest();
request2.name = fileName;
request2.folder = remotePath;
request2.calendarUid = 1;
request2.index = exception.index;
request2.calendarException = exception;
const result2 = yield tasksApi.putCalendarException(request2);
chai_1.expect(result2.body.code).to.equal(200);
result1 = yield tasksApi.getCalendarExceptions(request1);
chai_1.expect(result1.body.code).to.equal(200);
chai_1.expect(result1.body.calendarExceptions).is.not.undefined.and.not.null;
chai_1.expect(result1.body.calendarExceptions.length).to.equal(1);
assertCalendarExceptionsAreEqual(exception, result1.body.calendarExceptions[0]);
}));
});
describe("deleteCalendarExceptions function", () => {
it("should return response with code 200 and correct data", () => __awaiter(void 0, void 0, void 0, function* () {
const tasksApi = BaseTest.initializeTasksApi();
const fileName = "Calenar_with_exception.mpp";
const localPath = BaseTest.localBaseTestDataFolder + fileName;
const remotePath = BaseTest.remoteBaseTestDataFolder;
const remoteFullPath = remotePath + "/" + fileName;
yield tasksApi.uploadFileToStorage(remoteFullPath, localPath);
const request1 = new model_1.DeleteCalendarExceptionRequest();
request1.name = fileName;
request1.folder = remotePath;
request1.calendarUid = 1;
request1.index = 1;
const result1 = yield tasksApi.deleteCalendarException(request1);
chai_1.expect(result1.response.statusCode).to.equal(200);
const request2 = new model_1.GetCalendarExceptionsRequest();
request2.name = fileName;
request2.folder = remotePath;
request2.calendarUid = 1;
const result2 = yield tasksApi.getCalendarExceptions(request2);
chai_1.expect(result2.response.statusCode).to.equal(200);
chai_1.expect(result2.body.calendarExceptions).is.not.undefined.and.not.null;
chai_1.expect(result2.body.calendarExceptions.length).to.equal(0);
}));
});
function assertCalendarExceptionsAreEqual(actual, expected) {
chai_1.expect(actual.name).to.equal(expected.name);
chai_1.expect(actual.dayWorking).to.equal(expected.dayWorking);
chai_1.expect(actual.enteredByOccurrences).to.equal(expected.enteredByOccurrences);
chai_1.expect(BaseTest.getDateOnly(actual.fromDate)).to.eql(BaseTest.getDateOnly(expected.fromDate));
chai_1.expect(actual.monthDay).to.equal(expected.monthDay);
chai_1.expect(actual.occurrences).to.equal(expected.occurrences);
chai_1.expect(actual.period).to.equal(expected.period);
chai_1.expect(BaseTest.getDateOnly(actual.toDate)).to.eql(BaseTest.getDateOnly(expected.toDate));
chai_1.expect(actual.type).to.equal(expected.type);
chai_1.expect(actual.workingTimes.length).to.equal(expected.workingTimes.length);
for (let i = 0; i < actual.workingTimes.length; i++) {
chai_1.expect(BaseTest.getTimeOnly(actual.workingTimes[i].fromTime)).to.eql(BaseTest.getTimeOnly(expected.workingTimes[i].fromTime));
chai_1.expect(BaseTest.getTimeOnly(actual.workingTimes[i].toTime)).to.eql(BaseTest.getTimeOnly(expected.workingTimes[i].toTime));
}
chai_1.expect(actual.daysOfWeek.length).to.equal(expected.daysOfWeek.length);
for (let i = 0; i < actual.daysOfWeek.length; i++) {
chai_1.expect(actual.daysOfWeek[i]).to.equal(expected.daysOfWeek[i]);
}
}
//# sourceMappingURL=calendarExceptionsTests.js.map