Skip to content

Commit

Permalink
Merge branch 'master' into feat/make-request-token-optional
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Ferrari <74320613+brunoekferrari@users.noreply.github.com>
  • Loading branch information
brunoekferrari authored Jan 30, 2025
2 parents 5e69edf + 644880a commit 3ad44a1
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/incognia/api/IncogniaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public SignupAssessment registerSignup(RegisterSignupRequest request) throws Inc
PostSignupRequestBody.builder()
.installationId(request.getInstallationId())
.requestToken(request.getRequestToken())
.appVersion(request.getAppVersion())
.deviceOs(
Optional.ofNullable(request.getDeviceOs()).map(String::toLowerCase).orElse(null))
.addressLine(address.map(Address::getAddressLine).orElse(null))
.structuredAddress(address.map(Address::getStructuredAddress).orElse(null))
.addressCoordinates(address.map(Address::getCoordinates).orElse(null))
Expand Down Expand Up @@ -189,6 +192,9 @@ public TransactionAssessment registerLogin(RegisterLoginRequest request)
PostTransactionRequestBody.builder()
.installationId(request.getInstallationId())
.requestToken(request.getRequestToken())
.appVersion(request.getAppVersion())
.deviceOs(
Optional.ofNullable(request.getDeviceOs()).map(String::toLowerCase).orElse(null))
.accountId(request.getAccountId())
.externalId(request.getExternalId())
.policyId(request.getPolicyId())
Expand Down Expand Up @@ -383,6 +389,9 @@ public TransactionAssessment registerPayment(RegisterPaymentRequest request)
PostTransactionRequestBody.builder()
.installationId(request.getInstallationId())
.requestToken(request.getRequestToken())
.appVersion(request.getAppVersion())
.deviceOs(
Optional.ofNullable(request.getDeviceOs()).map(String::toLowerCase).orElse(null))
.accountId(request.getAccountId())
.externalId(request.getExternalId())
.policyId(request.getPolicyId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class PostSignupRequestBody {
String sessionToken;
String requestToken;
String addressLine;
String appVersion;
String deviceOs;
StructuredAddress structuredAddress;
Coordinates addressCoordinates;
String externalId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
public class RegisterSignupRequest {
String installationId;
String requestToken;
String appVersion;
String deviceOs;
@Nullable Address address;
String externalId;
String policyId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
public class PostTransactionRequestBody {
String installationId;
String requestToken;
String appVersion;
String deviceOs;
String accountId;
String sessionToken;
String policyId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class RegisterLoginRequest {
String accountId;
String externalId;
String policyId;
String appVersion;
String deviceOs;
Map<String, Object> customProperties;

@Getter(AccessLevel.NONE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
public class RegisterPaymentRequest {
String installationId;
String requestToken;
String appVersion;
String deviceOs;
String accountId;
String externalId;
String policyId;
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/incognia/api/IncogniaAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,17 @@ void testRegisterSignup_withEmptyAddress() {
String accountId = "my-account";
String policyId = UUID.randomUUID().toString();
String externalId = "external-id";
String appVersion = "1.4.3";
String deviceOs = "iOS";

TokenAwareDispatcher dispatcher = new TokenAwareDispatcher(token, CLIENT_ID, CLIENT_SECRET);
dispatcher.setExpectedAddressLine(null);
dispatcher.setExpectedRequestToken(requestToken);
dispatcher.setExpectedExternalId(externalId);
dispatcher.setExpectedPolicyId(policyId);
dispatcher.setExpectedAccountId(accountId);
dispatcher.setExpectedAppVersion(appVersion);
dispatcher.setExpectedDeviceOs(deviceOs.toLowerCase());
dispatcher.setExpectedCustomProperties(null);
mockServer.setDispatcher(dispatcher);
RegisterSignupRequest registerSignupRequest =
Expand All @@ -169,6 +173,8 @@ void testRegisterSignup_withEmptyAddress() {
.accountId(accountId)
.policyId(policyId)
.externalId(externalId)
.appVersion(appVersion)
.deviceOs(deviceOs)
.customProperties(null)
.build();
SignupAssessment signupAssessment = client.registerSignup(registerSignupRequest);
Expand Down Expand Up @@ -273,6 +279,8 @@ void testRegisterLogin_whenDataIsValid(Boolean eval) {
String token = TokenCreationFixture.createToken();
String requestToken = "request-token";
String accountId = "account-id";
String appVersion = "1.4.3";
String deviceOs = "Android";
String externalId = "external-id";
String policyId = "policy-id";
Map<String, Object> map = new HashMap<>();
Expand All @@ -283,6 +291,8 @@ void testRegisterLogin_whenDataIsValid(Boolean eval) {
PostTransactionRequestBody.builder()
.requestToken(requestToken)
.externalId(externalId)
.appVersion(appVersion)
.deviceOs(deviceOs.toLowerCase())
.accountId(accountId)
.type("login")
.addresses(null)
Expand All @@ -295,6 +305,8 @@ void testRegisterLogin_whenDataIsValid(Boolean eval) {
RegisterLoginRequest.builder()
.requestToken(requestToken)
.accountId(accountId)
.appVersion(appVersion)
.deviceOs(deviceOs)
.externalId(externalId)
.evaluateTransaction(eval)
.policyId(policyId)
Expand Down Expand Up @@ -385,6 +397,8 @@ void testRegisterPayment_whenDataIsValid(Boolean eval) {
String token = TokenCreationFixture.createToken();
String requestToken = "request-token";
String accountId = "account-id";
String appVersion = "appVersion";
String deviceOs = "iOS";
String externalId = "external-id";
String policyId = "policy-id";
Address address =
Expand Down Expand Up @@ -428,6 +442,8 @@ void testRegisterPayment_whenDataIsValid(Boolean eval) {
RegisterPaymentRequest.builder()
.requestToken(requestToken)
.accountId(accountId)
.appVersion(appVersion)
.deviceOs(deviceOs)
.externalId(externalId)
.policyId(policyId)
.addresses(Collections.singletonMap(AddressType.SHIPPING, address))
Expand All @@ -441,6 +457,8 @@ void testRegisterPayment_whenDataIsValid(Boolean eval) {
.externalId(externalId)
.policyId(policyId)
.accountId(accountId)
.appVersion(appVersion)
.deviceOs(deviceOs.toLowerCase())
.type("payment")
.addresses(transactionAddresses)
.paymentValue(paymentValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class TokenAwareDispatcher extends Dispatcher {
@Setter private String expectedInstallationId;
@Setter private String expectedExternalId;
@Setter private String expectedAccountId;
@Setter private String expectedAppVersion;
@Setter private String expectedDeviceOs;
@Setter private String expectedPolicyId;
@Setter private String expectedAddressLine;
@Setter private Map<String, Object> expectedCustomProperties;
Expand Down Expand Up @@ -138,6 +140,8 @@ private MockResponse handlePostSignup(@NotNull RecordedRequest request)
assertThat(postSignupRequestBody.getInstallationId()).isEqualTo(expectedInstallationId);
assertThat(postSignupRequestBody.getRequestToken()).isEqualTo(expectedRequestToken);
assertThat(postSignupRequestBody.getAccountId()).isEqualTo(expectedAccountId);
assertThat(postSignupRequestBody.getAppVersion()).isEqualTo(expectedAppVersion);
assertThat(postSignupRequestBody.getDeviceOs()).isEqualTo(expectedDeviceOs);
assertThat(postSignupRequestBody.getExternalId()).isEqualTo(expectedExternalId);
assertThat(postSignupRequestBody.getPolicyId()).isEqualTo(expectedPolicyId);
assertThat(postSignupRequestBody.getAddressLine()).isEqualTo(expectedAddressLine);
Expand Down

0 comments on commit 3ad44a1

Please sign in to comment.