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 d39e4d2 commit 95c5c45
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions src/test/java/com/uniovi/Wiq_UnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,22 @@ public void testGetQuestions() throws IOException, InterruptedException, JSONExc
Assertions.assertTrue(json.getJSONArray("questions").length() > 0);
}

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

HttpResponse<String> response = sendRequest("GET", "/api/questions", Map.of("id", "notnumeric"),
Map.of("apiKey", apiKey.getKeyToken()));

Assertions.assertEquals(200, response.statusCode());
JSONObject json = parseJsonResponse(response);
Assertions.assertTrue(json.has("questions"));
Assertions.assertTrue(json.getJSONArray("questions").length() > 0);
}

@Test
@Order(51)
public void testGetQuestionsByCategoryName() throws IOException, InterruptedException, JSONException {
Expand Down Expand Up @@ -1364,9 +1380,8 @@ public void testModifyQuestionMissingData() throws IOException, InterruptedExcep

@Test
@Order(91)
@Tag("flaky")
public void testModifyQuestion() throws IOException, InterruptedException, JSONException {
insertSomeQuestions();;
insertSomeQuestions();
Question question = questionService.getAllQuestions().get(0);
Player player = playerService.getUsersByRole("ROLE_USER").get(0);
ApiKey apiKey = player.getApiKey();
Expand Down Expand Up @@ -1397,6 +1412,40 @@ public void testModifyQuestion() throws IOException, InterruptedException, JSONE
Assertions.assertEquals("Modified question", updatedQuestion.get().getStatement());
}

@Test
@Order(91)
public void testModifyQuestionNewCategory() throws IOException, InterruptedException, JSONException {
insertSomeQuestions();;
Question question = questionService.getAllQuestions().get(0);
Player player = playerService.getUsersByRole("ROLE_USER").get(0);
ApiKey apiKey = player.getApiKey();
Category category = categoryService.getCategoryByName("Geography");

Map<String, Object> data = new HashMap<>();
data.put("statement", "Modified question");

List<Map<String, Object>> opts = new ArrayList<>();
opts.add(Map.of("text", "Option A", "correct", true));
opts.add(Map.of("text", "Option B", "correct", false));
opts.add(Map.of("text", "Option C", "correct", false));
opts.add(Map.of("text", "Option D", "correct", false));

data.put("options", opts);
data.put("category", Map.of("name", "NewCreatedCategory"));
data.put("language", "en");

HttpResponse<String> response = sendRequest("PATCH", "/api/questions/" + question.getId(), Map.of("API-KEY", apiKey.getKeyToken()),
data);

Assertions.assertEquals(200, response.statusCode());
JSONObject json = parseJsonResponse(response);
Assertions.assertTrue(json.getBoolean("success"));

Optional<Question> updatedQuestion = questionService.getQuestion(question.getId());
Assertions.assertTrue(updatedQuestion.isPresent());
Assertions.assertEquals("Modified question", updatedQuestion.get().getStatement());
}

@Test
@Order(92)
public void testModifyQuestionWithLessOptions() throws IOException, InterruptedException, JSONException {
Expand Down

0 comments on commit 95c5c45

Please sign in to comment.