Skip to content

Commit 8767022

Browse files
author
Sergey Shelomentsev
committed
chore: add tests for update evemt
1 parent 9996331 commit 8767022

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

sdk/src/test/java/com/fingerprint/api/FingerprintApiTest.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
77
import com.fingerprint.model.*;
88
import com.fingerprint.sdk.*;
9-
import org.junit.jupiter.api.Assertions;
109
import org.junit.jupiter.api.BeforeAll;
1110
import org.junit.jupiter.api.Test;
1211

1312
import java.io.IOException;
1413
import java.io.InputStream;
15-
import java.util.LinkedHashMap;
1614
import java.util.Map;
1715

1816
import org.junit.jupiter.api.TestInstance;
@@ -29,6 +27,7 @@
2927
public class FingerprintApiTest {
3028
private FingerprintApi api;
3129
private static final String MOCK_REQUEST_ID = "0KSh65EnVoB85JBmloQK";
30+
private static final String MOCK_REQUEST_FOR_UPDATE = "1722878691275.6RRrbn";
3231
private static final String MOCK_REQUEST_WITH_EXTRA_FIELDS_ID = "EXTRA_FIELDS";
3332
private static final String MOCK_REQUEST_WITH_ALL_FAILED_SIGNALS = "ALL_FAILED_SIGNALS";
3433
private static final String MOCK_REQUEST_BOTD_FAILED = "MOCK_REQUEST_BOTD_FAILED";
@@ -40,6 +39,7 @@ public class FingerprintApiTest {
4039
private static final String MOCK_WEBHOOK_VISITOR_ID = "3HNey93AkBW6CRbxV6xP";
4140
private static final String MOCK_WEBHOOK_REQUEST_ID = "Px6VxbRC6WBkA39yeNH3";
4241

42+
private static final ObjectMapper MAPPER = getMapper();
4343

4444
private InputStream getFileAsIOStream(final String fileName) {
4545
InputStream ioStream = this.getClass()
@@ -56,6 +56,7 @@ private InputStream getFileAsIOStream(final String fileName) {
5656
public void before() throws ApiException, IOException {
5757
api = Mockito.mock(FingerprintApi.class);
5858
when(api.getEvent(MOCK_REQUEST_ID)).thenReturn(fetchMockWithEventResponse("mocks/get_event_200.json"));
59+
//when(api.getEvent(MOCK_REQUEST_ID)).thenReturn(fetchMockWithEventResponse("mocks/update_event_400_error.json"));
5960
when(api.getEvent(MOCK_REQUEST_WITH_EXTRA_FIELDS_ID)).thenReturn(fetchMockWithEventResponse("mocks/get_event_200_extra_fields.json"));
6061
when(api.getEvent(MOCK_REQUEST_WITH_ALL_FAILED_SIGNALS)).thenReturn(fetchMockWithEventResponse("mocks/get_event_200_all_errors.json"));
6162
when(api.getEvent(MOCK_REQUEST_BOTD_FAILED)).thenReturn(fetchMockWithEventResponse("mocks/get_event_200_botd_failed_error.json"));
@@ -66,14 +67,21 @@ public void before() throws ApiException, IOException {
6667
when(api.getVisits(MOCK_VISITOR_ID, MOCK_VISITOR_REQUEST_ID, null, 50, "1683900801733.Ogvu1j", null)).thenReturn(fetchMockVisit());
6768
}
6869

69-
private EventResponse fetchMockWithEventResponse(String fileName) throws IOException {
70+
private static ObjectMapper getMapper() {
7071
ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule());
7172
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
7273
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
7374
JsonNullableModule jnm = new JsonNullableModule();
7475
mapper.registerModule(jnm);
76+
return mapper;
77+
}
78+
79+
private EventResponse fetchMockWithEventResponse(String fileName) throws IOException {
80+
return MAPPER.readValue(getFileAsIOStream(fileName), EventResponse.class);
81+
}
7582

76-
return mapper.readValue(getFileAsIOStream(fileName), EventResponse.class);
83+
private <T> T fetchMock(String filename, Class<T> type) throws IOException {
84+
return MAPPER.readValue(getFileAsIOStream(filename), type);
7785
}
7886

7987
private Response fetchMockVisit() throws IOException {
@@ -119,6 +127,18 @@ public void getEventTest() throws ApiException {
119127
assertEquals(true, signalResponseRawDeviceAttributes.getData().get("cookiesEnabled").getValue());
120128
}
121129

130+
@Test
131+
public void updateOneFieldEventRequest() throws ApiException, IOException {
132+
EventUpdateRequest request = fetchMock("mocks/update_event_one_field_request.json", EventUpdateRequest.class);
133+
api.updateEvent(MOCK_REQUEST_FOR_UPDATE, request);
134+
}
135+
136+
@Test
137+
public void updateMultipleFieldsEventRequest() throws ApiException, IOException {
138+
EventUpdateRequest request = fetchMock("mocks/update_event_multiple_fields_request.json", EventUpdateRequest.class);
139+
api.updateEvent(MOCK_REQUEST_FOR_UPDATE, request);
140+
}
141+
122142
/**
123143
* Get event by requestId
124144
* This endpoint allows you to get events with all the information from each activated product (Fingerprint Pro or Bot Detection). Use the requestId as a URL path :request_id parameter. This API method is scoped to a request, i.e. all returned information is by requestId.

0 commit comments

Comments
 (0)