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 { PutImportProjectFromFileRequest , ImportedProjectType , ProjectFileFormat , GetTasksRequest , PutImportProjectFromDbRequest , ProjectDatabaseType , GetProjectIdsRequest , PutImportProjectFromProjectOnlineRequest , DownloadFileRequest } from "../src/model/model" ;
29
+ import * as BaseTest from "./baseTest" ;
30
+
31
+ describe ( "putImportProjectFromFile function" , ( ) => {
32
+ it ( "should return response with code 200 and correct data" , async ( ) => {
33
+
34
+ const tasksApi = BaseTest . initializeTasksApi ( ) ;
35
+ const fileName = "p6_multiproject.xml" ;
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 request1 = new PutImportProjectFromFileRequest ( ) ;
43
+ request1 . name = fileName ;
44
+ request1 . folder = remotePath ;
45
+ request1 . filename = "imported_from_primavera.xml" ;
46
+ request1 . projectUid = "111" ;
47
+ request1 . fileType = ImportedProjectType . PrimaveraXml ;
48
+ request1 . outputFileFormat = ProjectFileFormat . P6xml
49
+
50
+ const result1 = await tasksApi . putImportProjectFromFile ( request1 ) ;
51
+
52
+ expect ( result1 . response . statusCode ) . to . equal ( 200 ) ;
53
+
54
+ const request2 = new GetTasksRequest ( ) ;
55
+ request2 . name = "imported_from_primavera.xml" ;
56
+ request2 . folder = remotePath ;
57
+
58
+ const result2 = await tasksApi . getTasks ( request2 ) ;
59
+
60
+ expect ( result2 . response . statusCode ) . to . equal ( 200 ) ;
61
+ expect ( result2 . body . tasks . taskItem . length ) . to . equal ( 12 ) ;
62
+ } ) ;
63
+ } ) ;
64
+
65
+ describe . skip ( "Ignored because real credentials is required" , ( ) => {
66
+ describe ( "putImportProjectFromDb function" , ( ) => {
67
+ it ( "should return response with code 200 and correct data" , async ( ) => {
68
+
69
+ const tasksApi = BaseTest . initializeTasksApi ( ) ;
70
+ const request1 = new PutImportProjectFromDbRequest ( ) ;
71
+ request1 . connectionString = "Data Source=db.contoso.com;Initial Catalog=ProjectServer;Persist Security Info=True;User ID=sa;Password=pwd;"
72
+ request1 . databaseType = ProjectDatabaseType . Msp ;
73
+ request1 . filename = "imported_from_db.xml" ;
74
+ request1 . folder = BaseTest . remoteBaseTestDataFolder ;
75
+ request1 . projectUid = "E6426C44-D6CB-4B9C-AF16-48910ACE0F54" ;
76
+ request1 . databaseSchema = "dbo" ;
77
+ request1 . format = ProjectFileFormat . P6xml ;
78
+
79
+ const result1 = await tasksApi . putImportProjectFromDb ( request1 ) ;
80
+
81
+ expect ( result1 . response . statusCode ) . to . equal ( 200 ) ;
82
+
83
+ const request2 = new GetProjectIdsRequest ( ) ;
84
+ request2 . name = "imported_from_db.xml" ;
85
+ request2 . folder = BaseTest . remoteBaseTestDataFolder ;
86
+
87
+ const result2 = await tasksApi . getProjectIds ( request2 ) ;
88
+
89
+ expect ( result2 . response . statusCode ) . to . equal ( 200 ) ;
90
+ expect ( result2 . body . projectIds ) . to . eql ( [ "1" ] ) ;
91
+ } ) ;
92
+ } ) ;
93
+ describe ( "putImportProjectFromProjectOnline function" , ( ) => {
94
+ it ( "should return response with code 200 and correct data" , async ( ) => {
95
+
96
+ const tasksApi = BaseTest . initializeTasksApi ( ) ;
97
+ const request1 = new PutImportProjectFromProjectOnlineRequest ( ) ;
98
+ request1 . name = "NewProductDev.mpp"
99
+ request1 . guid = "E6426C44-D6CB-4B9C-AF16-48910ACE0F54" ;
100
+ request1 . xProjectOnlineToken = "SOMESECRETTOKEN" ;
101
+ request1 . folder = BaseTest . remoteBaseTestDataFolder ;
102
+ request1 . siteUrl = "https://your_company_name.sharepoint.com" ;
103
+ request1 . format = ProjectFileFormat . P6xml ;
104
+
105
+ const result1 = await tasksApi . putImportProjectFromProjectOnline ( request1 ) ;
106
+
107
+ expect ( result1 . response . statusCode ) . to . equal ( 200 ) ;
108
+
109
+ const request2 = new DownloadFileRequest ( ) ;
110
+ request2 . path = "NewProductDev.mpp" ;
111
+
112
+ const result2 = await tasksApi . downloadFile ( request2 ) ;
113
+
114
+ expect ( result2 . response . statusCode ) . to . equal ( 200 ) ;
115
+ expect ( result2 . body ) . is . not . undefined . and . not . null ;
116
+ expect ( result2 . body . length ) . to . be . at . least ( 1 ) ;
117
+ } ) ;
118
+ } ) ;
119
+ } ) ;
0 commit comments