-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathVerificationEventTest.java
More file actions
101 lines (89 loc) · 4.37 KB
/
VerificationEventTest.java
File metadata and controls
101 lines (89 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.siftscience;
import static java.net.HttpURLConnection.HTTP_OK;
import com.siftscience.model.App;
import com.siftscience.model.VerificationFieldSet;
import okhttp3.OkHttpClient;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.Assert;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;
public class VerificationEventTest {
@Test
public void testVerification() throws Exception {
String sessionId = "gigtleqddo84l8cm15qe4il";
String verifiedValue = "14155551212";
String verifiedEvent = "$create_content";
String verifiedEntityId = "chekle212452";
String reason = "$user_setting";
String expectedRequestBody = "{\n" +
" \"$type\" : \"$verification\",\n" +
" \"$api_key\" : \"YOUR_API_KEY\",\n" +
" \"$user_id\" : \"billy_jones_301\",\n" +
" \"$session_id\" : \"" + sessionId + "\",\n" +
" \"$app\" : {\n" +
" \"$os\" : \"iOS\",\n" +
" \"$app_name\" : \"Calculator\",\n" +
" \"$device_manufacturer\" : \"Apple\",\n" +
" \"$device_model\" : \"iPhone 4,2\",\n" +
" \"$device_unique_id\" : \"A3D261E4-DE0A-470B-9E4A-720F3D3D22E6\",\n" +
" \"$app_version\" : \"3.2.7\"\n" +
" },\n" +
" \"$status\" : \"$pending\",\n" +
" \"$verification_type\" : \"$sms\",\n" +
" \"$verified_value\" : \"" + verifiedValue + "\",\n" +
" \"$verified_event\" : \"" + verifiedEvent + "\",\n" +
" \"$verified_entity_id\" : \"" + verifiedEntityId + "\",\n" +
" \"$reason\" : \"" + reason + "\",\n" +
" \"$ip\" : \"128.148.1.135\"\n" +
"}";
// Start a new mock server and enqueue a mock response.
MockWebServer server = new MockWebServer();
MockResponse response = new MockResponse();
response.setResponseCode(HTTP_OK);
response.setBody("{\n" +
" \"status\" : 0,\n" +
" \"error_message\" : \"OK\",\n" +
" \"time\" : 1327604222,\n" +
" \"request\" : \"" + TestUtils.unescapeJson(expectedRequestBody) + "\"\n" +
"}");
server.enqueue(response);
server.start();
// Create a new client and link it to the mock server.
SiftClient client = new SiftClient("YOUR_API_KEY", "YOUR_ACCOUNT_ID",
new OkHttpClient.Builder()
.addInterceptor(OkHttpUtils.urlRewritingInterceptor(server))
.build());
// Build and execute the request against the mock server.
SiftRequest request = client.buildRequest(new VerificationFieldSet()
.setUserId("billy_jones_301")
.setSessionId(sessionId)
.setStatus("$pending")
.setVerificationType("$sms")
.setVerifiedValue(verifiedValue)
.setReason(reason)
.setVerifiedEvent(verifiedEvent)
.setVerifiedEntityId(verifiedEntityId)
.setIp("128.148.1.135")
.setApp(new App()
.setAppName("Calculator")
.setAppVersion("3.2.7")
.setDeviceManufacturer("Apple")
.setDeviceModel("iPhone 4,2")
.setDeviceUniqueId("A3D261E4-DE0A-470B-9E4A-720F3D3D22E6")
.setOperatingSystem("iOS")));
SiftResponse siftResponse = request.send();
// Verify the request.
RecordedRequest request1 = server.takeRequest();
Assert.assertEquals("POST", request1.getMethod());
Assert.assertEquals("/v205/events", request1.getPath());
JSONAssert.assertEquals(expectedRequestBody, request.getFieldSet().toJson(), true);
// Verify the response.
Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode());
Assert.assertEquals(0, (int) siftResponse.getBody().getStatus());
JSONAssert.assertEquals(response.getBody().readUtf8(),
siftResponse.getBody().toJson(), true);
server.shutdown();
}
}