TD-34: fixed bugs in tests
Some checks failed
Quality Check / Linting (push) Failing after 1m6s
Quality Check / Validate OAS (push) Successful in 3m35s
Quality Check / Testing (push) Successful in 4m5s
Quality Check / Static Analysis (push) Successful in 4m40s
Quality Check / Validate OAS (pull_request) Successful in 31s
Quality Check / Linting (pull_request) Failing after 49s
Quality Check / Testing (pull_request) Successful in 56s
Quality Check / Static Analysis (pull_request) Successful in 58s

This commit is contained in:
mehdiboudjoudi 2025-02-26 09:38:35 +01:00
parent 5523287cc9
commit 06121ddb93
4 changed files with 40 additions and 9 deletions

View file

@ -54,6 +54,7 @@ public class AdminApiController implements AdminApi {
@Override
public ResponseEntity<List<PlayerApiModel>> getAllPlayers(Integer page, Integer pageSize, String sortBy, String order, String username) {
Sort.Direction direction = order.equalsIgnoreCase("asc") ? Sort.Direction.ASC : Sort.Direction.DESC;
Pageable pageable = PageRequest.of(page, pageSize, Sort.by(direction, sortBy));

View file

@ -15,6 +15,7 @@ public class PlayerMapperService {
for (Player player : players) {
PlayerApiModel apiPlayer = new PlayerApiModel();
apiPlayer.setUsername(player.getUsername());
apiPlayers.add(apiPlayer);
}
return apiPlayers;
}

View file

@ -35,13 +35,21 @@ public abstract class IntegrationTest {
playerRepository.deleteAll();
Player player1 = new Player();
player1.setUsername("Player1");
player1.setUsername("Alex");
try {
playerService.setPassword(player1, "1234");
} catch (NoSuchAlgorithmException e) {return;}
this.playerRepository.save(player1);
Player player2 = new Player();
player2.setUsername("Zorro");
try {
playerService.setPassword(player2, "1234");
} catch (NoSuchAlgorithmException e) {return;}
this.playerRepository.save(player2);
System.out.println("LISTE: " + playerRepository.findAll());
}

View file

@ -11,7 +11,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
class GetAllPlayersPaginatedAndSortedTest extends IntegrationTest {
@Test
void testGetAllPlayersPaginatedAndSorted() throws Exception {
void playersExist() throws Exception {
//Testing if list ist being returned successfully
this.mvc.perform(MockMvcRequestBuilders.get(baseUri + "/admin/players")
.param("page", "0")
.param("pageSize", "10")
@ -21,7 +22,11 @@ class GetAllPlayersPaginatedAndSortedTest extends IntegrationTest {
.andExpect(status().isOk())
.andExpect(jsonPath("$").isArray())
.andExpect(jsonPath("$[0]").exists());
}
@Test
void playersSortedByAsc() throws Exception {
//Test list ist being sorted correctly
this.mvc.perform(MockMvcRequestBuilders.get(baseUri + "/admin/players")
.param("page", "0")
.param("pageSize", "10")
@ -29,21 +34,37 @@ class GetAllPlayersPaginatedAndSortedTest extends IntegrationTest {
.param("order", "asc")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].name").value("A"))
.andExpect(jsonPath("$[9].name").value("Z"));
.andExpect(jsonPath("$[0].username").value("Alex"))
.andExpect(jsonPath("$[1].username").value("Zorro"));
/*
testing if specific username that is being filtered by is in the result list
}
@Test
void playersSortedByDesc() throws Exception {
//Test list ist being sorted correctly
this.mvc.perform(MockMvcRequestBuilders.get(baseUri + "/admin/players")
.param("page", "0")
.param("pageSize", "10")
.param("username", "John")
.param("sortBy", "username")
.param("order", "desc")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$[1].username").value("Alex"))
.andExpect(jsonPath("$[0].username").value("Zorro"));
}
@Test
void playersFiltered() throws Exception {
//testing if specific username that is being filtered by is in the result list
this.mvc.perform(MockMvcRequestBuilders.get(baseUri + "/admin/players")
.param("page", "0")
.param("pageSize", "10")
.param("username", "Alex")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$").isArray())
.andExpect(jsonPath("$[0].name").value("John"))
.andExpect(jsonPath("$[0].username").value("Alex"))
.andExpect(jsonPath("$").isNotEmpty());
*/
}
}