Skip to content

Commit

Permalink
add trait tags tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris T committed Jul 12, 2021
1 parent d822f2b commit a1ca5b3
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,25 @@ public void getTraitsNoExistInBrAPI() {
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, e.getStatus());
}

@Test
@SneakyThrows
@Order(1)
public void getTraitTagsDefaultFavorites() {

Flowable<HttpResponse<String>> call = client.exchange(
GET("/programs/" + otherValidProgram.getId() + "/traits/tags").cookie(new NettyCookie("phylo-token", "test-registered-user")), String.class
);

HttpResponse<String> response = call.blockingFirst();
assertEquals(HttpStatus.OK, response.getStatus());

JsonObject result = JsonParser.parseString(response.body()).getAsJsonObject().getAsJsonObject("result");
JsonArray data = result.getAsJsonArray("data");

assertEquals(1, data.size(), "Wrong number of results returned.");
assertEquals("favorites", data.get(0).getAsString(), "Wrong default tag returned");
}

@Test
@SneakyThrows
@Order(2)
Expand Down Expand Up @@ -287,6 +306,10 @@ public void postTraitsMultiple() {
setBrAPIProperties(trait1);
setBrAPIProperties(trait2);

// Set the tags
trait1.setTags(List.of("leaf trait"));
trait2.setTags(List.of("stem trait"));

List<Trait> traits = List.of(trait1, trait2);

// Call endpoint
Expand Down Expand Up @@ -326,6 +349,31 @@ public void postTraitsMultiple() {
validTraits = traits;
}

@Test
@SneakyThrows
@Order(4)
public void getTraitTags() {

Flowable<HttpResponse<String>> call = client.exchange(
GET("/programs/" + validProgram.getId() + "/traits/tags").cookie(new NettyCookie("phylo-token", "test-registered-user")), String.class
);

HttpResponse<String> response = call.blockingFirst();
assertEquals(HttpStatus.OK, response.getStatus());

JsonObject result = JsonParser.parseString(response.body()).getAsJsonObject().getAsJsonObject("result");
JsonArray data = result.getAsJsonArray("data");

assertEquals(3, data.size(), "Wrong number of results returned.");
Set<String> tagsList = new HashSet<>(List.of("favorites", "leaf trait", "stem trait"));
Set<String> foundTags = new HashSet<>();
for (JsonElement tagElement: data) {
foundTags.add(tagElement.getAsString());
}

assertTrue(tagsList.equals(foundTags), "Returned tags do not equal expected tags");
}

@Test
@Order(4)
public void postTraitsMultipleExistInDb() {
Expand Down

0 comments on commit a1ca5b3

Please sign in to comment.