Skip to content

Commit 5047dbf

Browse files
authored
fix(translations): empty array value instead of empty object (#324)
1 parent e353e97 commit 5047dbf

6 files changed

Lines changed: 120 additions & 17 deletions

File tree

src/main/java/com/crowdin/client/translations/model/PreTranslationReportResponse.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.crowdin.client.translations.model;
22

3+
import com.crowdin.client.core.http.impl.json.EmptyArrayToNullDeserializer;
4+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
35
import lombok.Data;
46
import java.util.List;
57
import java.util.Map;
6-
import com.crowdin.client.translationstatus.model.Category;
78

89

910
@Data
@@ -16,8 +17,10 @@ public class PreTranslationReportResponse {
1617
public static class TargetLanguage {
1718
private String id;
1819
private List<File> files;
20+
@JsonDeserialize(using = EmptyArrayToNullDeserializer.class)
1921
private Map<String, Integer> skipped;
20-
private List<Category> skippedQaCheckCategories;
22+
@JsonDeserialize(using = EmptyArrayToNullDeserializer.class)
23+
private Map<String, Integer> skippedQaCheckCategories;
2124
}
2225

2326
@Data

src/main/java/com/crowdin/client/translationstatus/model/Category.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public enum Category implements EnumConverter<Category> {
66

77
EMPTY, VARIABLES, TAGS, PUNCTUATION, SYMBOL_REGISTER,
8-
SPACES, SIZE, SPECIAL_SYMBOLS, WRONG_TRANSLATION, SPELLCHECK, ICU;
8+
SPACES, SIZE, SPECIAL_SYMBOLS, WRONG_TRANSLATION, SPELLCHECK, ICU, DUPLICATE;
99

1010
public static Category from(String value) {
1111
return Category.valueOf(value.toUpperCase());
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.crowdin.client.translations;
2+
3+
import com.crowdin.client.core.model.ResponseObject;
4+
import com.crowdin.client.framework.RequestMock;
5+
import com.crowdin.client.framework.TestClient;
6+
import com.crowdin.client.translations.model.Method;
7+
import com.crowdin.client.translations.model.PreTranslationReportResponse;
8+
import org.apache.http.client.methods.HttpGet;
9+
import org.junit.jupiter.api.Test;
10+
11+
import java.util.Arrays;
12+
import java.util.List;
13+
14+
import static org.junit.jupiter.api.Assertions.*;
15+
16+
public class TranslationsApiIssuesTest extends TestClient {
17+
18+
private final Long projectId = 12L;
19+
private final Long parallelProjectId = 13L;
20+
private final String language = "uk";
21+
private final String preTranslationId = "9e7de270-4f83-41cb-b606-2f90631f26e2";
22+
private final long directoryId = 3L;
23+
private final Long fileId = 2L;
24+
private final Long branchId = 211L;
25+
private final Long storageId = 14L;
26+
private final Long buildId = 2L;
27+
private final String link = "test.com";
28+
29+
@Override
30+
public List<RequestMock> getMocks() {
31+
return Arrays.asList(
32+
RequestMock.build(this.url + "/projects/" + projectId + "/pre-translations/" + preTranslationId + "/report", HttpGet.METHOD_NAME, "api/translations/preTranslationReportResponse_issueEmptyArray.json")
33+
);
34+
}
35+
36+
@Test
37+
public void getPreTranslationReportTest() {
38+
ResponseObject<PreTranslationReportResponse> response = this.getTranslationsApi().getPreTranslationReport(projectId, preTranslationId);
39+
40+
PreTranslationReportResponse report = response.getData();
41+
assertNotNull(report);
42+
assertEquals(Method.AI, report.getPreTranslateType());
43+
44+
PreTranslationReportResponse.TargetLanguage lang = report.getLanguages().get(0);
45+
assertEquals(language, lang.getId());
46+
47+
PreTranslationReportResponse.File file = lang.getFiles().get(0);
48+
assertEquals(fileId, file.getId());
49+
50+
assertNull(lang.getSkipped());
51+
assertNull(lang.getSkippedQaCheckCategories());
52+
}
53+
}

src/test/java/com/crowdin/client/translations/TranslationsApiTest.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
import java.util.Arrays;
3737
import java.util.List;
38+
import java.util.Map;
3839

3940
import static java.util.Collections.singletonList;
4041
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -272,13 +273,30 @@ public void editPreTranslationTest() {
272273

273274
@Test
274275
public void getPreTranslationReportTest() {
275-
ResponseObject<PreTranslationReportResponse> response = this.getTranslationsApi().getPreTranslationReport(projectId, preTranslationId);
276-
PreTranslationReportResponse report = response.getData();
277-
assertNotNull(report);
278-
assertEquals(Method.AI, report.getPreTranslateType());
279-
PreTranslationReportResponse.TargetLanguage lang = report.getLanguages().get(0);
280-
assertEquals(language, lang.getId());
281-
PreTranslationReportResponse.File file = lang.getFiles().get(0);
282-
assertEquals(fileId, file.getId());
276+
ResponseObject<PreTranslationReportResponse> response = this.getTranslationsApi().getPreTranslationReport(projectId, preTranslationId);
277+
PreTranslationReportResponse report = response.getData();
278+
assertNotNull(report);
279+
280+
assertEquals(Method.AI, report.getPreTranslateType());
281+
282+
PreTranslationReportResponse.TargetLanguage language = report.getLanguages().get(0);
283+
assertEquals("es", language.getId());
284+
285+
PreTranslationReportResponse.File file = language.getFiles().get(0);
286+
assertEquals(10191, file.getId());
287+
288+
PreTranslationReportResponse.Statistics statistics = file.getStatistics();
289+
assertEquals(6, statistics.getPhrases());
290+
assertEquals(13, statistics.getWords());
291+
292+
Map<String, Integer> skipped = language.getSkipped();
293+
assertEquals(2, skipped.get("translation_eq_source"));
294+
assertEquals(1, skipped.get("qa_check"));
295+
assertEquals(0, skipped.get("hidden_strings"));
296+
assertEquals(6, skipped.get("ai_error"));
297+
298+
Map<String, Integer> skippedQaCheckCategories = language.getSkippedQaCheckCategories();
299+
assertEquals(1, skippedQaCheckCategories.get("duplicate"));
300+
assertEquals(1, skippedQaCheckCategories.get("spellcheck"));
283301
}
284302
}

src/test/resources/api/translations/preTranslationReportResponse.json

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@
22
"data": {
33
"languages": [
44
{
5-
"id": "uk",
5+
"id": "es",
66
"files": [
77
{
8-
"id": "2",
9-
"statistics": { "phrases": 6, "words": 13 }
8+
"id": "10191",
9+
"statistics": {
10+
"phrases": 6,
11+
"words": 13
12+
}
1013
}
1114
],
12-
"skipped": { "ai_error": 6 },
13-
"skippedQaCheckCategories": ["spellcheck"]
15+
"skipped": {
16+
"translation_eq_source": 2,
17+
"qa_check": 1,
18+
"hidden_strings": 0,
19+
"ai_error": 6
20+
},
21+
"skippedQaCheckCategories": {
22+
"duplicate": 1,
23+
"spellcheck": 1
24+
}
1425
}
1526
],
1627
"preTranslateType": "ai"
1728
}
18-
}
29+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"data": {
3+
"languages": [
4+
{
5+
"id": "uk",
6+
"files": [
7+
{
8+
"id": "2",
9+
"statistics": { "phrases": 6, "words": 13 }
10+
}
11+
],
12+
"skipped": [],
13+
"skippedQaCheckCategories": []
14+
}
15+
],
16+
"preTranslateType": "ai"
17+
}
18+
}

0 commit comments

Comments
 (0)