Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test payment methods payloads #1076

Merged
merged 1 commit into from
Aug 2, 2023
Merged
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 @@ -16,17 +16,18 @@ public final class AchTransferAccountPayload extends BankAccountPayload {

private final String holderAddress;

public AchTransferAccountPayload(String paymentMethodName,
String id,
public AchTransferAccountPayload(String id,
String paymentMethodName,
String countryCode,
String holderName,
String bankName,
String branchId,
String accountNr,
String accountType,
String holderAddress) {
super(paymentMethodName,
super(
id,
paymentMethodName,
countryCode,
holderName,
bankName,
Expand All @@ -41,26 +42,23 @@ public AchTransferAccountPayload(String paymentMethodName,

@Override
public AccountPayload toProto() {
var builder = bisq.account.protobuf.AchTransferAccountPayload.newBuilder().setHolderAddress(holderAddress);
var bankAccountPayloadBuilder = getAccountPayloadBuilder()
.getCountryBasedAccountPayloadBuilder()
.getBankAccountPayloadBuilder()
.setAchTransferAccountPayload(builder);
var countryBasedPaymentAccountPayloadBuilder = getAccountPayloadBuilder()
.getCountryBasedAccountPayloadBuilder()
.setBankAccountPayload(bankAccountPayloadBuilder);
return getAccountPayloadBuilder()
.setCountryBasedAccountPayload(countryBasedPaymentAccountPayloadBuilder)
.build();
return getAccountPayloadBuilder().setCountryBasedAccountPayload(
getCountryBasedAccountPayloadBuilder().setBankAccountPayload(
getBankAccountPayloadBuilder().setAchTransferAccountPayload(
bisq.account.protobuf.AchTransferAccountPayload.newBuilder()
.setHolderAddress(holderAddress)
)
)
).build();
}

public static AchTransferAccountPayload fromProto(bisq.account.protobuf.AccountPayload proto) {
var countryBasedPaymentAccountPayload = proto.getCountryBasedAccountPayload();
var bankAccountPayload = countryBasedPaymentAccountPayload.getBankAccountPayload();
var accountPayload = bankAccountPayload.getAchTransferAccountPayload();
return new AchTransferAccountPayload(
proto.getPaymentMethodName(),
proto.getId(),
proto.getPaymentMethodName(),
countryBasedPaymentAccountPayload.getCountryCode(),
bankAccountPayload.getHolderName(),
bankAccountPayload.getBankName().isEmpty() ? null : bankAccountPayload.getBankName(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package bisq.account.accounts;

import bisq.account.protobuf.AccountPayload;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -28,8 +27,8 @@ public abstract class BankAccountPayload extends CountryBasedAccountPayload {
@Nullable
protected String nationalAccountId;

protected BankAccountPayload(String paymentMethodName,
String id,
protected BankAccountPayload(String id,
String paymentMethodName,
String countryCode,
String holderName,
@Nullable String bankName,
Expand All @@ -39,7 +38,7 @@ protected BankAccountPayload(String paymentMethodName,
@Nullable String holderTaxId,
@Nullable String bankId,
@Nullable String nationalAccountId) {
super(paymentMethodName, id, countryCode);
super(id, paymentMethodName, countryCode);
this.holderName = Optional.ofNullable(holderName).orElse("");
this.bankName = Optional.ofNullable(bankName).orElse("");
this.branchId = Optional.ofNullable(branchId).orElse("");
Expand All @@ -50,21 +49,17 @@ protected BankAccountPayload(String paymentMethodName,
this.nationalAccountId = nationalAccountId;
}

protected AccountPayload.Builder getBankAccountPayloadBuilder() {
protected bisq.account.protobuf.BankAccountPayload.Builder getBankAccountPayloadBuilder() {
var builder = bisq.account.protobuf.BankAccountPayload.newBuilder()
.setHolderName(holderName)
.setBankName(bankName)
.setBranchId(branchId)
.setAccountNr(accountNr)
.setAccountType(accountNr)
.setAccountType(accountType)
.setBranchId(branchId)
.setBankId(bankId);
Optional.ofNullable(holderTaxId).ifPresent(builder::setHolderTaxId);
Optional.ofNullable(nationalAccountId).ifPresent(builder::setNationalAccountId);
var countryBasedPaymentAccountPayloadBuilder = getAccountPayloadBuilder()
.getCountryBasedAccountPayloadBuilder()
.setBankAccountPayload(builder);
return getAccountPayloadBuilder()
.setCountryBasedAccountPayload(countryBasedPaymentAccountPayloadBuilder);
return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package bisq.account.accounts;

import bisq.account.protobuf.AccountPayload;
import bisq.account.protobuf.AchTransferAccountPayload;
import bisq.account.protobuf.BankAccountPayload;
import bisq.account.protobuf.CountryBasedAccountPayload;
import org.junit.jupiter.api.Test;

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

class AchTransferAccountPayloadTest {

private static final AccountPayload PROTO = bisq.account.protobuf.AccountPayload.newBuilder()
.setId("id")
.setPaymentMethodName("paymentMethodName")
.setCountryBasedAccountPayload(CountryBasedAccountPayload.newBuilder()
.setCountryCode("countryCode")
.setBankAccountPayload(BankAccountPayload.newBuilder()
.setHolderName("holderName")
.setAccountNr("accountNr")
.setAccountType("accountType")
.setBankName("bankName")
.setBranchId("branchId")
.setAchTransferAccountPayload(AchTransferAccountPayload.newBuilder()
.setHolderAddress("holderAddress"))
)
).build();

private static final AccountPayload PROTO_OPTIONALS_NOT_SET = bisq.account.protobuf.AccountPayload.newBuilder()
.setId("id")
.setPaymentMethodName("paymentMethodName")
.setCountryBasedAccountPayload(CountryBasedAccountPayload.newBuilder()
.setCountryCode("countryCode")
.setBankAccountPayload(BankAccountPayload.newBuilder()
.setHolderName("holderName")
.setAchTransferAccountPayload(AchTransferAccountPayload.newBuilder())))
.build();

private static final bisq.account.accounts.AchTransferAccountPayload PAYLOAD =
new bisq.account.accounts.AchTransferAccountPayload(
"id", "paymentMethodName", "countryCode", "holderName", "bankName", "branchId", "accountNr", "accountType", "holderAddress"
);
private static final bisq.account.accounts.AchTransferAccountPayload PAYLOAD_OPTIONALS_NOT_SET =
new bisq.account.accounts.AchTransferAccountPayload(
"id", "paymentMethodName", "countryCode", "holderName", null, null, null, null, null
);

@Test
void toProto() {
assertEquals(PROTO, PAYLOAD.toProto());
}

@Test
void fromProto() {
assertEquals(PAYLOAD, bisq.account.accounts.AchTransferAccountPayload.fromProto(PROTO));
}

@Test
void fromProto_optionals() {
assertEquals(PAYLOAD_OPTIONALS_NOT_SET, bisq.account.accounts.AchTransferAccountPayload.fromProto(PROTO_OPTIONALS_NOT_SET));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package bisq.account.accounts;

import bisq.account.protobuf.AccountPayload;
import bisq.account.protobuf.CountryBasedAccountPayload;
import org.junit.jupiter.api.Test;

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

class F2FAccountPayloadTest {

private static final AccountPayload PROTO = AccountPayload.newBuilder()
.setId("id")
.setPaymentMethodName("paymentMethodName")
.setCountryBasedAccountPayload(
CountryBasedAccountPayload.newBuilder()
.setCountryCode("countryCode")
.setF2FAccountPayload(
bisq.account.protobuf.F2FAccountPayload.newBuilder()
.setCity("city")
.setContact("contact")
.setExtraInfo("extraInfo")))
.build();

private static final F2FAccountPayload PAYLOAD = new F2FAccountPayload(
"id", "paymentMethodName", "countryCode",
"city", "contact", "extraInfo");

@Test
void toProto() {
assertEquals(PROTO, PAYLOAD.toProto());
}

@Test
void fromProto() {
assertEquals(PAYLOAD, F2FAccountPayload.fromProto(PROTO));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package bisq.account.accounts;

import bisq.account.protobuf.AccountPayload;
import bisq.account.protobuf.RevolutAccountPayload;
import org.junit.jupiter.api.Test;

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

class RevolutAccountPayloadTest {

private static final AccountPayload PROTO = AccountPayload.newBuilder()
.setId("id")
.setPaymentMethodName("paymentMethodName")
.setRevolutAccountPayload(RevolutAccountPayload.newBuilder()
.setEmail("email"))
.build();

private static final bisq.account.accounts.RevolutAccountPayload PAYLOAD = new bisq.account.accounts.RevolutAccountPayload(
"id", "paymentMethodName", "email");

@Test
void toProto() {
assertEquals(PROTO, PAYLOAD.toProto());
}

@Test
void fromProto() {
assertEquals(PAYLOAD, bisq.account.accounts.RevolutAccountPayload.fromProto(PROTO));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package bisq.account.accounts;

import bisq.account.protobuf.AccountPayload;
import bisq.account.protobuf.CountryBasedAccountPayload;
import bisq.account.protobuf.SepaAccountPayload;
import org.junit.jupiter.api.Test;

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

class SepaAccountPayloadTest {

private static final AccountPayload PROTO = AccountPayload.newBuilder()
.setId("id")
.setPaymentMethodName("paymentMethodName")
.setCountryBasedAccountPayload(
CountryBasedAccountPayload.newBuilder()
.setCountryCode("countryCode")
.setSepaAccountPayload(SepaAccountPayload.newBuilder()
.setHolderName("holderName")
.setIban("iban")
.setBic("bic")))
.build();

private static final bisq.account.accounts.SepaAccountPayload PAYLOAD = new bisq.account.accounts.SepaAccountPayload(
"id", "paymentMethodName", "holderName", "iban", "bic", "countryCode");

@Test
void toProto() {
assertEquals(PROTO, PAYLOAD.toProto());
}

@Test
void fromProto() {
assertEquals(PAYLOAD, bisq.account.accounts.SepaAccountPayload.fromProto(PROTO));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package bisq.account.accounts;

import bisq.account.protobuf.AccountPayload;
import bisq.account.protobuf.UserDefinedFiatAccountPayload;
import org.junit.jupiter.api.Test;

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

class UserDefinedFiatAccountPayloadTest {

private static final AccountPayload PROTO = AccountPayload.newBuilder()
.setId("id")
.setPaymentMethodName("paymentMethodName")
.setUserDefinedFiatAccountPayload(UserDefinedFiatAccountPayload.newBuilder()
.setAccountData("custom data"))
.build();

private static final bisq.account.accounts.UserDefinedFiatAccountPayload PAYLOAD =
new bisq.account.accounts.UserDefinedFiatAccountPayload("id", "paymentMethodName", "custom data");

@Test
void toProto() {
assertEquals(PROTO, PAYLOAD.toProto());
}

@Test
void fromProto() {
assertEquals(PAYLOAD, bisq.account.accounts.UserDefinedFiatAccountPayload.fromProto(PROTO));
}
}