Skip to content

Commit

Permalink
test: add related visitors test
Browse files Browse the repository at this point in the history
  • Loading branch information
TheUnderScorer committed Dec 17, 2024
1 parent e49248a commit 9d5e6af
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions sdk/src/test/java/com/fingerprint/api/FingerprintApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fingerprint.model.*;
import com.fingerprint.model.Webhook;
import com.fingerprint.sdk.*;
import com.fingerprint.sdk.ApiException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.mockito.Mockito;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

import org.junit.jupiter.api.TestInstance;
import org.mockito.Mockito;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -63,6 +61,7 @@ public void before() throws ApiException, IOException {
when(api.getEvent(MOCK_REQUEST_IDENTIFICATION_MANY_REQUEST)).thenReturn(fetchMockWithEventResponse("mocks/get_event_200_too_many_requests_error.json"));

when(api.getVisits(MOCK_VISITOR_ID, MOCK_VISITOR_REQUEST_ID, null, 50, "1683900801733.Ogvu1j", null)).thenReturn(fetchMockVisit());
when(api.getRelatedVisitors(MOCK_VISITOR_ID)).thenReturn(fetchMockVisitWithRelatedVisitorsResponse("mocks/related-visitors/get_related_visitors_200.json"));
}

private static ObjectMapper getMapper() {
Expand All @@ -76,6 +75,14 @@ private EventsGetResponse fetchMockWithEventResponse(String fileName) throws IOE
return MAPPER.readValue(getFileAsIOStream(fileName), EventsGetResponse.class);
}

private RelatedVisitorsResponse fetchMockVisitWithRelatedVisitorsResponse(String fileName) throws IOException {
return MAPPER.readValue(getFileAsIOStream(fileName), RelatedVisitorsResponse.class);
}

private ErrorResponse fetchMockErrorResponse(String fileName) throws IOException {
return MAPPER.readValue(getFileAsIOStream(fileName), ErrorResponse.class);
}

private <T> T fetchMock(String filename, Class<T> type) throws IOException {
return MAPPER.readValue(getFileAsIOStream(filename), type);
}
Expand Down Expand Up @@ -263,4 +270,12 @@ public void webhookTest() throws Exception {
assertEquals(MOCK_WEBHOOK_REQUEST_ID, visit.getRequestId());
}

@Test
public void relatedVisitorsTest() throws Exception {
RelatedVisitorsResponse response = api.getRelatedVisitors(MOCK_VISITOR_ID);
RelatedVisitorsResponse mock = fetchMockVisitWithRelatedVisitorsResponse("mocks/related-visitors/get_related_visitors_200.json");

assertEquals(response, mock);
}

}

0 comments on commit 9d5e6af

Please sign in to comment.