-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from onfido/test-id_photos
Tests id_photos endpoints
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters