Compare commits

..

1 commit

Author SHA1 Message Date
440160980d TD-34: Solved comments made by reviewer
Some checks failed
Quality Check / Validate OAS (push) Successful in 35s
Quality Check / Validate OAS (pull_request) Successful in 35s
Quality Check / Testing (push) Successful in 1m15s
Quality Check / Static Analysis (push) Successful in 1m25s
Quality Check / Linting (push) Failing after 1m51s
Quality Check / Linting (pull_request) Failing after 1m16s
Quality Check / Static Analysis (pull_request) Successful in 1m19s
Quality Check / Testing (pull_request) Successful in 51s
2025-02-26 12:32:04 +01:00
2 changed files with 84 additions and 1 deletions

View file

@ -0,0 +1,83 @@
package de.towerdefence.server.server;
import de.towerdefence.server.IntegrationTest;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
class GetAllPlayersPaginatedAndSortedTest extends IntegrationTest {
private MockHttpServletRequestBuilder createGetAllPlayersRequest(String requestBody) {
return MockMvcRequestBuilders.get(baseUri + "/admin/players")
.contentType(MediaType.APPLICATION_JSON)
.content(requestBody);
}
@Test
void playersExist() throws Exception {
String requestBody = "{" +
"\"page\": 0," +
"\"pageSize\": 10," +
"\"sortBy\": \"username\"," +
"\"order\": \"descending\"," +
"\"username\": \"\"" +
"}";
this.mvc.perform(createGetAllPlayersRequest(requestBody))
.andExpect(status().isOk())
.andExpect(jsonPath("$").isArray())
.andExpect(jsonPath("$[0]").exists());
}
@Test
void playersSortedByAsc() throws Exception {
String requestBody = "{" +
"\"page\": 0," +
"\"pageSize\": 10," +
"\"sortBy\": \"username\"," +
"\"order\": \"ascending\"," +
"\"username\": \"\"" +
"}";
this.mvc.perform(createGetAllPlayersRequest(requestBody))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].username").value("Alex"))
.andExpect(jsonPath("$[1].username").value("Zorro"));
}
@Test
void playersSortedByDesc() throws Exception {
String requestBody = "{" +
"\"page\": 0," +
"\"pageSize\": 10," +
"\"sortBy\": \"username\"," +
"\"order\": \"descending\"," +
"\"username\": \"\"" +
"}";
this.mvc.perform(createGetAllPlayersRequest(requestBody))
.andExpect(status().isOk())
.andExpect(jsonPath("$[1].username").value("Alex"))
.andExpect(jsonPath("$[0].username").value("Zorro"));
}
@Test
void playersFiltered() throws Exception {
String requestBody = "{" +
"\"page\": 0," +
"\"pageSize\": 10," +
"\"username\": \"Alex\","+
"\"order\": \"ascending\""+
"}";
this.mvc.perform(createGetAllPlayersRequest(requestBody))
.andExpect(status().isOk())
.andExpect(jsonPath("$").isArray())
.andExpect(jsonPath("$[0].username").value("Alex"))
.andExpect(jsonPath("$").isNotEmpty());
}
}

View file

@ -80,4 +80,4 @@ class GetAllPlayersTest extends IntegrationTest {
.andExpect(jsonPath("$[0].username").value("Alex"))
.andExpect(jsonPath("$").isNotEmpty());
}
}
}