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