Skip to content

Commit

Permalink
Merge pull request #113 from onfido/test-id_photos
Browse files Browse the repository at this point in the history
Tests id_photos endpoints
  • Loading branch information
sofia-gomes-onfido authored Jun 5, 2024
2 parents 1667792 + d277d7d commit 219e1a7
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/test/java/com/onfido/integration/IdPhotoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.onfido.integration;

import com.onfido.ApiException;
import com.onfido.model.Applicant;
import com.onfido.model.IdPhoto;
import java.io.File;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class IdPhotoTest extends TestBase {

private Applicant applicant;
private IdPhoto idPhoto;

@BeforeEach
public void setupTest() throws Exception {
applicant = createApplicant();
idPhoto = uploadIdPhoto(applicant, "sample_photo.png");
}

@Test
public void uploadIdPhotoTest() throws Exception {
Assertions.assertEquals(idPhoto.getId() + ".png", idPhoto.getFileName());
}

@Test
public void downloadIdPhotoTest() throws Exception {
File download = onfido.downloadIdPhoto(idPhoto.getId());

Assertions.assertTrue(download.length() > 0);
}

@Test
public void downloadErrorTest() throws Exception {
try {
onfido.downloadIdPhoto(nonExistingId);
Assertions.fail();
} catch (ApiException ex) {
Assertions.assertEquals(404, ex.getCode());
}
}

@Test
public void findIdPhotoTest() throws Exception {
IdPhoto lookupIdPhoto = onfido.findIdPhoto(idPhoto.getId());

Assertions.assertEquals(idPhoto.getId() + ".png", lookupIdPhoto.getFileName());
}

@Test
public void listIdPhotosTest() throws Exception {
uploadIdPhoto(applicant, "another_sample_photo.png");

List<IdPhoto> idPhotos =
onfido.listIdPhotos(applicant.getId()).getIdPhotos().stream()
.sorted(Comparator.comparing(IdPhoto::getFileName))
.collect(Collectors.toList());

Assertions.assertEquals(idPhotos.get(0).getId() + ".png", idPhotos.get(0).getFileName());
Assertions.assertEquals(idPhotos.get(1).getId() + ".png", idPhotos.get(1).getFileName());
}
}
5 changes: 5 additions & 0 deletions src/test/java/com/onfido/integration/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.onfido.model.CheckBuilder;
import com.onfido.model.CountryCodes;
import com.onfido.model.Document;
import com.onfido.model.IdPhoto;
import com.onfido.model.LivePhoto;
import com.onfido.model.LocationBuilder;
import com.onfido.model.Webhook;
Expand Down Expand Up @@ -92,6 +93,10 @@ protected LivePhoto uploadLivePhoto(Applicant applicant, String filename) throws
return onfido.uploadLivePhoto(applicant.getId(), new File("media/" + filename), true);
}

protected IdPhoto uploadIdPhoto(Applicant applicant, String filename) throws Exception {
return onfido.uploadIdPhoto(applicant.getId(), new File("media/" + filename));
}

protected Check createCheck(Applicant applicant, Document document, CheckBuilder checkBuilder)
throws IOException, InterruptedException, ApiException {
return onfido.createCheck(
Expand Down

0 comments on commit 219e1a7

Please sign in to comment.