Skip to content

Commit

Permalink
Merge pull request #42 from onfido/tests-github-actions
Browse files Browse the repository at this point in the history
Add GitHub actions workflow and pre-determined response functionality
  • Loading branch information
Phoebe-B authored May 18, 2021
2 parents 834022b + d3f312f commit 56539c2
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Build with Maven
run: mvn -B package --file pom.xml
2 changes: 1 addition & 1 deletion onfido-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.onfido</groupId>
<artifactId>onfido-api-java</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>

<name>Onfido API Java Client</name>
<description>Official Java API client library for the Onfido API</description>
Expand Down
13 changes: 13 additions & 0 deletions onfido-java/src/main/models/check.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@
"type": "string"
},
"description": "Array of strings describing which webhooks to trigger for a check."
},
"sub_result": {
"type": "string",
"writeOnly": true,
"description": "Triggers responses for particular sub-results for sandbox Document reports."
},
"consider": {
"type": "array",
"items": {
"type": "string"
},
"writeOnly": true,
"description": "Triggers a pre-determined 'consider' report result in the sandbox for reports specified in the array."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.testng.annotations.Test;
import java.util.ArrayList;

public class CheckManagerTest extends ApiIntegrationTest {

Expand All @@ -20,6 +21,7 @@ public void createCheck() throws Exception {
new JsonObject()
.add("applicant_id", "id")
.add("webhook_ids", null)
.add("privacy_notices_read_consent_given", true)
.toJson();

MockWebServer server = mockRequestResponse(response);
Expand All @@ -28,7 +30,7 @@ public void createCheck() throws Exception {
Onfido.builder().apiToken("token").unknownApiUrl(server.url("/").toString()).build();

Check check =
onfido.check.create(Check.request().applicantId("id").reportNames("report_name_1"));
onfido.check.create(Check.request().applicantId("id").reportNames("report_name_1").privacyNoticesReadConsentGiven(true));

// Correct path
RecordedRequest request = server.takeRequest();
Expand All @@ -38,10 +40,72 @@ public void createCheck() throws Exception {
String json = request.getBody().readUtf8();
JsonObject jsonObject = JsonObject.parse(json);
assertEquals("id", jsonObject.get("applicant_id"));
assertEquals(true, jsonObject.get("privacy_notices_read_consent_given"));

// Correct response body
assertEquals("id", check.getApplicantId());
assertEquals(null, check.getWebhookIds());
assertEquals(true, check.getPrivacyNoticesReadConsentGiven());
}

@Test
public void createSubResultCheck() throws Exception {
String response =
new JsonObject()
.add("applicant_id", "id")
.toJson();

MockWebServer server = mockRequestResponse(response);

Onfido onfido =
Onfido.builder().apiToken("token").unknownApiUrl(server.url("/").toString()).build();

Check check =
onfido.check.create(Check.request().applicantId("id").reportNames("document").subResult("rejected"));

// Correct path
RecordedRequest request = server.takeRequest();
assertEquals("/checks/", request.getPath());

// Correct request body
String json = request.getBody().readUtf8();
JsonObject jsonObject = JsonObject.parse(json);
assertEquals("id", jsonObject.get("applicant_id"));
assertEquals("rejected", jsonObject.get("sub_result"));

// Correct response body
assertEquals("id", check.getApplicantId());
}

@Test
public void createConsiderCheck() throws Exception {
String response =
new JsonObject()
.add("applicant_id", "id")
.toJson();

MockWebServer server = mockRequestResponse(response);

Onfido onfido =
Onfido.builder().apiToken("token").unknownApiUrl(server.url("/").toString()).build();

Check check =
onfido.check.create(Check.request().applicantId("id").reportNames("document", "identity_enhanced").consider("identity_enhanced"));

// Correct path
RecordedRequest request = server.takeRequest();
assertEquals("/checks/", request.getPath());

// Correct request body
String json = request.getBody().readUtf8();
JsonObject jsonObject = JsonObject.parse(json);
assertEquals("id", jsonObject.get("applicant_id"));
ArrayList<String> expectedConsiderArrayList = new ArrayList<>();
expectedConsiderArrayList.add("identity_enhanced");
assertEquals(expectedConsiderArrayList, jsonObject.get("consider"));

// Correct response body
assertEquals("id", check.getApplicantId());
}

@Test
Expand Down

0 comments on commit 56539c2

Please sign in to comment.