Skip to content

Commit 40f49a4

Browse files
committed
Improve test coverage and refactor tests for task statuses
1 parent 5a46442 commit 40f49a4

3 files changed

Lines changed: 102 additions & 25 deletions

File tree

src/test/java/com/crowdin/client/tasks/TasksApiTest.java

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.crowdin.client.tasks.model.*;
1111
import com.crowdin.client.tasks.model.pending.CreateEnterprisePendingTaskRequest;
1212
import com.crowdin.client.tasks.model.pending.CreatePendingTaskRequest;
13+
import lombok.SneakyThrows;
1314
import org.apache.http.client.methods.HttpDelete;
1415
import org.apache.http.client.methods.HttpGet;
1516
import org.apache.http.client.methods.HttpPatch;
@@ -19,14 +20,15 @@
1920
import java.util.*;
2021

2122
import static java.util.Collections.singletonList;
22-
import static org.junit.jupiter.api.Assertions.assertEquals;
23-
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
import static org.junit.jupiter.api.Assertions.*;
24+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2425

2526
public class TasksApiTest extends TestClient {
2627

2728
private final Long projectId = 12L;
2829
private final Long enterpriseProjectId = 13L;
2930
private final Long multiStatusProjectId = 14L;
31+
private final Long singleStatusProjectId = 15L;
3032
private final Long taskId = 2L;
3133
private final Long prevTaskId = 1L;
3234
private final Status status = Status.TODO;
@@ -50,37 +52,41 @@ public List<RequestMock> getMocks() {
5052
RequestMock.build(this.url + "/user/tasks/" + taskId, HttpPatch.METHOD_NAME, "api/tasks/editTask.json", "api/tasks/task.json"),
5153
RequestMock.build(this.url + "/projects/" + multiStatusProjectId + "/tasks", HttpGet.METHOD_NAME, "api/tasks/multiStatusListTasks.json", new HashMap<String, String>() {{
5254
put("status", "todo,done");
55+
}}),
56+
RequestMock.build(this.url + "/projects/" + singleStatusProjectId + "/tasks", HttpGet.METHOD_NAME, "api/tasks/singleStatusListTasks.json", new HashMap<String, String>() {{
57+
put("status", "in_progress");
5358
}})
5459
);
5560
}
5661

5762
@Test
5863
public void listTasksTest() {
59-
Assignee assignee = new Assignee();
60-
assignee.setId(1L);
61-
assignee.setUsername("john_smith");
62-
assignee.setFullName("john_smith");
63-
assignee.setAvatarUrl("");
64-
assignee.setWordsCount(5);
65-
assignee.setWordsLeft(3);
6664
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
6765
ResponseList<Task> taskResponseList = this.getTasksApi().listTasks(projectId, null, null, null, null);
68-
assertEquals(taskResponseList.getData().size(), 1);
69-
assertEquals(taskResponseList.getData().get(0).getData().getId(), taskId);
70-
assertEquals(taskResponseList.getData().get(0).getData().getStatus(), status);
71-
assertEquals(new Date(119, Calendar.SEPTEMBER,27,7,0,14), taskResponseList.getData().get(0).getData().getDeadline());
72-
assertEquals(taskResponseList.getData().get(0).getData().getAssignees().get(0), assignee);
66+
67+
assertNotNull(taskResponseList.getData().get(0).getData());
68+
assertEquals(1, taskResponseList.getData().size());
69+
70+
assertEquals(projectId, taskResponseList.getData().get(0).getData().getProjectId());
71+
72+
assertListTasks(taskResponseList);
73+
}
74+
75+
@Test
76+
public void listTasksTest_testSingleStatus() {
77+
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
78+
ResponseList<Task> taskResponseList = this.getTasksApi().listTasks(singleStatusProjectId, null, null, Status.IN_PROGRESS, null);
79+
80+
assertNotNull(taskResponseList.getData().get(0).getData());
81+
assertEquals(1, taskResponseList.getData().size());
82+
assertEquals(singleStatusProjectId, taskResponseList.getData().get(0).getData().getProjectId());
83+
assertEquals(Status.IN_PROGRESS, taskResponseList.getData().get(0).getData().getStatus());
84+
85+
assertListTasks(taskResponseList);
7386
}
7487

