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

Tests id_photos endpoints #113

Merged
merged 1 commit into from
Jun 5, 2024
Merged
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
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
Loading