-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
117 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/io/github/jpdev/asaassdk/rest/transfer/children/PixRecurringFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.github.jpdev.asaassdk.rest.transfer.children; | ||
|
||
import io.github.jpdev.asaassdk.http.Domain; | ||
import io.github.jpdev.asaassdk.rest.action.Fetcher; | ||
|
||
public class PixRecurringFetcher extends Fetcher<PixRecurring> { | ||
|
||
private final String id; | ||
|
||
public PixRecurringFetcher(String id) { | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public String getResourceUrl() { | ||
return Domain.PIX_RECURRING.addPathVariable(id).toString(); | ||
} | ||
|
||
@Override | ||
public Class<PixRecurring> getResourceClass() { | ||
return PixRecurring.class; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/java/integration/io/github/jpdev/asaassdk/CustomMockUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package integration.io.github.jpdev.asaassdk; | ||
|
||
import io.github.jpdev.asaassdk.utils.Money; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Random; | ||
|
||
public class CustomMockUtils { | ||
|
||
public static BigDecimal randomValue() { | ||
int value = new Random().nextInt(100) + 1; | ||
return Money.create(value); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/test/java/integration/io/github/jpdev/asaassdk/rest/pix/recurring/PixRecurringTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package integration.io.github.jpdev.asaassdk.rest.pix.recurring; | ||
|
||
import integration.io.github.jpdev.asaassdk.AsaasClientMock; | ||
import integration.io.github.jpdev.asaassdk.CustomMockUtils; | ||
import io.github.jpdev.asaassdk.rest.pix.enums.PixAddressKeyType; | ||
import io.github.jpdev.asaassdk.rest.transfer.Transfer; | ||
import io.github.jpdev.asaassdk.rest.transfer.children.PixRecurring; | ||
import io.github.jpdev.asaassdk.rest.transfer.children.PixRecurringFrequency; | ||
import io.github.jpdev.asaassdk.utils.Money; | ||
import org.junit.jupiter.api.*; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Random; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
public class PixRecurringTest { | ||
|
||
private static String recurringId; | ||
private static PixRecurringFrequency recurringFrequency; | ||
private static Integer recurringQuantity; | ||
|
||
@BeforeAll | ||
static void setup() { | ||
AsaasClientMock.create(); | ||
} | ||
|
||
@Test | ||
@Tag("integration") | ||
@Order(1) | ||
@DisplayName("Teste de criação de recorrência") | ||
void save() { | ||
BigDecimal value = CustomMockUtils.randomValue(); | ||
recurringFrequency = PixRecurringFrequency.MONTHLY; | ||
recurringQuantity = new Random().nextInt(8) + 1; | ||
|
||
PixRecurring recurring = new PixRecurring() | ||
.setFrequency(PixRecurringFrequency.MONTHLY) | ||
.setQuantity(2); | ||
|
||
Transfer transfer = Transfer.pixAddressKeyCreator() | ||
.setPixAddressKey("+5547999999999") | ||
.setValue(value) | ||
.setDescription("teste") | ||
.setPixAddressKeyType(PixAddressKeyType.PHONE) | ||
.setRecurring(recurring) | ||
.create(); | ||
|
||
assertNotNull(transfer, "Transferência não criada."); | ||
assertNotNull(transfer.getRecurring()); | ||
|
||
recurringId = transfer.getRecurring(); | ||
} | ||
|
||
@Test | ||
@Tag("integration") | ||
@Order(2) | ||
@DisplayName("Teste de leitura de recorrência") | ||
void fetcher() { | ||
assumeTrue(recurringId != null, "Recorrência não criada."); | ||
|
||
PixRecurring recurring = PixRecurring.fetcher(recurringId) | ||
.fetch(); | ||
|
||
assertNotNull(recurring, "Recorrência não encontrada."); | ||
assertEquals(recurringFrequency, recurring.getFrequency(), "Frequência incorreta."); | ||
assertEquals(recurringQuantity, recurring.getQuantity(), "Quantidade incorreta."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters