Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import org.a5calls.android.a5calls.model.Contact;
import org.a5calls.android.a5calls.model.Issue;
import org.a5calls.android.a5calls.model.Outcome;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -352,28 +355,18 @@ public void testGetContacts_malformedJson() {
}

@Test
public void testReportCall() {
byte[] bytes = "{\"ok\":true}".getBytes();
ArrayList<Header> headers = new ArrayList<>();
headers.add(new Header("Content-Type", "text/json"));
HttpResponse response = new HttpResponse(200, headers);
mHttpStack.setResponseToReturn(response);

TestCallListener testCallListener = new TestCallListener();
mApi.registerCallRequestListener(testCallListener);

mApi.reportCall("myIssue", "myRep", "unavailable", "myLocation");
waitForHttpRequestComplete();

assertEquals(1, testCallListener.mCallReported);
assertEquals(0, testCallListener.mCallError);
assertEquals(0, testCallListener.mCallJsonError);
public void testReportCallUnavailable() {
testReportCallStatus(Outcome.Status.UNAVAILABLE, "unavailable");
}

assertEquals(new String(mHttpStack.getLastPostBody()),
"result=unavailable&issueid=myIssue&contactid=myRep&callerid=itMe&via=" +
(FiveCallsApi.TESTING ? "test&" : "android&"));
@Test
public void testReportCallVoicemail() {
testReportCallStatus(Outcome.Status.VOICEMAIL, "voicemail");
}

mApi.unregisterCallRequestListener(testCallListener);
@Test
public void testReportCallContact() {
testReportCallStatus(Outcome.Status.CONTACT, "contact");
}

@Test
Expand All @@ -383,7 +376,7 @@ public void testReportCall_serverError() {
TestCallListener testCallListener = new TestCallListener();
mApi.registerCallRequestListener(testCallListener);

mApi.reportCall("myIssue", "myRep", "unavailable", "myLocation");
mApi.reportCall("myIssue", "myRep", Outcome.Status.UNAVAILABLE);
waitForHttpRequestComplete();

assertEquals(0, testCallListener.mCallReported);
Expand Down Expand Up @@ -425,6 +418,50 @@ public void newsletterSubscribe_serverError() {
assertFalse(testNewsletterListener.mSubscribeSuccess);
}

@Test
public void reportSearch() {
ArrayList<Header> headers = new ArrayList<>();
headers.add(new Header("Content-Type", "text/json"));
HttpResponse response = new HttpResponse(200, headers);
mHttpStack.setResponseToReturn(response);

mApi.reportSearch("Banana phone");
waitForHttpRequestComplete();

assertEquals("https://api.5calls.org/v1/users/search", mHttpStack.getLastUrl());
try {
JSONObject params = new JSONObject(new String(mHttpStack.getLastPostBody()));
assertEquals("Banana phone", params.get("query"));
assertEquals("android", params.get("via"));
} catch (JSONException e) {
fail(e.getMessage());
}
}

private void testReportCallStatus(Outcome.Status status, String outcomeString) {
ArrayList<Header> headers = new ArrayList<>();
headers.add(new Header("Content-Type", "text/json"));
HttpResponse response = new HttpResponse(200, headers);
mHttpStack.setResponseToReturn(response);

TestCallListener testCallListener = new TestCallListener();
mApi.registerCallRequestListener(testCallListener);

mApi.reportCall("myIssue", "myRep", status);
waitForHttpRequestComplete();

assertEquals(1, testCallListener.mCallReported);
assertEquals(0, testCallListener.mCallError);
assertEquals(0, testCallListener.mCallJsonError);

assertEquals("https://api.5calls.org/v1/report", mHttpStack.getLastUrl());
assertEquals(new String(mHttpStack.getLastPostBody()),
"result=" + outcomeString + "&issueid=myIssue&contactid=myRep&callerid=itMe&via=" +
(FiveCallsApi.TESTING ? "test&" : "android&"));

mApi.unregisterCallRequestListener(testCallListener);
}

private void waitForHttpRequestComplete() {
assertNotNull(mRequestQueue.mRequest);
mRequestQueue.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private void reportCall(Outcome outcome, String address) {
mIssue.name, mIssue.contacts.get(mActiveContactIndex).id,
mIssue.contacts.get(mActiveContactIndex).name, outcome.status.toString(), address);
AppSingleton.getInstance(getApplicationContext()).getJsonController().reportCall(
mIssue.id, mIssue.contacts.get(mActiveContactIndex).id, outcome.label, address);
mIssue.id, mIssue.contacts.get(mActiveContactIndex).id, outcome.status);
}

private void setupContactUi(int index, boolean expandLocalSection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,7 @@ public void onErrorResponse(VolleyError error) {
mRequestQueue.add(reportRequest);
}

// Result is "VOICEMAIL", "unavailable", or "contacted"
// https://github.com/5calls/5calls/blob/master/static/js/main.js#L221
public void reportCall(final String issueId, final String contactId, final String result,
final String zip) {
public void reportCall(final String issueId, final String contactId, final Outcome.Status result) {
String getReport = GET_REPORT;
StringRequest request = new StringRequest(Request.Method.POST, getReport,
new Response.Listener<String>() {
Expand All @@ -430,7 +427,7 @@ public void onErrorResponse(VolleyError error) {
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("issueid", issueId);
params.put("result", result);
params.put("result", result.toString());
params.put("contactid", contactId);
params.put("via", (BuildConfig.DEBUG && TESTING) ? "test" : "android");
params.put("callerid", mCallerId);
Expand Down Expand Up @@ -486,18 +483,12 @@ public void reportSearch(String searchTerm) {
try {
JSONObject jsonBody = new JSONObject();
jsonBody.put("query", searchTerm);
jsonBody.put("via", "android");

JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, SEARCH_TRACKING, jsonBody, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// Search report successful - no action needed
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.w(TAG, "Search tracking failed: " + error.getMessage());
}
});
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, SEARCH_TRACKING,
jsonBody, response -> {
// Search report successful - no action needed
}, error -> Log.w(TAG, "Search tracking failed: " + error.getMessage()));
request.setTag(TAG);
// Add the request to the RequestQueue.
mRequestQueue.add(request);
Expand Down