Skip to content

Commit

Permalink
YO
Browse files Browse the repository at this point in the history
  • Loading branch information
aPassie committed Oct 10, 2024
1 parent 2101227 commit 2aedeb9
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/main/java/com/crowdin/client/clients/ClientsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,21 @@ public ResponseList<Client> 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);
}
}
52 changes: 51 additions & 1 deletion src/test/java/com/crowdin/client/clients/ClientsApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<RequestMock> getMocks() {
Expand All @@ -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
}
}

0 comments on commit 2aedeb9

Please sign in to comment.