Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 'unassignLabelFromStrings' - 'stringIds' parameter #164

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/java/com/crowdin/client/labels/LabelsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,17 @@ public ResponseList<SourceString> assignLabelToStrings(Long projectId, Long labe
/**
* @param projectId Project Identifier
* @param labelId Label Identifier
* @param stringIds List of string IDs
* @return Source string
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.labels.strings.deleteMany" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.labels.strings.deleteMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<SourceString> unassignLabelFromStrings(Long projectId, Long labelId) throws HttpException, HttpBadRequestException {
public ResponseList<SourceString> unassignLabelFromStrings(Long projectId, Long labelId, List<Long> stringIds) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/labels/%d/strings", this.url, projectId, labelId);
SourceStringResponseList response = this.httpClient.delete(builtUrl, new HttpRequestConfig(), SourceStringResponseList.class);
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams("stringIds", Optional.ofNullable(stringIds == null ? null : stringIds.stream().map(String::valueOf).collect(Collectors.joining(","))));
SourceStringResponseList response = this.httpClient.delete(builtUrl, new HttpRequestConfig(queryParams), SourceStringResponseList.class);
return SourceStringResponseList.to(response);
}

Expand Down
Binary file added src/test/java/com/crowdin/client/.DS_Store
Binary file not shown.
54 changes: 25 additions & 29 deletions src/test/java/com/crowdin/client/labels/LabelsApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,37 @@

public class LabelsApiTest extends TestClient {

private final String apiFiles = "api/labels/";

private String file(String fileName) {
return apiFiles + fileName;
}

private final Long projectId = 8L;
private final String labelTitle = "main";
private final Long labelId = 34L;
private final Map<String, Object> urlParams = new HashMap<String, Object>() {{

private final Map<String, Object> unassignLabelToScreenshotsUrlParams = new HashMap<String, Object>() {{
put("screenshotIds", "1");
}};
private final Map<String, Object> unassignLabelToStringTestUrlParams = new HashMap<String, Object>() {{
put("stringIds", "1");
}};

@Override
public List<RequestMock> getMocks() {
return Arrays.asList(
RequestMock.build(String.format("%s/projects/%d/labels", this.url, projectId), HttpGet.METHOD_NAME,
"api/labels/listLabels.json"),
RequestMock.build(String.format("%s/projects/%d/labels", this.url, projectId), HttpPost.METHOD_NAME,
"api/labels/addLabelRequest.json", "api/labels/label.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId), HttpGet.METHOD_NAME,
"api/labels/label.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId), HttpDelete.METHOD_NAME),
RequestMock.build(String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId), HttpPatch.METHOD_NAME,
"api/labels/editLabelRequest.json", "api/labels/label.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d/strings", this.url, projectId, labelId), HttpPost.METHOD_NAME,
"api/labels/labelToStringsRequest.json", "api/labels/listStrings.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d/strings", this.url, projectId, labelId), HttpDelete.METHOD_NAME,
"api/labels/listStrings.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d/screenshots", this.url, projectId, labelId), HttpPost.METHOD_NAME,
"api/labels/labelToScreenshotsRequest.json", "api/labels/listScreenshots.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d/screenshots", this.url, projectId, labelId), HttpDelete.METHOD_NAME,
"api/labels/listScreenshots.json", urlParams)
RequestMock.build(String.format("%s/projects/%d/labels", this.url, projectId), HttpGet.METHOD_NAME,
"api/labels/listLabels.json"),
RequestMock.build(String.format("%s/projects/%d/labels", this.url, projectId), HttpPost.METHOD_NAME,
"api/labels/addLabelRequest.json", "api/labels/label.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId), HttpGet.METHOD_NAME,
"api/labels/label.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId), HttpDelete.METHOD_NAME),
RequestMock.build(String.format("%s/projects/%d/labels/%d", this.url, projectId, labelId), HttpPatch.METHOD_NAME,
"api/labels/editLabelRequest.json", "api/labels/label.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d/strings", this.url, projectId, labelId), HttpPost.METHOD_NAME,
"api/labels/labelToStringsRequest.json", "api/labels/listStrings.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d/strings", this.url, projectId, labelId), HttpDelete.METHOD_NAME,
"api/labels/listStrings.json", unassignLabelToStringTestUrlParams),
RequestMock.build(String.format("%s/projects/%d/labels/%d/screenshots", this.url, projectId, labelId), HttpPost.METHOD_NAME,
"api/labels/labelToScreenshotsRequest.json", "api/labels/listScreenshots.json"),
RequestMock.build(String.format("%s/projects/%d/labels/%d/screenshots", this.url, projectId, labelId), HttpDelete.METHOD_NAME,
"api/labels/listScreenshots.json", unassignLabelToScreenshotsUrlParams)
);
}

Expand Down Expand Up @@ -117,8 +115,8 @@ public void assignLabelToStringTest() {
}

@Test
public void unassignLabelToStringTest() {
ResponseList<SourceString> response = this.getLabelsApi().unassignLabelFromStrings(projectId, labelId);
public void unassignLabelFromStringTest() {
ResponseList<SourceString> response = this.getLabelsApi().unassignLabelFromStrings(projectId, labelId, Arrays.asList(1L));
assertEquals(1, response.getData().size());
}

Expand All @@ -133,9 +131,7 @@ public void assignLabelToScreenshot() {

@Test
public void unassignLabelToScreenshot() {
List<Long> screenshotIds= Arrays.asList(1L);
ResponseList<Screenshot> response = this.getLabelsApi().unassignLabelFromScreenshots(projectId, labelId, screenshotIds);
ResponseList<Screenshot> response = this.getLabelsApi().unassignLabelFromScreenshots(projectId, labelId, Arrays.asList(1L));
assertEquals(1, response.getData().size());

}
}