|
| 1 | +package io.mailtrap.api.suppressions; |
| 2 | + |
| 3 | +import io.mailtrap.Constants; |
| 4 | +import io.mailtrap.config.MailtrapConfig; |
| 5 | +import io.mailtrap.factory.MailtrapClientFactory; |
| 6 | +import io.mailtrap.model.response.suppressions.SendingStream; |
| 7 | +import io.mailtrap.model.response.suppressions.SuppressionType; |
| 8 | +import io.mailtrap.model.response.suppressions.SuppressionsResponse; |
| 9 | +import io.mailtrap.testutils.BaseTest; |
| 10 | +import io.mailtrap.testutils.DataMock; |
| 11 | +import io.mailtrap.testutils.TestHttpClient; |
| 12 | +import org.junit.jupiter.api.BeforeEach; |
| 13 | +import org.junit.jupiter.api.Test; |
| 14 | + |
| 15 | +import java.util.List; |
| 16 | +import java.util.Map; |
| 17 | + |
| 18 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 19 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 20 | + |
| 21 | +class SuppressionsImplTest extends BaseTest { |
| 22 | + |
| 23 | + private Suppressions api; |
| 24 | + |
| 25 | + @BeforeEach |
| 26 | + public void init() { |
| 27 | + TestHttpClient httpClient = new TestHttpClient(List.of( |
| 28 | + DataMock.build( |
| 29 | + Constants.GENERAL_HOST + "/api/accounts/" + accountId + "/suppressions", |
| 30 | + "GET", null, "api/suppressions/searchSuppressions.json", |
| 31 | + Map.of("email", email) |
| 32 | + ), |
| 33 | + DataMock.build( |
| 34 | + Constants.GENERAL_HOST + "/api/accounts/" + accountId + "/suppressions/" + suppressionIdEncoded, |
| 35 | + "DELETE", null, "api/suppressions/deleteSuppression.json" |
| 36 | + ) |
| 37 | + )); |
| 38 | + |
| 39 | + MailtrapConfig testConfig = new MailtrapConfig.Builder() |
| 40 | + .httpClient(httpClient) |
| 41 | + .token("dummy_token") |
| 42 | + .build(); |
| 43 | + |
| 44 | + api = MailtrapClientFactory.createMailtrapClient(testConfig).sendingApi().suppressions(); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + void test_search() { |
| 49 | + List<SuppressionsResponse> searchResponse = api.search(accountId, email); |
| 50 | + |
| 51 | + assertEquals(1, searchResponse.size()); |
| 52 | + assertEquals(suppressionId, searchResponse.get(0).getId()); |
| 53 | + assertEquals(email, searchResponse.get(0).getEmail()); |
| 54 | + assertEquals(SendingStream.BULK, searchResponse.get(0).getSendingStream()); |
| 55 | + assertEquals(SuppressionType.SPAM_COMPLAINT, searchResponse.get(0).getType()); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + void test_deleteSuppression() { |
| 60 | + SuppressionsResponse deleted = api.deleteSuppression(accountId, suppressionId); |
| 61 | + |
| 62 | + assertNotNull(deleted); |
| 63 | + assertEquals(suppressionId, deleted.getId()); |
| 64 | + assertEquals(email, deleted.getEmail()); |
| 65 | + assertEquals(SendingStream.BULK, deleted.getSendingStream()); |
| 66 | + assertEquals(SuppressionType.SPAM_COMPLAINT, deleted.getType()); |
| 67 | + } |
| 68 | +} |
0 commit comments