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

Fix webhooks event tests #130

Closed
wants to merge 1 commit into from
Closed
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
@@ -1,7 +1,5 @@
package com.onfido.integration;

import static com.onfido.model.WorkflowRun.StatusEnum.APPROVED;

import com.google.gson.Gson;
import com.onfido.model.*;
import java.io.FileReader;
Expand Down Expand Up @@ -87,11 +85,11 @@ public void documentAndFacialSimilarityReportsAsOutputs() throws Exception {
repeatRequestUntilStatusChanges(
"findWorkflowRun",
new UUID[] {workflowRunId},
WorkflowRun.StatusEnum.APPROVED,
WorkflowRunStatus.APPROVED,
10,
1000);

Assertions.assertEquals(APPROVED, workflowRun.getStatus());
Assertions.assertEquals(WorkflowRunStatus.APPROVED, workflowRun.getStatus());

Map<?, ?> workflowRunOutput = (Map<?, ?>) workflowRun.getOutput();

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/onfido/integration/WorkflowRunTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.onfido.model.TimelineFileReference;
import com.onfido.model.WorkflowRun;
import com.onfido.model.WorkflowRunBuilder;
import com.onfido.model.WorkflowRunStatus;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -48,8 +49,7 @@ public void createWorkflowRunWithCustomInputsTest() throws Exception {

Assertions.assertEquals(workflowId, workflowRunWithCustomInputs.getWorkflowId());
Assertions.assertEquals(applicantId, workflowRunWithCustomInputs.getApplicantId());
Assertions.assertEquals(
WorkflowRun.StatusEnum.APPROVED, workflowRunWithCustomInputs.getStatus());
Assertions.assertEquals(WorkflowRunStatus.APPROVED, workflowRunWithCustomInputs.getStatus());
}

@Test
Expand All @@ -73,7 +73,7 @@ public void generateTimelineFileTest() throws Exception {
UUID workflowRunId = createWorkflowRun(WORKFLOW_ID_TIMELINE, applicantId).getId();

repeatRequestUntilStatusChanges(
"findWorkflowRun", new UUID[] {workflowRunId}, WorkflowRun.StatusEnum.APPROVED, 10, 1000);
"findWorkflowRun", new UUID[] {workflowRunId}, WorkflowRunStatus.APPROVED, 10, 1000);
TimelineFileReference workflowTimelineFileData = onfido.createTimelineFile(workflowRunId);

Assertions.assertNotNull(workflowTimelineFileData.getWorkflowTimelineFileId());
Expand All @@ -85,7 +85,7 @@ public void findTimelineFileTest() throws Exception {
UUID workflowRunId = createWorkflowRun(WORKFLOW_ID_TIMELINE, applicantId).getId();

repeatRequestUntilStatusChanges(
"findWorkflowRun", new UUID[] {workflowRunId}, WorkflowRun.StatusEnum.APPROVED, 10, 1000);
"findWorkflowRun", new UUID[] {workflowRunId}, WorkflowRunStatus.APPROVED, 10, 1000);
UUID timelineFileId = onfido.createTimelineFile(workflowRunId).getWorkflowTimelineFileId();

FileTransfer download =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.onfido.WebhookEventVerifier;
import com.onfido.integration.TestBase;
import com.onfido.model.WebhookEvent;
import com.onfido.model.WebhookEventObjectStatus;
import com.onfido.model.WebhookEventPayload;
import com.onfido.model.WebhookEventPayloadObject;
import com.onfido.model.WebhookEventResourceType;
import com.onfido.model.WebhookEventType;
import java.time.OffsetDateTime;
import org.junit.jupiter.api.Assertions;
Expand All @@ -26,13 +28,13 @@ public class WebhookClassicEventVerifierTest extends TestBase {
.payload(
new WebhookEventPayload()
.action(WebhookEventType.CHECK_COMPLETED)
.resourceType("check")
.resourceType(WebhookEventResourceType.CHECK)
._object(
new WebhookEventPayloadObject()
.id("f2302f45-227d-413d-ad61-09ec077a086a")
.href(
"https://api.onfido.com/v3.6/checks/f2302f45-227d-413d-ad61-09ec077a086a")
.status("complete")
.status(WebhookEventObjectStatus.COMPLETE)
.completedAtIso8601(OffsetDateTime.parse("2024-04-04T09:21:21Z"))));

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import com.onfido.WebhookEventVerifier;
import com.onfido.integration.TestBase;
import com.onfido.model.WebhookEvent;
import com.onfido.model.WebhookEventObjectStatus;
import com.onfido.model.WebhookEventPayload;
import com.onfido.model.WebhookEventPayloadObject;
import com.onfido.model.WebhookEventPayloadResource;
import com.onfido.model.WebhookEventResourceType;
import com.onfido.model.WebhookEventType;
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.UUID;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -27,16 +32,19 @@ public class WebhookStudioEventVerifierTest extends TestBase {
private static final WebhookEventPayloadObject expectedObject =
new WebhookEventPayloadObject()
.id("profile_1eb92")
.status("started")
.status(WebhookEventObjectStatus.STARTED)
.startedAtIso8601(OffsetDateTime.parse("2024-07-10T12:49:09Z"))
.href(
"https://api.eu.onfido.com/v3.6/workflow_runs/bc77c6e5-753a-4580-96a6-aaed3e5a8d19/tasks/profile_1eb92");

private static final String expectedResource =
"{created_at=2024-07-10T12:49:09Z, id=profile_1eb92,"
+ " workflow_run_id=bc77c6e5-753a-4580-96a6-aaed3e5a8d19,"
+ " updated_at=2024-07-10T12:49:09Z, input={}, task_def_version=null,"
+ " task_def_id=profile_data, output=null}";
private static final WebhookEventPayloadResource expectedResource =
new WebhookEventPayloadResource()
.createdAt(OffsetDateTime.parse("2024-07-10T12:49:09Z"))
.id("profile_1eb92")
.workflowRunId(UUID.fromString("bc77c6e5-753a-4580-96a6-aaed3e5a8d19"))
.updatedAt(OffsetDateTime.parse("2024-07-10T12:49:09Z"))
.input(new HashMap<>())
.taskDefId("profile_data");

@Test
public void validSignatureTest() throws Exception {
Expand All @@ -46,11 +54,10 @@ public void validSignatureTest() throws Exception {
WebhookEventPayload webhookPayload = event.getPayload();

Assertions.assertEquals(WebhookEventType.WORKFLOW_TASK_STARTED, webhookPayload.getAction());
Assertions.assertEquals("workflow_task", webhookPayload.getResourceType());
Assertions.assertEquals(
WebhookEventResourceType.WORKFLOW_TASK, webhookPayload.getResourceType());
Assertions.assertEquals(expectedObject, webhookPayload.getObject());

// TODO fix me once Resource accessors are made available
Assertions.assertEquals(webhookPayload.getResource().toString(), expectedResource);
Assertions.assertEquals(expectedResource, webhookPayload.getResource());
}

@Test
Expand Down
Loading