7588
@Test
7689
public void listTasksTest_multipleStatuses() {
77-
Assignee assignee = new Assignee();
78-
assignee.setId(1L);
79-
assignee.setUsername("john_smith");
80-
assignee.setFullName("john_smith");
81-
assignee.setAvatarUrl("");
82-
assignee.setWordsCount(5);
83-
assignee.setWordsLeft(3);
8490
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
8591

8692
EnumSet<Status> statuses = EnumSet.of(Status.TODO, Status.DONE);
@@ -90,15 +96,14 @@ public void listTasksTest_multipleStatuses() {
9096

9197
ResponseList<Task> taskResponseList = this.getTasksApi().listTasks(multiStatusProjectId, listTasksParams);
9298

99+
assertNotNull(taskResponseList.getData().get(0).getData());
93100
assertEquals(1, taskResponseList.getData().size());
94-
assertEquals(taskId, taskResponseList.getData().get(0).getData().getId());
95101
assertEquals(multiStatusProjectId, taskResponseList.getData().get(0).getData().getProjectId());
96102

97103
Status responseProjectStatus = taskResponseList.getData().get(0).getData().getStatus();
98104
assertTrue(statuses.contains(responseProjectStatus));
99105

100-
assertEquals(new Date(119, Calendar.SEPTEMBER,27,7,0,14), taskResponseList.getData().get(0).getData().getDeadline());
101-
assertEquals(taskResponseList.getData().get(0).getData().getAssignees().get(0), assignee);
106+
assertListTasks(taskResponseList);
102107
}
103108

104109
@Test
@@ -300,4 +305,21 @@ public void editUserTaskTest() {
300305
assertEquals(taskResponseObject.getData().getId(), taskId);
301306
assertEquals(taskResponseObject.getData().getStatus(), status);
302307
}
308+
309+
//<editor-fold desc="Common method for listTasks assertion">
310+
@SneakyThrows
311+
private void assertListTasks(ResponseList<Task> taskResponseList) {
312+
Assignee assignee = new Assignee();
313+
assignee.setId(1L);
314+
assignee.setUsername("john_smith");
315+
assignee.setFullName("john_smith");
316+
assignee.setAvatarUrl("");
317+
assignee.setWordsCount(5);
318+
assignee.setWordsLeft(3);
319+
320+
assertEquals(taskId, taskResponseList.getData().get(0).getData().getId());
321+
assertEquals(new Date(119, Calendar.SEPTEMBER,27,7,0,14), taskResponseList.getData().get(0).getData().getDeadline());
322+
assertEquals(assignee, taskResponseList.getData().get(0).getData().getAssignees().get(0));
323+
}
324+
//</editor-fold>
303325
}

src/test/resources/api/tasks/listTasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"data": {
55
"id": 2,
6-
"projectId": 2,
6+
"projectId": 12,
77
"creatorId": 6,
88
"type": 1,
99
"status": "todo",
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"data": [
3+
{
4+
"data": {
5+
"id": 2,
6+
"projectId": 15,
7+
"creatorId": 6,
8+
"type": 1,
9+
"status": "in_progress",
10+
"title": "French",
11+
"assignees": [
12+
{
13+
"id": 1,
14+
"username": "john_smith",
15+
"fullName": "john_smith",
16+
"avatarUrl": "",
17+
"wordsCount": 5,
18+
"wordsLeft": 3
19+
}
20+
],
21+
"assignedTeams": [
22+
{
23+
"id": 1,
24+
"wordsCount": 5
25+
}
26+
],
27+
"fileIds": [
28+
1
29+
],
30+
"progress": {
31+
"total": 24,
32+
"done": 15,
33+
"percent": 62
34+
},
35+
"sourceLanguageId": "en",
36+
"targetLanguageId": "fr",
37+
"description": "Proofread all French strings",
38+
"hash": "dac37aff364d83899128e68afe0de4994",
39+
"translationUrl": "/proofread/9092638ac9f2a2d1b5571d08edc53763/all/en-fr/10?task=dac37aff364d83899128e68afe0de4994",
40+
"wordsCount": 24,
41+
"filesCount": 2,
42+
"commentsCount": 0,
43+
"deadline": "2019-09-27T07:00:14+00:00",
44+
"timeRange": "string",
45+
"workflowStepId": 10,
46+
"createdAt": "2019-09-23T09:04:29+00:00",
47+
"updatedAt": "2019-09-23T09:04:29+00:00"
48+
}
49+
}
50+
],
51+
"pagination": {
52+
"offset": 0,
53+
"limit": 25
54+
}
55+
}

0 commit comments

Comments
 (0)