Skip to content

Commit

Permalink
Do some e2e tests for multiplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Pelayori committed Apr 27, 2024
1 parent 2e5230b commit 008d580
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<java.version>17</java.version>
<sonar.sources>src/main/java,src/test/resources/features</sonar.sources>
<sonar.jacoco.reportPaths>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPaths>
<sonar.exclusions>**/controllers/CustomErrorController.java</sonar.exclusions>
<sonar.exclusions>**/controllers/CustomErrorController.java, **/**/InsertDataSampleService.java</sonar.exclusions>
</properties>
<dependencies>
<dependency>
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/com/uniovi/Wiq_UnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,46 @@ public void testGetPlayersByEmails() throws IOException, InterruptedException, J
}
}

@Test
@Order(35)
public void testGetPlayersByEmailsAndRole() throws IOException, InterruptedException, JSONException {
Player player = playerService.getUsersByRole("ROLE_USER").get(0);
ApiKey apiKey = player.getApiKey();

HttpResponse<String> response = sendRequest("GET", "/api/players", Map.of(),
Map.of("apiKey", apiKey.getKeyToken(),
"emails", player.getEmail(), "role", "ROLE_USER"));

Assertions.assertEquals(200, response.statusCode());
JSONObject json = parseJsonResponse(response);
JSONArray players = json.getJSONArray("players");
Assertions.assertTrue(players.length() > 0);
for (int i = 0; i < players.length(); i++) {
JSONObject playerJson = players.getJSONObject(i);
Assertions.assertEquals(player.getEmail(), playerJson.getString("email"));
}
}

@Test
@Order(35)
public void testGetPlayersByRole() throws IOException, InterruptedException, JSONException {
Player player = playerService.getUsersByRole("ROLE_USER").get(0);
ApiKey apiKey = player.getApiKey();

HttpResponse<String> response = sendRequest("GET", "/api/players", Map.of(),
Map.of("apiKey", apiKey.getKeyToken(),
"role", "ROLE_USER"));

Assertions.assertEquals(200, response.statusCode());
JSONObject json = parseJsonResponse(response);
JSONArray players = json.getJSONArray("players");
Assertions.assertTrue(players.length() > 0);
for (int i = 0; i < players.length(); i++) {
JSONObject playerJson = players.getJSONObject(i);
Assertions.assertEquals(player.getEmail(), playerJson.getString("email"));
}
}

@Test
@Order(36)
public void testCreatePlayerEmptyApiKey() throws IOException, InterruptedException, JSONException {
Expand Down

0 comments on commit 008d580

Please sign in to comment.