Skip to content

Commit

Permalink
feat: allow to pass feedback event type as string
Browse files Browse the repository at this point in the history
  • Loading branch information
figueredo committed Jul 24, 2024
1 parent 3285df2 commit 38f2459
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 4 deletions.
75 changes: 74 additions & 1 deletion src/main/java/com/incognia/api/IncogniaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,8 @@ public void registerFeedback(
* FeedbackIdentifiers.builder()
* .installationId("installation-id")
* .accountId("account-id")
* .build());
* .build(),
* false);
* } catch (IncogniaAPIException e) {
* //Some api error happened (invalid data, invalid credentials)
* } catch (IncogniaException e) {
Expand All @@ -439,6 +440,78 @@ public void registerFeedback(
FeedbackIdentifiers identifiers,
boolean dryRun)
throws IncogniaException {
registerFeedback(feedbackEvent.getEventName(), occurredAt, identifiers, dryRun);
}

/**
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* Instant occurredAt = Instant.parse("2024-07-22T15:20:00Z");
* api.registerFeedback(
* "account_takeover",
* occurredAt,
* FeedbackIdentifiers.builder()
* .installationId("installation-id")
* .accountId("account-id")
* .build());
* } catch (IncogniaAPIException e) {
* //Some api error happened (invalid data, invalid credentials)
* } catch (IncogniaException e) {
* //Something unexpected happened
* }
* }</pre>
*
* @param feedbackEvent type of feedback event
* @param occurredAt Instant when the fraud or event happened
* @param identifiers the user's identifiers
* @throws IncogniaAPIException in case of api errors
* @throws IncogniaException in case of unexpected errors
*/
public void registerFeedback(
String feedbackEvent, Instant occurredAt, FeedbackIdentifiers identifiers)
throws IncogniaException {
registerFeedback(feedbackEvent, occurredAt, identifiers, false);
}

/**
* Shares feedback about a risk decision, improving the quality of risk assessments. Check <a
* href="https://dash.incognia.com/api-reference#operation/feedbacks-post">the docs</a><br>
* Example:
*
* <pre>{@code
* IncogniaAPI api = new IncogniaAPI("client-id", "client-secret");
* try {
* Instant occurredAt = Instant.parse("2024-07-22T15:20:00Z");
* api.registerFeedback(
* "account_takeover",
* occurredAt,
* FeedbackIdentifiers.builder()
* .installationId("installation-id")
* .accountId("account-id")
* .build(),
* false);
* } catch (IncogniaAPIException e) {
* //Some api error happened (invalid data, invalid credentials)
* } catch (IncogniaException e) {
* //Something unexpected happened
* }
* }</pre>
*
* @param feedbackEvent type of feedback event
* @param occurredAt Instant when the fraud or event happened
* @param identifiers the user's identifiers
* @param dryRun whether this request is a dry-run
* @throws IncogniaAPIException in case of api errors
* @throws IncogniaException in case of unexpected errors
*/
public void registerFeedback(
String feedbackEvent, Instant occurredAt, FeedbackIdentifiers identifiers, boolean dryRun)
throws IncogniaException {
PostFeedbackRequestBody requestBody =
PostFeedbackRequestBody.builder()
.event(feedbackEvent)
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/incognia/feedback/FeedbackEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ public enum FeedbackEvent {
CUSTOM_CARGO_FRAUD,
@JsonProperty("custom_debt_churn_20d")
CUSTOM_DEBT_CHURN_20D;

public String getEventName() {
return this.name().toLowerCase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Value
@Builder
public class PostFeedbackRequestBody {
FeedbackEvent event;
String event;
@Deprecated Long timestamp;
Instant occurredAt;
String accountId;
Expand Down
42 changes: 40 additions & 2 deletions src/test/java/com/incognia/api/IncogniaAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ void testRegisterPayment_whenEvalIsFalse() {
@ValueSource(booleans = {true, false})
@DisplayName("should be successful")
@SneakyThrows
void testRegisterFeedback_whenDataIsValid(boolean dryRun) {
void testRegisterFeedback_whenUsingFeedbackEventEnum_andDataIsValid(boolean dryRun) {
String token = TokenCreationFixture.createToken();
String installationId = "installation-id";
String sessionToken = "session-token";
Expand All @@ -555,7 +555,7 @@ void testRegisterFeedback_whenDataIsValid(boolean dryRun) {
.externalId(externalId)
.signupId(signupId)
.accountId(accountId)
.event(FeedbackEvent.ACCOUNT_TAKEOVER)
.event(FeedbackEvent.ACCOUNT_TAKEOVER.getEventName())
.occurredAt(timestamp)
.build());
mockServer.setDispatcher(dispatcher);
Expand All @@ -572,6 +572,44 @@ void testRegisterFeedback_whenDataIsValid(boolean dryRun) {
dryRun);
}

@ParameterizedTest
@ValueSource(booleans = {true, false})
@DisplayName("should be successful")
@SneakyThrows
void testRegisterFeedback_whenUsingFeedbackEventAsString_andDataIsValid(boolean dryRun) {
String token = TokenCreationFixture.createToken();
String installationId = "installation-id";
String sessionToken = "session-token";
String accountId = "account-id";
String externalId = "external-id";
String signupId = UUID.randomUUID().toString();
Instant timestamp = Instant.now();

TokenAwareDispatcher dispatcher = new TokenAwareDispatcher(token, CLIENT_ID, CLIENT_SECRET);
dispatcher.setExpectedFeedbackRequestBody(
PostFeedbackRequestBody.builder()
.installationId(installationId)
.sessionToken(sessionToken)
.externalId(externalId)
.signupId(signupId)
.accountId(accountId)
.event("custom_feedback_type")
.occurredAt(timestamp)
.build());
mockServer.setDispatcher(dispatcher);
client.registerFeedback(
"custom_feedback_type",
timestamp,
FeedbackIdentifiers.builder()
.installationId(installationId)
.sessionToken(sessionToken)
.accountId(accountId)
.externalId(externalId)
.signupId(signupId)
.build(),
dryRun);
}

@Test
@DisplayName("should throw illegal argument exception with correct message")
@SneakyThrows
Expand Down

0 comments on commit 38f2459

Please sign in to comment.