forked from Mastercard/open-banking-us-openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransactionsApiTest.java
102 lines (87 loc) · 3.57 KB
/
TransactionsApiTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.mastercard.finicity.client.api;
import com.mastercard.finicity.client.ApiException;
import com.mastercard.finicity.client.model.TransactionsReportConstraints;
import com.mastercard.finicity.client.test.BaseTest;
import com.mastercard.finicity.client.test.utils.AccountUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import static java.time.ZoneOffset.UTC;
import static org.junit.jupiter.api.Assertions.*;
class TransactionsApiTest extends BaseTest {
private static final TransactionsApi api = new TransactionsApi(apiClient);
private static String existingAccountId;
private static Long existingTransactionId;
private static String customerAccountList;
private static final Long fromDate = LocalDateTime.now().minusYears(10).toEpochSecond(UTC);
private static final Long toDate = LocalDateTime.now().toEpochSecond(UTC);
@BeforeAll
protected static void beforeAll() {
try {
// Find the last account ID
var accounts = AccountUtils.getCustomerAccounts(new AccountsApi(apiClient), CUSTOMER_ID);
var account = accounts.get(accounts.size() - 1);
existingAccountId = account.getId();
// Find an existing transaction ID
var transaction = api.getAllCustomerTransactions(CUSTOMER_ID, fromDate, toDate, null, null, null, true)
.getTransactions()
.stream()
.findFirst();
if (transaction.isEmpty()) {
fail();
}
existingTransactionId = transaction.get().getId();
// Fetch some accounts IDs to be included in reports
customerAccountList = AccountUtils.getCustomerAccountListString(new AccountsApi(apiClient), CUSTOMER_ID);
} catch (ApiException e) {
fail(e);
}
}
@Test
void generateTransactionsReportTest() {
try {
var constraints = new TransactionsReportConstraints().accountIds(customerAccountList);
var reportAck = api.generateTransactionsReport(CUSTOMER_ID, toDate, constraints, null, true);
assertEquals("inProgress", reportAck.getStatus());
assertEquals("transactions", reportAck.getType());
} catch (ApiException e) {
// Status code: 429, Reason: Too Many Requests
logApiException(e);
}
}
@Test
void getAllCustomerTransactionsTest() {
try {
var transactions = api.getAllCustomerTransactions(CUSTOMER_ID, fromDate, toDate, null, null, null, true);
assertTrue(transactions.getTransactions().size() > 0);
} catch (ApiException e) {
fail(e);
}
}
@Test
void getCustomerAccountTransactionsTest() {
try {
var transactions = api.getCustomerAccountTransactions(CUSTOMER_ID, existingAccountId, fromDate, toDate, null, null, null, true);
assertTrue(transactions.getTransactions().size() > 0);
} catch (ApiException e) {
fail(e);
}
}
@Test
void getCustomerTransactionTest() {
try {
var transaction = api.getCustomerTransaction(CUSTOMER_ID, existingTransactionId);
assertNotNull(transaction);
} catch (ApiException e) {
fail(e);
}
}
@Test
void loadHistoricTransactionsForCustomerAccountTest() {
try {
api.loadHistoricTransactionsForCustomerAccount(CUSTOMER_ID, existingAccountId);
} catch (ApiException e) {
fail(e);
}
}
}