Skip to content

Commit b15aa2f

Browse files
committed
Add tests for status controller
1 parent 88edf54 commit b15aa2f

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.whispersystems.bithub.tests.controllers;
2+
3+
import static com.yammer.dropwizard.testing.JsonHelpers.fromJson;
4+
import static com.yammer.dropwizard.testing.JsonHelpers.jsonFixture;
5+
import static org.fest.assertions.api.Assertions.assertThat;
6+
import static org.mockito.Mockito.mock;
7+
import static org.mockito.Mockito.when;
8+
9+
import java.math.BigDecimal;
10+
11+
import javax.ws.rs.core.MediaType;
12+
13+
import org.junit.Test;
14+
import org.whispersystems.bithub.client.CoinbaseClient;
15+
import org.whispersystems.bithub.controllers.StatusController;
16+
import org.whispersystems.bithub.entities.RecentTransactionsResponse;
17+
18+
import com.sun.jersey.api.client.ClientResponse;
19+
import com.yammer.dropwizard.testing.ResourceTest;
20+
import com.yammer.dropwizard.views.ViewMessageBodyWriter;
21+
22+
public class StatusControllerTest extends ResourceTest {
23+
24+
private static final BigDecimal PAYOUT_RATE = new BigDecimal(0.02);
25+
private static final BigDecimal BALANCE = new BigDecimal(10.01);
26+
private static final BigDecimal EXCHANGE_RATE = new BigDecimal(1.0);
27+
28+
private final CoinbaseClient coinbaseClient = mock(CoinbaseClient.class);
29+
30+
@Override
31+
protected void setUpResources() throws Exception {
32+
33+
when(coinbaseClient.getRecentTransactions()).thenReturn(fromJson(jsonFixture("payloads/transactions.json"), RecentTransactionsResponse.class).getTransactions());
34+
when(coinbaseClient.getAccountBalance()).thenReturn(BALANCE);
35+
when(coinbaseClient.getExchangeRate()).thenReturn(EXCHANGE_RATE);
36+
addResource(new StatusController(coinbaseClient, PAYOUT_RATE));
37+
38+
addProvider(ViewMessageBodyWriter.class);
39+
}
40+
41+
@Test
42+
public void testTransactionsHtml() throws Exception {
43+
ClientResponse response = client().resource("/v1/status/transactions/")
44+
.get(ClientResponse.class);
45+
46+
assertThat(response.getStatus()).isEqualTo(200);
47+
assertThat(response.getType()).isEqualTo(MediaType.TEXT_HTML_TYPE);
48+
}
49+
50+
@Test
51+
public void testTransactionsJson() throws Exception {
52+
ClientResponse response = client().resource("/v1/status/transactions/").queryParam("format", "json")
53+
.get(ClientResponse.class);
54+
55+
assertThat(response.getStatus()).isEqualTo(200);
56+
assertThat(response.getType()).isEqualTo(MediaType.APPLICATION_JSON_TYPE);
57+
}
58+
59+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"current_user": {
3+
"id": "5011f33df8182b142400000e",
4+
"email": "[email protected]",
5+
"name": "User Two"
6+
},
7+
"balance": {
8+
"amount": "50.00000000",
9+
"currency": "BTC"
10+
},
11+
"total_count": 2,
12+
"num_pages": 1,
13+
"current_page": 1,
14+
"transactions": [
15+
{
16+
"transaction": {
17+
"id": "5018f833f8182b129c00002f",
18+
"created_at": "2012-08-01T02:34:43-07:00",
19+
"amount": {
20+
"amount": "-1.10000000",
21+
"currency": "BTC"
22+
},
23+
"request": true,
24+
"status": "pending",
25+
"sender": {
26+
"id": "5011f33df8182b142400000e",
27+
"name": "User Two",
28+
"email": "[email protected]"
29+
},
30+
"recipient": {
31+
"id": "5011f33df8182b142400000a",
32+
"name": "User One",
33+
"email": "[email protected]"
34+
},
35+
"notes": "Commit payment:__moxie0__ https://github.com/WhisperSystems/BitHub/commit/88edf54e5b57c80ac05093a9be90965fd41291c2"
36+
}
37+
},
38+
{
39+
"transaction": {
40+
"id": "5018f833f8182b129c00002e",
41+
"created_at": "2012-08-01T02:36:43-07:00",
42+
"hsh": "9d6a7d1112c3db9de5315b421a5153d71413f5f752aff75bf504b77df4e646a3",
43+
"amount": {
44+
"amount": "-1.00000000",
45+
"currency": "BTC"
46+
},
47+
"request": false,
48+
"status": "complete",
49+
"sender": {
50+
"id": "5011f33df8182b142400000e",
51+
"name": "User Two",
52+
"email": "[email protected]"
53+
},
54+
"recipient_address": "37muSN5ZrukVTvyVh3mT5Zc5ew9L9CBare",
55+
"notes": "Commit payment:__moxie0__ https://github.com/WhisperSystems/BitHub/commit/88edf54e5b57c80ac05093a9be90965fd41291c2"
56+
}
57+
}
58+
]
59+
}

0 commit comments

Comments
 (0)