Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Iulian Masar committed Jan 21, 2025
1 parent a9149ed commit 21c6095
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 50 deletions.
66 changes: 60 additions & 6 deletions src/test/java/com/mangopay/core/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public abstract class BaseTest {
protected MangoPayApi api;

private static UserNatural JOHN;
private static UserNatural JOHN_PAYER;
private static UserNaturalSca JOHN_SCA_OWNER;
private static UserNaturalSca JOHN_SCA_PAYER;
private static UserLegal MATRIX;
private static UserLegal MATRIX_PAYER;
private static UserLegalSca MATRIX_SCA;
private static UboDeclaration MATRIX_UBO_DECLARATION;
private static Ubo MATRIX_UBO;
Expand Down Expand Up @@ -133,11 +135,21 @@ protected Shipping getNewShipping() {
}

protected UserNatural getJohn() throws Exception {
return getJohn(false, false);
return getJohnOwner(false, false);
}

protected UserNatural getJohn(UserCategory userCategory) throws Exception {
switch (userCategory) {
case OWNER:
return getJohnOwner(false, false);
case PAYER:
return getJohnPayer(false, false);
}
throw new Exception("userCategory not supported");
}

protected UserNatural getJohnWithTermsAccepted() throws Exception {
return getJohn(true, true);
return getJohnOwner(true, true);
}

protected UserNaturalSca getJohnSca() throws Exception {
Expand All @@ -158,7 +170,7 @@ protected UserLegalSca getMatrixSca() throws Exception {
return getMatrixSca(false, false);
}

protected UserNatural getJohn(Boolean recreate, Boolean termsAccepted) throws Exception {
protected UserNatural getJohnOwner(Boolean recreate, Boolean termsAccepted) throws Exception {
if (BaseTest.JOHN == null || recreate) {
Calendar c = Calendar.getInstance();
c.set(1975, 12, 21, 0, 0, 0);
Expand Down Expand Up @@ -191,6 +203,20 @@ protected UserNatural getJohn(Boolean recreate, Boolean termsAccepted) throws Ex
return BaseTest.JOHN;
}

protected UserNatural getJohnPayer(Boolean recreate, Boolean termsAccepted) throws Exception {
if (BaseTest.JOHN_PAYER == null || recreate) {
UserNatural user = new UserNatural();
user.setFirstName("John");
user.setLastName("Doe");
user.setEmail("[email protected]");
user.setTermsAndConditionsAccepted(termsAccepted);
user.setUserCategory(UserCategory.PAYER);

BaseTest.JOHN_PAYER = (UserNatural) this.api.getUserApi().create(user);
}
return BaseTest.JOHN_PAYER;
}

protected UserNaturalSca getJohnScaOwner(Boolean recreate, Boolean termsAccepted) throws Exception {
if (BaseTest.JOHN_SCA_OWNER == null || recreate) {
Calendar c = Calendar.getInstance();
Expand Down Expand Up @@ -259,7 +285,17 @@ protected UserNatural getNewJohn(boolean declarative) throws Exception {
return (UserNatural) this.api.getUserApi().create(user);
}

protected UserLegal getMatrix() throws Exception {
protected UserLegal getMatrix(UserCategory userCategory) throws Exception {
switch (userCategory) {
case OWNER:
return getMatrixOwner();
case PAYER:
return getMatrixPayer();
}
throw new Exception("userCategory not supported");
}

protected UserLegal getMatrixOwner() throws Exception {
if (BaseTest.MATRIX == null) {
UserNatural john = this.getJohn();
UserLegal user = new UserLegal();
Expand All @@ -274,6 +310,7 @@ protected UserLegal getMatrix() throws Exception {
user.setLegalRepresentativeNationality(john.getNationality());
user.setLegalRepresentativeCountryOfResidence(john.getCountryOfResidence());
user.setCompanyNumber("LU12345678");
user.setUserCategory(UserCategory.OWNER);

Calendar c = Calendar.getInstance();
c.set(1975, 12, 21, 0, 0, 0);
Expand All @@ -285,6 +322,23 @@ protected UserLegal getMatrix() throws Exception {
return BaseTest.MATRIX;
}

protected UserLegal getMatrixPayer() throws Exception {
if (BaseTest.MATRIX_PAYER == null) {
UserNatural john = this.getJohn();
UserLegal user = new UserLegal();
user.setName("MartixSampleOrg");
user.setLegalPersonType(LegalPersonType.BUSINESS);
user.setEmail(john.getEmail());
user.setUserCategory(UserCategory.PAYER);
user.setLegalRepresentativeFirstName(john.getFirstName());
user.setLegalRepresentativeLastName(john.getLastName());
user.setTermsAndConditionsAccepted(true);

BaseTest.MATRIX_PAYER = (UserLegal) this.api.getUserApi().create(user);
}
return BaseTest.MATRIX_PAYER;
}

protected UserLegalSca getMatrixSca(Boolean recreate, Boolean termsAccepted) throws Exception {
if (BaseTest.MATRIX_SCA == null || recreate) {
UserNatural john = this.getJohn();
Expand Down Expand Up @@ -1510,7 +1564,7 @@ protected BankingAlias getNewJohnsBankingAlias() throws Exception {

protected UboDeclaration getMatrixUboDeclaration() throws Exception {
if (MATRIX_UBO_DECLARATION == null) {
MATRIX_UBO_DECLARATION = api.getUboDeclarationApi().create(this.getMatrix().getId());
MATRIX_UBO_DECLARATION = api.getUboDeclarationApi().create(this.getMatrixOwner().getId());
}
return MATRIX_UBO_DECLARATION;
}
Expand All @@ -1531,7 +1585,7 @@ protected Ubo createNewUboForMatrix() throws Exception {

protected Ubo getMatrixUbo() throws Exception {
if (MATRIX_UBO == null) {
UserLegal matrix = this.getMatrix();
UserLegal matrix = this.getMatrixOwner();
UboDeclaration uboDeclaration = this.getMatrixUboDeclaration();

Ubo ubo = this.createNewUboForMatrix();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/mangopay/core/MandateApiImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void getAllMandates() throws Exception {

@Test
public void getMandatesForUser() throws Exception {
UserNatural user = this.getJohn(true, false);
UserNatural user = this.getJohnOwner(true, false);

Mandate mandatePost = new Mandate();
mandatePost.setBankAccountId(this.getJohnsAccount(true).getId());
Expand All @@ -105,7 +105,7 @@ public void getMandatesForUser() throws Exception {

@Test
public void getMandatesForBankAccount() throws Exception {
UserNatural user = this.getJohn(true, false);
UserNatural user = this.getJohnOwner(true, false);

Mandate mandatePost = new Mandate();
mandatePost.setBankAccountId(this.getJohnsAccount(true).getId());
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/com/mangopay/core/PayInApiImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,8 @@ public void testDirectApplepayPayin() {
"\"transactionId\":\"b061eb32181a2d9ca42ad16031b476eebaa62a9a095ad660e2759fba52b51a61\"}}");
PayIn applePayPayin = new PayIn();
applePayPayin.setCreditedWalletId(wallet.getId());
applePayPayin.setAuthorId(this.getMatrix().getId());
applePayPayin.setCreditedUserId(this.getMatrix().getId());
applePayPayin.setAuthorId(this.getMatrixOwner().getId());
applePayPayin.setCreditedUserId(this.getMatrixOwner().getId());
applePayPayin.setDebitedFunds(new Money()
.setAmount(199)
.setCurrency(CurrencyIso.EUR)
Expand Down Expand Up @@ -792,8 +792,8 @@ public void testDirectGooglepayPayin() {
.setTokenData("placeholder");
PayIn googlePayIn = new PayIn();
googlePayIn.setCreditedWalletId(wallet.getId());
googlePayIn.setAuthorId(this.getMatrix().getId());
googlePayIn.setCreditedUserId(this.getMatrix().getId());
googlePayIn.setAuthorId(this.getMatrixOwner().getId());
googlePayIn.setCreditedUserId(this.getMatrixOwner().getId());
googlePayIn.setDebitedFunds(new Money()
.setAmount(199)
.setCurrency(CurrencyIso.EUR)
Expand Down Expand Up @@ -830,8 +830,8 @@ public void testDirectGooglepayV2Payin() {
String paymentData = "{\"signature\":\"MEUCIEMVk9qrfoJ/ku5qvHCZuv9zPC1QVH6NMMrkZ6wLmt8FAiEAjNduo5gvMGE4KgTeTIuwevdvxJdkQP03ru9lp/5rKhk\\u003d\",\"intermediateSigningKey\":{\"signedKey\":\"{\\\"keyValue\\\":\\\"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEC1gn5CSvw/UxS9+PCVhgPWNTMGxTBUHpenGNWirrNlmi5bJts3FO92DjcUQmLaCmM1hQwtZ9KCzkc0SGh99X4A\\\\u003d\\\\u003d\\\",\\\"keyExpiration\\\":\\\"1694758343052\\\"}\",\"signatures\":[\"MEUCIG+oaBGEl63CqCy+C7OwQCFvr/K9cSYWtQ/ku2UejCTKAiEAnhJ1LXd+JMMvueEorp0Kha922H9wRMR6tPvnGIZ6cM4\\u003d\"]},\"protocolVersion\":\"ECv2\",\"signedMessage\":\"{\\\"encryptedMessage\\\":\\\"HmCQdP5BOdsv33ACkGyYJYKFHEnxRbe+TTaTI79tJm/v8NP4XH5Iim9H/a1jj2OmZTgQDklZ6pv1v6XNjKkkaEMPW1MZbtZ2P8GcwAWRKKJx8W4ZmDexb564GP8EvLw4dGzlYE8L5nY7khunPZKAfioQGmNSTIBpB1MLRtgArGA9T/w3EcjU1+gdGAce7NpcZeVIrIX4tNLL5TlpGdAHRU5XNlA/q0HcuvKpmgCfpnSJKu1xPO8Xzoa7C7toX6GmmGlkdhH0Y+vK+mKFpI02uGItSPR64vaZYFD7qPMzXOsp7KjyGw1Tr6fx0Qrmc3CeDcZ3Dzc/WVbM0jw1gMz/gjnZ7KILoqMNxcEz1h8rkLp7FHjCNlls0i6VYNINWWl1PMqHTDBsTsHVdYJlAqycoBJTssHy44ASBIF8epBw3oAydhFV4ZkeLPX/x+QlrS+IEi3af8xj//nhtZ5CwwW5IOuMF0sqAa0PcRVpgw9BrQSXNprymtatS3qtwRrL0LHJsIii+xSI5XY4dfy6Z6j1QCvWriCwfbS9TasvbMb6dbh0S6sS5XBHd5wp/FtHfYBAh9iK08DQ8uKcKfnZx4zmvU5TsSTTbrj/SEFJiJ3rBegIweEpYM3m1QifErNAVhBIpm67tg\\\\u003d\\\\u003d\\\",\\\"ephemeralPublicKey\\\":\\\"BCr5xXtNJMkCYutxBQi8sQBHllG4RcSrxalvi0bf23Jwvyr46OwNGfMe45518pxNzPC8yPUXrGTbKXoQeJR16Ew\\\\u003d\\\",\\\"tag\\\":\\\"5W+s9OGQTFEojaZ5K3ynKuUVninxOVep9pkmqI/+ed4\\\\u003d\\\"}\"}";
PayIn googlePayIn = new PayIn();
googlePayIn.setCreditedWalletId(wallet.getId());
googlePayIn.setAuthorId(this.getMatrix().getId());
googlePayIn.setCreditedUserId(this.getMatrix().getId());
googlePayIn.setAuthorId(this.getMatrixOwner().getId());
googlePayIn.setCreditedUserId(this.getMatrixOwner().getId());
googlePayIn.setDebitedFunds(new Money()
.setAmount(112)
.setCurrency(CurrencyIso.EUR)
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/com/mangopay/core/UboDeclarationApiImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void createUboDeclaration() throws Exception {
@Test
public void getUboDeclarationList() throws Exception {
UboDeclaration uboDeclaration=this.getMatrixUboDeclaration();
UserLegal matrix=this.getMatrix();
UserLegal matrix = this.getMatrixOwner();
List<UboDeclaration> declarations=this.api.getUboDeclarationApi().getAll(matrix.getId(),null,null);

assertNotNull(declarations);
Expand All @@ -41,7 +41,7 @@ public void getUboDeclarationList() throws Exception {
@Test
public void getUboDeclaration() throws Exception {
UboDeclaration uboDeclaration=this.getMatrixUboDeclaration();
UserLegal matrix=this.getMatrix();
UserLegal matrix = this.getMatrixOwner();

UboDeclaration declarationFromApi=this.api.getUboDeclarationApi().get(matrix.getId(),uboDeclaration.getId());

Expand All @@ -52,7 +52,7 @@ public void getUboDeclaration() throws Exception {
@Test
public void createUbo() throws Exception {
Ubo ubo=this.createNewUboForMatrix();
UserLegal matrix = this.getMatrix();
UserLegal matrix = this.getMatrixOwner();
UboDeclaration uboDeclaration = this.getMatrixUboDeclaration();
Ubo newUbo = api.getUboDeclarationApi().createUbo(matrix.getId(), uboDeclaration.getId(), ubo);

Expand All @@ -68,7 +68,7 @@ public void createUbo() throws Exception {

@Test
public void updateUbo() throws Exception {
UserLegal matrix=this.getMatrix();
UserLegal matrix = this.getMatrixOwner();
UboDeclaration uboDeclaration=this.getMatrixUboDeclaration();
Calendar calendar=Calendar.getInstance();
calendar.set(1991,12,21,0,0,0);
Expand Down Expand Up @@ -96,7 +96,7 @@ public void updateUbo() throws Exception {

@Test
public void getUbo() throws Exception {
UserLegal matrix=this.getMatrix();
UserLegal matrix = this.getMatrixOwner();
UboDeclaration uboDeclaration=this.getMatrixUboDeclaration();
Ubo existingUbo=this.getMatrixUbo();

Expand All @@ -115,7 +115,7 @@ public void getUbo() throws Exception {

@Test
public void submitUboDeclaration() throws Exception{
UserLegal matrix=this.getMatrix();
UserLegal matrix = this.getMatrixOwner();
UboDeclaration uboDeclaration=this.getMatrixUboDeclaration();
UboDeclaration declaration=this.api.getUboDeclarationApi().get(matrix.getId(),uboDeclaration.getId());

Expand Down
65 changes: 35 additions & 30 deletions src/test/java/com/mangopay/core/UserApiImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void createNaturalSca() throws Exception {

@Test
public void createLegal() throws Exception {
UserLegal matrix = this.getMatrix();
UserLegal matrix = this.getMatrixOwner();
assertTrue(matrix.getId().length() > 0);
assertEquals(matrix.getPersonType(), PersonType.LEGAL);
assertEquals("LU12345678", matrix.getCompanyNumber());
Expand Down Expand Up @@ -148,7 +148,7 @@ public void getNaturalSca() throws Exception {

@Test
public void getNaturalFailsForLegalUser() throws Exception {
UserLegal matrix = this.getMatrix();
UserLegal matrix = this.getMatrixOwner();

UserNatural user = null;
try {
Expand Down Expand Up @@ -176,7 +176,7 @@ public void getLegalFailsForNaturalUser() throws Exception {

@Test
public void getLegal() throws Exception {
UserLegal matrix = this.getMatrix();
UserLegal matrix = this.getMatrixOwner();

User user1 = this.api.getUserApi().get(matrix.getId());
User user2 = this.api.getUserApi().getLegal(matrix.getId());
Expand Down Expand Up @@ -238,49 +238,54 @@ public void updateLegalSca() throws Exception {
}

@Test
// @Ignore("Can't be tested at this moment")
@Ignore("Can't be tested at this moment")
public void categorizeNaturalSca() throws Exception {
UserNaturalSca johnSca = this.getJohnSca(UserCategory.PAYER);
UserNatural johnPayer = this.getJohn(UserCategory.PAYER);
Calendar c = Calendar.getInstance();
c.set(1975, 12, 21, 0, 0, 0);

johnSca.setUserCategory(UserCategory.OWNER);
johnSca.setTermsAndConditionsAccepted(true);
johnSca.setPhoneNumber("+33611111111");
johnSca.setPhoneNumberCountry(CountryIso.FR);
johnSca.setBirthday(c.getTimeInMillis() / 1000);
johnSca.setNationality(CountryIso.FR);
johnSca.setCountryOfResidence(CountryIso.FR);
johnPayer.setUserCategory(UserCategory.OWNER);
johnPayer.setTermsAndConditionsAccepted(true);
johnPayer.setPhoneNumber("+33611111111");
johnPayer.setPhoneNumberCountry(CountryIso.FR);
johnPayer.setBirthday(c.getTimeInMillis() / 1000);
johnPayer.setNationality(CountryIso.FR);
johnPayer.setCountryOfResidence(CountryIso.FR);
johnPayer.setAddress(getNewAddress());

// transition from PAYER to OWNER
this.api.getUserApi().categorize(johnSca);
User userFetched = this.api.getUserApi().getSca(johnSca.getId());
this.api.getUserApi().categorize(johnPayer);
User userFetched = this.api.getUserApi().getSca(johnPayer.getId());

assertEquals(UserCategory.OWNER, userFetched.getUserCategory());
}

@Test
// @Ignore("Can't be tested at this moment")
@Ignore("Can't be tested at this moment")
public void categorizeLegalSca() throws Exception {
UserLegalSca matrixSca = this.getMatrixSca();
UserLegal matrix = this.getMatrix();
UserLegal matrixPayer = this.getMatrix(UserCategory.PAYER);
UserNatural john = this.getJohn();

Calendar c = Calendar.getInstance();
c.set(1975, 12, 21, 0, 0, 0);

matrixSca.setUserCategory(UserCategory.OWNER);
matrixSca.setTermsAndConditionsAccepted(true);
LegalRepresentative updatedOwnerLegalRepresentative = matrixSca.getLegalRepresentative();
updatedOwnerLegalRepresentative.setPhoneNumber("+33611111111");
updatedOwnerLegalRepresentative.setPhoneNumberCountry(CountryIso.FR);
matrixPayer.setUserCategory(UserCategory.OWNER);
matrixPayer.setTermsAndConditionsAccepted(true);
matrixPayer.setHeadquartersAddress(this.getNewAddress());
matrixPayer.setLegalRepresentativeFirstName(john.getFirstName());
matrixPayer.setLegalRepresentativeLastName(john.getLastName());
matrixPayer.setLegalRepresentativeAddress(john.getAddress());
matrixPayer.setLegalRepresentativeEmail(john.getEmail());
matrixPayer.setLegalRepresentativeBirthday(john.getBirthday());
matrixPayer.setLegalRepresentativeNationality(john.getNationality());
matrixPayer.setLegalRepresentativeCountryOfResidence(john.getCountryOfResidence());
matrixPayer.setCompanyNumber("LU12345678");

this.api.getUserApi().categorize(matrix);
User user1 = this.api.getUserApi().get(matrixSca.getId());
User user2 = this.api.getUserApi().getLegalSca(matrixSca.getId());
// transition from PAYER to OWNER
this.api.getUserApi().categorize(matrixPayer);
User userFetched = this.api.getUserApi().getSca(matrixPayer.getId());

assert(user1 instanceof UserLegalSca);
assertEqualInputProps(user1, matrixSca);
assertEqualInputProps(user2, matrixSca);
assertEquals(UserCategory.OWNER, userFetched.getUserCategory());
}

@Test
Expand All @@ -307,7 +312,7 @@ public void updateNaturalNonASCII() throws Exception {

@Test
public void updateLegal() throws Exception {
UserLegal matrix = this.getMatrix();
UserLegal matrix = this.getMatrixOwner();
matrix.setLegalRepresentativeLastName(matrix.getLegalRepresentativeLastName() + " - CHANGED");

User userSaved = this.api.getUserApi().update(matrix);
Expand Down Expand Up @@ -864,7 +869,7 @@ public void testUserNaturalTermsAndConditions() throws Exception {

@Test
public void testUserLegalTermsAndConditions() throws Exception {
UserLegal user = this.getMatrix();
UserLegal user = this.getMatrixOwner();
assertFalse(user.isTermsAndConditionsAccepted());

user.setTermsAndConditionsAccepted(true);
Expand Down

0 comments on commit 21c6095

Please sign in to comment.