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 { GetTaskRecurringInfoRequest , RecurrencePattern , WeekDayType , OrdinalNumber , PutTaskRecurringInfoRequest , PostTaskRecurringInfoRequest , RecurringInfo , GetTaskRequest } from "../src/model/model" ;
29
+ import * as BaseTest from "./baseTest" ;
30
+
31
+ describe ( "getTaskRecurringInfo function" , ( ) => {
32
+ it ( "should return response with code 200 and correct data" , async ( ) => {
33
+
34
+ const tasksApi = BaseTest . initializeTasksApi ( ) ;
35
+ const fileName = "sample.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 GetTaskRecurringInfoRequest ( ) ;
43
+ request . name = fileName ;
44
+ request . folder = remotePath ;
45
+ request . taskUid = 6 ;
46
+
47
+ const result = await tasksApi . getTaskRecurringInfo ( request ) ;
48
+
49
+ expect ( result . response . statusCode ) . to . equal ( 200 ) ;
50
+ expect ( result . body . recurringInfo ) . is . not . undefined . and . not . null ;
51
+
52
+ const entity = result . body . recurringInfo ;
53
+ expect ( entity . occurrences ) . to . equal ( 2 ) ;
54
+ expect ( entity . recurrencePattern ) . to . equal ( RecurrencePattern . Monthly ) ;
55
+ expect ( entity . useEndDate ) . to . equal ( true ) ;
56
+ expect ( entity . monthlyUseOrdinalDay ) . to . equal ( false ) ;
57
+ expect ( entity . monthlyDay ) . to . equal ( 1 ) ;
58
+ expect ( entity . weeklyDays ) . to . equal ( WeekDayType . None ) ;
59
+ expect ( entity . yearlyOrdinalNumber ) . to . equal ( OrdinalNumber . Second ) ;
60
+ } ) ;
61
+ } ) ;
62
+
63
+ describe ( "putTaskRecurringInfo function" , ( ) => {
64
+ it ( "should return response with code 200 and correct data" , async ( ) => {
65
+
66
+ const tasksApi = BaseTest . initializeTasksApi ( ) ;
67
+ const fileName = "sample.mpp" ;
68
+ const localPath = BaseTest . localBaseTestDataFolder + fileName ;
69
+ const remotePath = BaseTest . remoteBaseTestDataFolder ;
70
+ const remoteFullPath = remotePath + "/" + fileName ;
71
+
72
+ await tasksApi . uploadFileToStorage ( remoteFullPath , localPath ) ;
73
+
74
+ const getRequest = new GetTaskRecurringInfoRequest ( ) ;
75
+ getRequest . name = fileName ;
76
+ getRequest . folder = remotePath ;
77
+ getRequest . taskUid = 6 ;
78
+
79
+ let getResult = await tasksApi . getTaskRecurringInfo ( getRequest ) ;
80
+
81
+ expect ( getResult . response . statusCode ) . to . equal ( 200 ) ;
82
+ expect ( getResult . body . recurringInfo ) . is . not . undefined . and . not . null ;
83
+
84
+ const recurringInfo = getResult . body . recurringInfo ;
85
+ recurringInfo . occurrences = 10 ;
86
+ const putRequest = new PutTaskRecurringInfoRequest ( ) ;
87
+ putRequest . name = fileName ;
88
+ putRequest . folder = remotePath ;
89
+ putRequest . taskUid = 6 ;
90
+ putRequest . recurringInfo = recurringInfo ;
91
+
92
+ const putResult = await tasksApi . putTaskRecurringInfo ( putRequest ) ;
93
+
94
+ expect ( putResult . response . statusCode ) . to . equal ( 200 ) ;
95
+
96
+ getResult = await tasksApi . getTaskRecurringInfo ( getRequest ) ;
97
+
98
+ const entity = getResult . body . recurringInfo ;
99
+ expect ( entity . occurrences ) . to . equal ( 10 ) ;
100
+ expect ( entity . recurrencePattern ) . to . equal ( RecurrencePattern . Monthly ) ;
101
+ expect ( entity . useEndDate ) . to . equal ( true ) ;
102
+ expect ( entity . monthlyUseOrdinalDay ) . to . equal ( false ) ;
103
+ expect ( entity . monthlyDay ) . to . equal ( 1 ) ;
104
+ expect ( entity . weeklyDays ) . to . equal ( WeekDayType . None ) ;
105
+ expect ( entity . yearlyOrdinalNumber ) . to . equal ( OrdinalNumber . Second ) ;
106
+ } ) ;
107
+ } ) ;
108
+
109
+ describe ( "postTaskRecurringInfo function" , ( ) => {
110
+ it ( "should return response with code 200 and correct data" , async ( ) => {
111
+
112
+ const tasksApi = BaseTest . initializeTasksApi ( ) ;
113
+ const fileName = "sample.mpp" ;
114
+ const localPath = BaseTest . localBaseTestDataFolder + fileName ;
115
+ const remotePath = BaseTest . remoteBaseTestDataFolder ;
116
+ const remoteFullPath = remotePath + "/" + fileName ;
117
+
118
+ await tasksApi . uploadFileToStorage ( remoteFullPath , localPath ) ;
119
+
120
+ const recurringInfo = new RecurringInfo ( ) ;
121
+ recurringInfo . recurrencePattern = RecurrencePattern . Weekly ;
122
+ recurringInfo . occurrences = 4 ;
123
+ recurringInfo . weeklyRepetitions = 3 ;
124
+ recurringInfo . weeklyDays = WeekDayType . Thursday ;
125
+ recurringInfo . startDate = new Date ( Date . UTC ( 2018 , 0 , 1 , 8 , 0 , 0 ) ) ;
126
+ recurringInfo . endDate = new Date ( Date . UTC ( 2018 , 11 , 31 ) ) ;
127
+ recurringInfo . useEndDate = true ;
128
+ const postRequest = new PostTaskRecurringInfoRequest ( ) ;
129
+ postRequest . name = fileName ;
130
+ postRequest . folder = remotePath ;
131
+ postRequest . recurringInfo = recurringInfo ;
132
+ postRequest . parentTaskUid = 0 ;
133
+ postRequest . taskName = "New recurring task" ;
134
+ postRequest . calendarName = "Standard" ;
135
+
136
+ const postResult = await tasksApi . postTaskRecurringInfo ( postRequest ) ;
137
+
138
+ expect ( postResult . body . code ) . to . equal ( 201 ) ;
139
+ expect ( postResult . body . taskItem ) . is . not . undefined . and . not . null ;
140
+
141
+ let getRequest = new GetTaskRequest ( ) ;
142
+ getRequest . name = fileName ;
143
+ getRequest . folder = remotePath ;
144
+ getRequest . taskUid = postResult . body . taskItem . uid ;
145
+
146
+ let getResult = await tasksApi . getTask ( getRequest ) ;
147
+
148
+ expect ( getResult . response . statusCode ) . to . equal ( 200 ) ;
149
+ expect ( getResult . body . task . subtasksUids . length ) . to . equal ( 18 ) ;
150
+
151
+ getRequest = new GetTaskRequest ( ) ;
152
+ getRequest . name = fileName ;
153
+ getRequest . folder = remotePath ;
154
+ getRequest . taskUid = Math . max ( ...getResult . body . task . subtasksUids ) ;
155
+
156
+ getResult = await tasksApi . getTask ( getRequest ) ;
157
+
158
+ expect ( getResult . body . task . start ) . to . eql ( new Date ( 2018 , 11 , 27 , 8 , 0 , 0 ) ) ;
159
+ } ) ;
160
+ } ) ;
0 commit comments