From 2aedeb94d314b2c9180cb3cb64df0a3c7c3d9ade Mon Sep 17 00:00:00 2001 From: Parth Sankhla Date: Thu, 10 Oct 2024 16:21:11 +0530 Subject: [PATCH] YO --- .../crowdin/client/clients/ClientsApi.java | 17 ++++++ .../client/clients/ClientsApiTest.java | 52 ++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/crowdin/client/clients/ClientsApi.java b/src/main/java/com/crowdin/client/clients/ClientsApi.java index 893be1ad1..a503a7620 100644 --- a/src/main/java/com/crowdin/client/clients/ClientsApi.java +++ b/src/main/java/com/crowdin/client/clients/ClientsApi.java @@ -38,4 +38,21 @@ public ResponseList listClients(Integer limit, Integer offset) throws Ht ClientResponseList vendorResponseList = this.httpClient.get(this.url + "/clients", new HttpRequestConfig(queryParams), ClientResponseList.class); return ClientResponseList.to(vendorResponseList); } + + // New method to remove string approvals + public void removeStringApprovals(String projectId, String stringId) throws HttpException, HttpBadRequestException { + String url = String.format("%s/projects/%s/strings/%s/approvals/remove", this.url, projectId, stringId); + this.httpClient.post(url, null, Void.class); // Assuming no body is needed and the response is not used + } + + // Updated method to delete string translations + public void deleteStringTranslations(String projectId, String stringId, String languageId) throws HttpException, HttpBadRequestException { + String url; + if (languageId != null) { + url = String.format("%s/projects/%s/strings/%s/translations/%s", this.url, projectId, stringId, languageId); + } else { + url = String.format("%s/projects/%s/strings/%s/translations", this.url, projectId, stringId); + } + this.httpClient.delete(url, null); + } } diff --git a/src/test/java/com/crowdin/client/clients/ClientsApiTest.java b/src/test/java/com/crowdin/client/clients/ClientsApiTest.java index 87f21f7ee..b7ead224b 100644 --- a/src/test/java/com/crowdin/client/clients/ClientsApiTest.java +++ b/src/test/java/com/crowdin/client/clients/ClientsApiTest.java @@ -5,18 +5,23 @@ import com.crowdin.client.core.model.ResponseList; import com.crowdin.client.framework.RequestMock; import com.crowdin.client.framework.TestClient; -import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpPost; import org.junit.jupiter.api.Test; import java.util.List; import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class ClientsApiTest extends TestClient { private final Long clientId = 678L; private final String name = "John Smith Translation Agency"; + private final String projectId = "1234"; // Example project ID + private final String stringId = "5678"; // Example string ID + private final String languageId = "en"; // Example language ID @Override public List getMocks() { @@ -33,4 +38,49 @@ public void listClientsTest() { assertEquals(clientResponseList.getData().get(0).getData().getName(), name); assertEquals(clientResponseList.getData().get(0).getData().getStatus(), Status.PENDING); } + + @Test + public void removeStringApprovalsTest() { + // Mock the request and response for removing string approvals + getMocks().add(RequestMock.build( + this.url + "/projects/" + projectId + "/strings/" + stringId + "/approvals/remove", + HttpPost.METHOD_NAME, + "api/strings/removeStringApprovals.json" // Mock response file + )); + + // Call the method to test + this.getClientsApi().removeStringApprovals(projectId, stringId); + + // Assertions can be added here if necessary + } + + @Test + public void deleteStringTranslationsWithLanguageIdTest() { + // Mock the request and response for deleting string translations with language ID + getMocks().add(RequestMock.build( + this.url + "/projects/" + projectId + "/strings/" + stringId + "/translations/" + languageId, + HttpDelete.METHOD_NAME, + "api/strings/deleteStringTranslationsWithLanguageId.json" // Mock response file + )); + + // Call the method to test + this.getClientsApi().deleteStringTranslations(projectId, stringId, languageId); + + // Assertions can be added here if necessary + } + + @Test + public void deleteStringTranslationsWithoutLanguageIdTest() { + // Mock the request and response for deleting string translations without language ID + getMocks().add(RequestMock.build( + this.url + "/projects/" + projectId + "/strings/" + stringId + "/translations", + HttpDelete.METHOD_NAME, + "api/strings/deleteStringTranslationsWithoutLanguageId.json" // Mock response file + )); + + // Call the method to test + this.getClientsApi().deleteStringTranslations(projectId, stringId, null); + + // Assertions can be added here if necessary + } }