Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ public static void main(String[] args) {
final var createdSubAccount = client.organizationsApi().subAccounts()
.createSubAccount(ORGANIZATION_ID, createRequest);
System.out.println(createdSubAccount);

// Permanent – removes all sub account data. Deleting the last sub account deletes the organization.
client.organizationsApi().subAccounts().deleteSubAccount(ORGANIZATION_ID, createdSubAccount.getId());
System.out.println("Sub account " + createdSubAccount.getId() + " deleted");
}
}
13 changes: 13 additions & 0 deletions src/main/java/io/mailtrap/api/subaccounts/SubAccounts.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,17 @@ public interface SubAccounts {
*/
SubAccount createSubAccount(long organizationId, CreateSubAccountRequest request);

/**
* Delete a sub account from the specified organization.
* Requires sub account management permissions for the organization.
* <p>
* Deletion is permanent and removes all sub account data. Deleting the last sub account
* of an organization deletes the organization as well. A repeated call for the same
* sub account fails with 404. Rate limit – 10 requests per minute per organization.
*
* @param organizationId unique organization ID
* @param subAccountId unique sub account ID
*/
void deleteSubAccount(long organizationId, long subAccountId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ public SubAccount createSubAccount(final long organizationId, final CreateSubAcc
SubAccount.class
);
}

@Override
public void deleteSubAccount(final long organizationId, final long subAccountId) {
httpClient.delete(
String.format(apiHost + "/api/organizations/%d/sub_accounts/%d", organizationId, subAccountId),
new RequestData(),
Void.class
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class SubAccountsImplTest extends BaseTest {

private final long organizationId = 1001L;
private final long subAccountId = 12345L;

private SubAccounts api;

Expand All @@ -30,7 +32,10 @@ public void init() {
"GET", null, "api/subaccounts/getSubAccountsResponse.json"),

DataMock.build(Constants.GENERAL_HOST + "/api/organizations/" + organizationId + "/sub_accounts",
"POST", "api/subaccounts/createSubAccountRequest.json", "api/subaccounts/createSubAccountResponse.json")
"POST", "api/subaccounts/createSubAccountRequest.json", "api/subaccounts/createSubAccountResponse.json"),

DataMock.build(Constants.GENERAL_HOST + "/api/organizations/" + organizationId + "/sub_accounts/" + subAccountId,
"DELETE", null, null)
));

final MailtrapConfig testConfig = new MailtrapConfig.Builder()
Expand Down Expand Up @@ -61,4 +66,9 @@ void test_createSubAccount() {
assertEquals(12347L, response.getId());
assertEquals("New Team Account", response.getName());
}

@Test
void test_deleteSubAccount() {
assertDoesNotThrow(() -> api.deleteSubAccount(organizationId, subAccountId));
}
}
Loading