Skip to content

Commit 4a8b827

Browse files
[TASKSCLOUD-491] - Added tests for Task Document Format endpoints.
1 parent 3e3b079 commit 4a8b827

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

tests/task_document_format_test.go

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* --------------------------------------------------------------------------------
3+
* <copyright company="Aspose" file="task_document_format_test.go">
4+
* Copyright (c) 2021 Aspose.Tasks Cloud
5+
* </copyright>
6+
* <summary>
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
* </summary>
25+
* --------------------------------------------------------------------------------
26+
*/
27+
28+
// Example of how to work with task document format.
29+
package api_test
30+
31+
import (
32+
"github.com/antihax/optional"
33+
"github.com/aspose-tasks-cloud/aspose-tasks-cloud-go/api/models"
34+
"github.com/aspose-tasks-cloud/aspose-tasks-cloud-go/api/requests"
35+
"github.com/stretchr/testify/assert"
36+
"testing"
37+
)
38+
39+
// Test for get task document with format.
40+
func Test_TaskDocumentFormat_GetTaskDocumentWithFormat(t *testing.T) {
41+
localFileName := "Home_move_plan.mpp"
42+
remoteFileName := CreateRandomGuid() + localFileName
43+
client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName)
44+
45+
opts := &requests.GetTaskDocumentWithFormatOpts{
46+
Name: remoteFileName,
47+
Format: string(models.CSV_ProjectFileFormat),
48+
Folder: optional.NewString(remoteBaseTestDataFolder),
49+
}
50+
data, response, err := client.TasksApi.GetTaskDocumentWithFormat(ctx, opts)
51+
if err != nil {
52+
t.Error(err)
53+
}
54+
assert.Equal(t, 200, response.StatusCode)
55+
assert.NotNil(t, data)
56+
assert.Less(t, 1, len(data))
57+
fileAsStrings := ConvertBytesToStrings(data)
58+
assert.Equal(t, "ID;Task_Name;Outline_Level;Duration;Start_Date;Finish_Date;Percent_Comp;Cost;Work", fileAsStrings[0])
59+
assert.Equal(t, "1;Five to Eight Weeks Before Moving;1;16 days;Thu 01.01.04 08:00;Thu 22.01.04 17:00;0%;$0;0 hrs", fileAsStrings[1])
60+
t.Cleanup(func() { DeleteTestFileFromStorage(t, ctx, client) })
61+
}
62+
63+
// Test for get task document with format as zipped html.
64+
func Test_TaskDocumentFormat_GetTaskDocumentWithFormatAsZippedHtml(t *testing.T) {
65+
localFileName := "Home_move_plan.mpp"
66+
remoteFileName := CreateRandomGuid() + localFileName
67+
client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName)
68+
69+
opts := &requests.GetTaskDocumentWithFormatOpts{
70+
Name: remoteFileName,
71+
Format: string(models.HTML_ProjectFileFormat),
72+
ReturnAsZipArchive: optional.NewBool(true),
73+
Folder: optional.NewString(remoteBaseTestDataFolder),
74+
}
75+
data, response, err := client.TasksApi.GetTaskDocumentWithFormat(ctx, opts)
76+
if err != nil {
77+
t.Error(err)
78+
}
79+
assert.Equal(t, 200, response.StatusCode)
80+
assert.NotNil(t, data)
81+
assert.Less(t, 1, len(data))
82+
t.Cleanup(func() { DeleteTestFileFromStorage(t, ctx, client) })
83+
}
84+
85+
// Test for get task document with format.
86+
func Test_TaskDocumentFormat_PostTaskDocumentWithFormat(t *testing.T) {
87+
localFileName := "Home_move_plan.mpp"
88+
remoteFileName := CreateRandomGuid() + localFileName
89+
client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName)
90+
91+
// SaveOptions parameters is a representation of
92+
// Aspose.Tasks's SaveOptions class or its format-specific inheritors (Like CsvOptions, etc):
93+
// See Aspose.Tasks reference: https://apireference.aspose.com/net/tasks/aspose.tasks.saving/saveoptions
94+
type (
95+
Column = struct {
96+
Type string
97+
Name string
98+
Property string
99+
Width int
100+
}
101+
View = struct {
102+
Columns []Column
103+
}
104+
saveOptions = struct {
105+
TextDelimiter string
106+
IncludeHeaders bool
107+
NonExistingTestProperty bool
108+
View View
109+
}
110+
)
111+
so := saveOptions{
112+
"Comma",
113+
false,
114+
false,
115+
View{
116+
[]Column{
117+
{"GanttChartColumn", "TestColumn1", "Name", 120},
118+
{"GanttChartColumn", "TestColumn2", "Duration", 120},
119+
},
120+
},
121+
}
122+
opts := &requests.PostTaskDocumentWithFormatOpts{
123+
Name: remoteFileName,
124+
SaveOptions: so,
125+
Format: string(models.CSV_ProjectFileFormat),
126+
Folder: optional.NewString(remoteBaseTestDataFolder),
127+
}
128+
data, response, err := client.TasksApi.PostTaskDocumentWithFormat(ctx, opts)
129+
if err != nil {
130+
t.Error(err)
131+
}
132+
assert.Equal(t, 200, response.StatusCode)
133+
assert.NotNil(t, data)
134+
assert.Less(t, 1, len(data))
135+
fileAsStrings := ConvertBytesToStrings(data)
136+
assert.Equal(t, "Five to Eight Weeks Before Moving,16 days", fileAsStrings[0])
137+
t.Cleanup(func() { DeleteTestFileFromStorage(t, ctx, client) })
138+
}

0 commit comments

Comments
 (0)