mainDev #6
@ -15,7 +15,7 @@ public class Team {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Integer id;
|
||||
private Integer teamId;
|
||||
private String name;
|
||||
private Integer score = 0;
|
||||
@Setter
|
||||
@ -37,7 +37,7 @@ public class Team {
|
||||
|
||||
public Team(Team team) {
|
||||
this.name = team.name;
|
||||
this.id = team.id;
|
||||
this.teamId = team.teamId;
|
||||
this.score = -1;
|
||||
this.imageUrl = team.imageUrl;
|
||||
this.userEmails = team.userEmails;
|
||||
|
||||
@ -51,7 +51,7 @@ public class TeamController {
|
||||
// Changes a Teams avatar.
|
||||
@PutMapping(path = "/change-avatar")
|
||||
public ResponseEntity<?> changeTeamAvatar(@RequestBody Team team) {
|
||||
if (teamService.updateAvatarSuccess(team.getId(), team.getImageUrl())) {
|
||||
if (teamService.updateAvatarSuccess(team.getTeamId(), team.getImageUrl())) {
|
||||
return ResponseEntity.ok("Avatar updated");
|
||||
} else {
|
||||
throw new NoSuchElementException("Avatar update failed: team not found or invalid");
|
||||
|
||||
@ -56,7 +56,7 @@ public class TeamService {
|
||||
public int idByName(String name) {
|
||||
for (Team team : teamRepository.findAll()) {
|
||||
if (team.getName().equals(name)) {
|
||||
return team.getId();
|
||||
return team.getTeamId();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@ -62,7 +62,7 @@ public class TeamControllerTests {
|
||||
Team team = allTeams.get(0);
|
||||
|
||||
// Should return team
|
||||
mockMvc.perform(get("/get-team/" + team.getId()))
|
||||
mockMvc.perform(get("/get-team/" + team.getTeamId()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.name").value(team.getName()));
|
||||
|
||||
@ -75,13 +75,13 @@ public class TeamControllerTests {
|
||||
@Test
|
||||
public void getTeamMembers() throws Exception {
|
||||
Team team = allTeams.get(0);
|
||||
|
||||
|
||||
// Should return members of existing team
|
||||
mockMvc.perform(get("/team-members/" + team.getId()))
|
||||
mockMvc.perform(get("/team-members/" + team.getTeamId()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType("application/json"))
|
||||
.andExpect(jsonPath("$").isArray());
|
||||
|
||||
|
||||
// Should return not found for non-existing team ID
|
||||
mockMvc.perform(get("/team-members/" + fakeId))
|
||||
.andExpect(status().isNotFound())
|
||||
@ -94,10 +94,10 @@ public class TeamControllerTests {
|
||||
String validTeamJson = """
|
||||
{
|
||||
"name": "NewTestTeam",
|
||||
"imageUrl": "http://example.com/image.png"
|
||||
"imageUrl": "http:example.com/image.png"
|
||||
}
|
||||
""";
|
||||
|
||||
|
||||
mockMvc.perform(post("/create-team")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(validTeamJson))
|
||||
@ -108,10 +108,10 @@ public class TeamControllerTests {
|
||||
String emptyNameJson = """
|
||||
{
|
||||
"name": " ",
|
||||
"imageUrl": "http://example.com/image.png"
|
||||
"imageUrl": "http:example.com/image.png"
|
||||
}
|
||||
""";
|
||||
|
||||
|
||||
mockMvc.perform(post("/create-team")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(emptyNameJson))
|
||||
@ -134,17 +134,16 @@ public class TeamControllerTests {
|
||||
assertEquals(before, after);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Test
|
||||
public void changeTeamScore() throws Exception {
|
||||
Team team = allTeams.get(0);
|
||||
int originalScore = team.getScore();
|
||||
// should update score
|
||||
mockMvc.perform(put("/change/" + team.getId() + "/10"))
|
||||
mockMvc.perform(put("/change/" + team.getTeamId() + "/10"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string("Score updated"));
|
||||
|
||||
Team updatedTeam = teamRepository.findById(team.getId()).orElseThrow();
|
||||
Team updatedTeam = teamRepository.findById(team.getTeamId()).orElseThrow();
|
||||
assertEquals(originalScore + 10, updatedTeam.getScore());
|
||||
|
||||
// should return not found, as id does not exist in repository
|
||||
@ -153,7 +152,7 @@ public class TeamControllerTests {
|
||||
.andExpect(content().string(containsString("Team ID not found")));
|
||||
|
||||
// checks that the point is an int
|
||||
mockMvc.perform(put("/change/" + team.getId() + "/5.5"))
|
||||
mockMvc.perform(put("/change/" + team.getTeamId() + "/5.5"))
|
||||
.andExpect(status().isBadRequest());
|
||||
}
|
||||
|
||||
@ -167,7 +166,7 @@ public class TeamControllerTests {
|
||||
"email": "testuser@example.com",
|
||||
"teamId": %d
|
||||
}
|
||||
""".formatted(team.getId());
|
||||
""".formatted(team.getTeamId());
|
||||
|
||||
mockMvc.perform(post("/add-user-to-team")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
@ -185,15 +184,15 @@ public class TeamControllerTests {
|
||||
mockMvc.perform(post("/add-user-to-team")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(json))
|
||||
.andExpect(status().isBadRequest());
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
// checks for missing team tid
|
||||
json = """
|
||||
{
|
||||
"email": "testuser@example.com"
|
||||
}
|
||||
""";
|
||||
|
||||
""";
|
||||
|
||||
mockMvc.perform(post("/add-user-to-team")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(json))
|
||||
@ -209,7 +208,7 @@ public class TeamControllerTests {
|
||||
teamRepository.save(team);
|
||||
|
||||
// should remove a user from team
|
||||
mockMvc.perform(delete("/remove-user-from-team/testuser@example.com/" + team.getId()))
|
||||
mockMvc.perform(delete("/remove-user-from-team/testuser@example.com/" + team.getTeamId()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string("User removed from team"));
|
||||
// should return not found error
|
||||
@ -217,14 +216,14 @@ public class TeamControllerTests {
|
||||
.andExpect(status().isNotFound())
|
||||
.andExpect(content().string(containsString("No value present")));
|
||||
long after = teamRepository.count();
|
||||
|
||||
|
||||
assertEquals(before, after);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void removeTeam() throws Exception {
|
||||
Team team = allTeams.get(0);
|
||||
int id = team.getId();
|
||||
int id = team.getTeamId();
|
||||
String name = team.getName();
|
||||
|
||||
// should delete
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user