Skip to content

Commit a99bf3c

Browse files
committed
Added tests for list order
1 parent 8a32b98 commit a99bf3c

4 files changed

Lines changed: 163 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.crowdin.client.styleguide;
2+
3+
import com.crowdin.client.core.model.OrderByField;
4+
import com.crowdin.client.core.model.ResponseList;
5+
import com.crowdin.client.core.model.SortOrder;
6+
import com.crowdin.client.framework.RequestMock;
7+
import com.crowdin.client.framework.TestClient;
8+
import com.crowdin.client.styleguide.model.StyleGuide;
9+
import org.apache.http.client.methods.HttpGet;
10+
import org.junit.jupiter.api.Test;
11+
12+
import java.util.Arrays;
13+
import java.util.HashMap;
14+
import java.util.List;
15+
16+
import static java.util.Collections.singletonList;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
19+
public class StyleGuidesApiStyleGuidesOrderByIdAscTest extends TestClient {
20+
21+
private final Long styleGuideId = 2L;
22+
private final Long styleGuide2Id = 3L;
23+
24+
@Override
25+
public List<RequestMock> getMocks() {
26+
return Arrays.asList(
27+
RequestMock.build(this.url + "/style-guides", HttpGet.METHOD_NAME, "api/styleguide/listStyleGuidesOrderByIdAsc.json", new HashMap<String, String>() {{
28+
put("orderBy", "id%20asc");
29+
}})
30+
);
31+
}
32+
33+
@Test
34+
public void listStyleGuidesTest_orderByIdNull() {
35+
OrderByField orderById = new OrderByField();
36+
orderById.setFieldName("id");
37+
38+
ResponseList<StyleGuide> styleGuideResponseList = this.getStyleGuidesApi().listStyleGuide(null, null, null, singletonList(orderById));
39+
assertEquals(2, styleGuideResponseList.getData().size());
40+
assertEquals(styleGuideId, styleGuideResponseList.getData().get(0).getData().getId());
41+
assertEquals(styleGuide2Id, styleGuideResponseList.getData().get(1).getData().getId());
42+
}
43+
44+
@Test
45+
public void listStyleGuidesTest_orderByIdAsc() {
46+
OrderByField orderById = new OrderByField();
47+
orderById.setFieldName("id");
48+
orderById.setOrderBy(SortOrder.ASC);
49+
50+
ResponseList<StyleGuide> styleGuideResponseList = this.getStyleGuidesApi().listStyleGuide(null, null, null, singletonList(orderById));
51+
assertEquals(2, styleGuideResponseList.getData().size());
52+
assertEquals(styleGuideId, styleGuideResponseList.getData().get(0).getData().getId());
53+
assertEquals(styleGuide2Id, styleGuideResponseList.getData().get(1).getData().getId());
54+
}
55+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.crowdin.client.styleguide;
2+
3+
import com.crowdin.client.core.model.OrderByField;
4+
import com.crowdin.client.core.model.ResponseList;
5+
import com.crowdin.client.core.model.SortOrder;
6+
import com.crowdin.client.framework.RequestMock;
7+
import com.crowdin.client.framework.TestClient;
8+
import com.crowdin.client.styleguide.model.StyleGuide;
9+
import org.apache.http.client.methods.HttpGet;
10+
import org.junit.jupiter.api.Test;
11+
12+
import java.util.Arrays;
13+
import java.util.HashMap;
14+
import java.util.List;
15+
16+
import static java.util.Collections.singletonList;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
19+
public class StyleGuidesApiStyleGuidesOrderByIdDescTest extends TestClient {
20+
21+
private final Long styleGuideId = 2L;
22+
private final Long styleGuide2Id = 3L;
23+
24+
@Override
25+
public List<RequestMock> getMocks() {
26+
return Arrays.asList(
27+
RequestMock.build(this.url + "/style-guides", HttpGet.METHOD_NAME, "api/styleguide/listStyleGuidesOrderByIdDesc.json", new HashMap<String, String>() {{
28+
put("orderBy", "id%20desc");
29+
}})
30+
);
31+
}
32+
33+
@Test
34+
public void listStyleGuidesTest_orderByIdDesc() {
35+
OrderByField orderById = new OrderByField();
36+
orderById.setFieldName("id");
37+
orderById.setOrderBy(SortOrder.DESC);
38+
39+
ResponseList<StyleGuide> styleGuideResponseList = this.getStyleGuidesApi().listStyleGuide(null, null, null, singletonList(orderById));
40+
assertEquals(2, styleGuideResponseList.getData().size());
41+
assertEquals(styleGuide2Id, styleGuideResponseList.getData().get(0).getData().getId());
42+
assertEquals(styleGuideId, styleGuideResponseList.getData().get(1).getData().getId());
43+
}
44+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"data": [
3+
{
4+
"data": {
5+
"id": 2,
6+
"name": "Be My Eyes iOS's Style Guide",
7+
"aiInstructions": "string",
8+
"userId": 2,
9+
"languageId": ["uk", "fr", "de"],
10+
"projectIds": [1, 2, 3],
11+
"isShared": false,
12+
"createdAt": "2019-09-16T13:42:04+00:00"
13+
}
14+
},
15+
{
16+
"data": {
17+
"id": 3,
18+
"name": "Be My Eyes iOS's Style Guide",
19+
"aiInstructions": "string",
20+
"userId": 2,
21+
"languageId": ["uk", "fr", "de"],
22+
"projectIds": [1, 2, 3],
23+
"isShared": false,
24+
"createdAt": "2019-09-16T13:42:04+00:00"
25+
}
26+
}
27+
],
28+
"pagination": {
29+
"offset": 0,
30+
"limit": 25
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"data": [
3+
{
4+
"data": {
5+
"id": 3,
6+
"name": "Be My Eyes iOS's Style Guide",
7+
"aiInstructions": "string",
8+
"userId": 2,
9+
"languageId": ["uk", "fr", "de"],
10+
"projectIds": [1, 2, 3],
11+
"isShared": false,
12+
"createdAt": "2019-09-16T13:42:04+00:00"
13+
}
14+
},
15+
{
16+
"data": {
17+
"id": 2,
18+
"name": "Be My Eyes iOS's Style Guide",
19+
"aiInstructions": "string",
20+
"userId": 2,
21+
"languageId": ["uk", "fr", "de"],
22+
"projectIds": [1, 2, 3],
23+
"isShared": false,
24+
"createdAt": "2019-09-16T13:42:04+00:00"
25+
}
26+
}
27+
],
28+
"pagination": {
29+
"offset": 0,
30+
"limit": 25
31+
}
32+
}

0 commit comments

Comments
 (0)