Skip to content

Commit

Permalink
add new rounds methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsobries committed Jul 2, 2024
1 parent fba7ab9 commit 4c48a38
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/integration/java/org/arkecosystem/client/api/RoundsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,36 @@
import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;

public class RoundsTest extends BaseClientTest {
public class RoundsIntegrationTest extends BaseClientTest {

@Test
void delegates() throws IOException {
Map<String, Object> actual = connection.api().rounds.delegates(12345);
assertThat(actual, hasKey("data"));
}

@Test
void all() throws IOException {
Map<String, Object> actual = connection.api().rounds.all();
assertThat(actual, hasKey("data"));
assertThat(actual, hasKey("meta"));
}

@Test
void allWithParams() throws IOException {
Map<String, Object> actual =
connection.api().rounds.param("page", 1).param("limit", 100).all();
assertThat(actual, hasKey("data"));
assertThat(actual, hasKey("meta"));
}

@Test
void show() throws IOException {
Map<String, Object> actual = connection.api().rounds.show(12345);
assertThat(actual, hasKey("data"));
assertThat((Map<String, ?>) actual.get("data"), hasEntry("id", 12345.0));
}
}
15 changes: 15 additions & 0 deletions src/main/java/org/arkecosystem/client/api/Rounds.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
package org.arkecosystem.client.api;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import org.arkecosystem.client.http.Client;

public class Rounds {
private final Client client;
private final Map<String, Object> params = new LinkedHashMap<>();

public Rounds(Client client) {
this.client = client;
}

public Rounds param(String name, Object value) {
params.put(name, value);
return this;
}

public Map<String, Object> delegates(int id) throws IOException {
return this.client.get("rounds/" + id + "/delegates");
}

public Map<String, Object> all() throws IOException {
return this.client.get("rounds", params);
}

public Map<String, Object> show(int roundId) throws IOException {
return this.client.get("rounds/" + roundId);
}
}
22 changes: 22 additions & 0 deletions src/test/java/org/arkecosystem/client/api/RoundsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,26 @@ void delegates() throws IOException {
Map<String, Object> actual = connection.api().rounds.delegates(12345);
assertTrue((boolean) actual.get("success"));
}

@Test
void all() throws IOException {
Connection connection = MockHelper.connection();
Map<String, Object> actual = connection.api().rounds.all();
assertTrue((boolean) actual.get("success"));
}

@Test
void allWithParams() throws IOException {
Connection connection = MockHelper.connection();
Map<String, Object> actual =
connection.api().rounds.param("page", 1).param("limit", 100).all();
assertTrue((boolean) actual.get("success"));
}

@Test
void show() throws IOException {
Connection connection = MockHelper.connection();
Map<String, Object> actual = connection.api().rounds.show(12345);
assertTrue((boolean) actual.get("success"));
}
}

0 comments on commit 4c48a38

Please sign in to comment.