Skip to content

Commit 7bf8cb9

Browse files
[TASKSCLOUD-272] - Added tests for extended attributes endpoints.
1 parent 7617492 commit 7bf8cb9

File tree

1 file changed

+237
-0
lines changed

1 file changed

+237
-0
lines changed

test/extendedAttributesTests.ts

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
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 { GetExtendedAttributesRequest, GetExtendedAttributeByIndexRequest, CalculationType, PutExtendedAttributeRequest, ExtendedAttributeDefinition, CustomFieldType, ElementType, Value, DeleteExtendedAttributeByIndexRequest } from "../src/model/model";
29+
import * as BaseTest from "./baseTest";
30+
31+
describe("getExtendedAttributes 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 GetExtendedAttributesRequest();
43+
request.name = fileName;
44+
request.folder = remotePath;
45+
46+
const result = await tasksApi.getExtendedAttributes(request);
47+
48+
expect(result.response.statusCode).to.equal(200);
49+
expect(result.body.extendedAttributes).not.undefined.and.not.null;
50+
expect(result.body.extendedAttributes.list.length).to.equal(2);
51+
});
52+
});
53+
54+
describe("getExtendedAttributeByIndex function", () => {
55+
it("should return response with code 200 and correct data", 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 request = new GetExtendedAttributeByIndexRequest();
66+
request.name = fileName;
67+
request.folder = remotePath;
68+
request.index = 1;
69+
70+
const result = await tasksApi.getExtendedAttributeByIndex(request);
71+
72+
expect(result.response.statusCode).to.equal(200);
73+
expect(result.body.extendedAttribute).not.undefined.and.not.null;
74+
expect(result.body.extendedAttribute.fieldName).to.equal("Text1");
75+
expect(result.body.extendedAttribute.calculationType).to.equal(CalculationType.Lookup);
76+
expect(result.body.extendedAttribute.valueList.length).to.equal(1);
77+
expect(result.body.extendedAttribute.valueList[0].description).to.equal("descr");
78+
expect(result.body.extendedAttribute.valueList[0].id).to.equal(1);
79+
});
80+
});
81+
82+
describe("putExtendedAttribute function", () => {
83+
it("should add new ExtendedAttribute and return 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 firstValue = new Value();
94+
firstValue.description = "descr1";
95+
firstValue.val = "Internal";
96+
firstValue.id = 111;
97+
const secondValue = new Value();
98+
secondValue.description = "descr2";
99+
secondValue.val = "External";
100+
secondValue.id = 112;
101+
const newExtendedAttribute = new ExtendedAttributeDefinition
102+
newExtendedAttribute.calculationType = CalculationType.Lookup,
103+
newExtendedAttribute.cfType = CustomFieldType.Text,
104+
newExtendedAttribute.fieldName = "Text3",
105+
newExtendedAttribute.elementType = ElementType.Task,
106+
newExtendedAttribute.alias = "New Field",
107+
newExtendedAttribute.valueList = [firstValue, secondValue];
108+
109+
const request1 = new PutExtendedAttributeRequest();
110+
request1.name = fileName;
111+
request1.folder = remotePath;
112+
request1.extendedAttribute = newExtendedAttribute;
113+
114+
const result1 = await tasksApi.putExtendedAttribute(request1);
115+
116+
expect(result1.response.statusCode).to.equal(200);
117+
expect(result1.body.extendedAttribute).not.undefined.and.not.null;
118+
expect(result1.body.extendedAttribute.fieldName).to.equal("Text3");
119+
expect(result1.body.extendedAttribute.alias).to.equal("New Field");
120+
expect(result1.body.extendedAttribute.fieldId).to.equal("188743737");
121+
122+
const addedAttributeIndex = result1.body.extendedAttribute.index;
123+
const request2 = new GetExtendedAttributeByIndexRequest();
124+
request2.name = fileName;
125+
request2.folder = remotePath;
126+
request2.index = addedAttributeIndex;
127+
128+
const result2 = await tasksApi.getExtendedAttributeByIndex(request2);
129+
130+
expect(result2.response.statusCode).to.equal(200);
131+
expect(result2.body.extendedAttribute).not.undefined.and.not.null;
132+
133+
expect(result2.body.extendedAttribute.fieldId).to.equal("188743737");
134+
expect(result2.body.extendedAttribute.fieldName).to.equal("Text3");
135+
expect(result2.body.extendedAttribute.cfType).to.equal(CustomFieldType.Text);
136+
expect(result2.body.extendedAttribute.alias).to.equal("New Field");
137+
138+
const valueList = result2.body.extendedAttribute.valueList;
139+
expect(valueList.length).to.equal(2);
140+
expect(valueList[0].id).to.equal(111);
141+
expect(valueList[0].val).to.equal("Internal");
142+
expect(valueList[0].description).to.equal("descr1");
143+
expect(valueList[1].id).to.equal(112);
144+
expect(valueList[1].val).to.equal("External");
145+
expect(valueList[1].description).to.equal("descr2");
146+
});
147+
it("should edit ExtendedAttribute and return correct data", async () => {
148+
149+
const tasksApi = BaseTest.initializeTasksApi();
150+
const fileName = "NewProductDev.mpp";
151+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
152+
const remotePath = BaseTest.remoteBaseTestDataFolder;
153+
const remoteFullPath = remotePath + "/" + fileName;
154+
155+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
156+
157+
const request1 = new GetExtendedAttributeByIndexRequest();
158+
request1.name = fileName;
159+
request1.folder = remotePath;
160+
request1.index = 1;
161+
162+
const result1 = await tasksApi.getExtendedAttributeByIndex(request1);
163+
164+
expect(result1.response.statusCode).to.equal(200);
165+
expect(result1.body.extendedAttribute).not.undefined.and.not.null;
166+
167+
const extendedAttributeToEdit = result1.body.extendedAttribute;
168+
extendedAttributeToEdit.calculationType = CalculationType.None;
169+
extendedAttributeToEdit.valueList.length = 0;
170+
extendedAttributeToEdit.cfType = CustomFieldType.Text;
171+
extendedAttributeToEdit.fieldName = "Text1";
172+
extendedAttributeToEdit.elementType = ElementType.Task;
173+
extendedAttributeToEdit.alias = "Edited field";
174+
175+
const request2 = new PutExtendedAttributeRequest();
176+
request2.name = fileName;
177+
request2.folder = remotePath;
178+
request2.extendedAttribute = extendedAttributeToEdit;
179+
180+
const result2 = await tasksApi.putExtendedAttribute(request2);
181+
182+
expect(result2.response.statusCode).to.equal(200);
183+
expect(result2.body.extendedAttribute).not.undefined.and.not.null;
184+
expect(result2.body.extendedAttribute.fieldName).to.equal("Text1");
185+
expect(result2.body.extendedAttribute.alias).to.equal("Edited field");
186+
expect(result2.body.extendedAttribute.fieldId).to.equal("188743731");
187+
188+
const addedAttributeIndex = result2.body.extendedAttribute.index;
189+
const request3 = new GetExtendedAttributeByIndexRequest();
190+
request3.name = fileName;
191+
request3.folder = remotePath;
192+
request3.index = addedAttributeIndex;
193+
194+
const result3 = await tasksApi.getExtendedAttributeByIndex(request3);
195+
196+
expect(result3.response.statusCode).to.equal(200);
197+
expect(result3.body.extendedAttribute).not.undefined.and.not.null;
198+
199+
expect(result3.body.extendedAttribute.fieldId).to.equal("188743731");
200+
expect(result3.body.extendedAttribute.fieldName).to.equal("Text1");
201+
expect(result3.body.extendedAttribute.cfType).to.equal(CustomFieldType.Text);
202+
expect(result3.body.extendedAttribute.alias).to.equal("Edited field");
203+
expect(result3.body.extendedAttribute.valueList.length).to.equal(0);
204+
});
205+
});
206+
207+
describe("deleteExtendedAttributeByIndex function", () => {
208+
it("should return response with code 200 and correct data", async () => {
209+
210+
const tasksApi = BaseTest.initializeTasksApi();
211+
const fileName = "NewProductDev.mpp";
212+
const localPath = BaseTest.localBaseTestDataFolder + fileName;
213+
const remotePath = BaseTest.remoteBaseTestDataFolder;
214+
const remoteFullPath = remotePath + "/" + fileName;
215+
216+
await tasksApi.uploadFileToStorage(remoteFullPath, localPath);
217+
218+
const request1 = new DeleteExtendedAttributeByIndexRequest();
219+
request1.name = fileName;
220+
request1.folder = remotePath;
221+
request1.index = 1;
222+
223+
const result1 = await tasksApi.deleteExtendedAttributeByIndex(request1);
224+
225+
expect(result1.response.statusCode).to.equal(200);
226+
227+
const request2 = new GetExtendedAttributesRequest();
228+
request2.name = fileName;
229+
request2.folder = remotePath;
230+
231+
const result2 = await tasksApi.getExtendedAttributes(request2);
232+
233+
expect(result2.response.statusCode).to.equal(200);
234+
expect(result2.body.extendedAttributes).not.undefined.and.not.null;
235+
expect(result2.body.extendedAttributes.list.length).to.equal(1);
236+
});
237+
});

0 commit comments

Comments
 (0)