Skip to content

Commit

Permalink
Decouple teams from tickets (#339)
Browse files Browse the repository at this point in the history
* Tickets are no longer needed to do Team actions.

* Change tests.
  • Loading branch information
MatthijsKok authored and Sille Kamoen committed Jan 8, 2017
1 parent 28bbabb commit 0823cfb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public TeamRestController(TeamService teamService, SeatService seatService) {
*
* @return Return status message of the operation
*/
@PreAuthorize("isAuthenticated() and @currentUserServiceImpl.hasAnyTicket(principal)")
@PreAuthorize("isAuthenticated()")
@JsonView(View.Public.class)
@RequestMapping(method = RequestMethod.POST)
ResponseEntity<?> add(@Validated @RequestBody TeamDTO teamDTO, Authentication auth) {
Expand Down Expand Up @@ -193,8 +193,7 @@ public ResponseEntity<?> addTeamMember(@PathVariable Long teamId, @RequestBody S
*
* @return Result message of the request
*/
@PreAuthorize("@currentUserServiceImpl.canEditTeam(principal, #teamId) " +
"and @currentUserServiceImpl.hasAnyTicket(#username)")
@PreAuthorize("@currentUserServiceImpl.canEditTeam(principal, #teamId) ")
@RequestMapping(method = RequestMethod.POST, value = "/{teamId}/invites")
public ResponseEntity<?> inviteTeamMember(@PathVariable Long teamId, @RequestBody String username) {
teamService.inviteMember(teamId, username);
Expand Down
30 changes: 20 additions & 10 deletions src/test/java/ch/wisv/areafiftylan/TeamRestIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,29 @@ public void testCreateTeamAsCaptainDifferentCase() {
}

@Test
public void testCreateTeamMissingTicket() {
public void testCreateTeamWithoutTicket() {
User captain = createUser();

Map<String, String> teamDTO = getTeamDTO(captain);

//@formatter:off
given().
header(getXAuthTokenHeaderForUser(captain)).
when().
body(teamDTO).contentType(ContentType.JSON).
post(TEAM_ENDPOINT).
then().
statusCode(HttpStatus.SC_FORBIDDEN);
Integer teamId =
given().
header(getXAuthTokenHeaderForUser(captain)).
when().
body(teamDTO).
contentType(ContentType.JSON).
post(TEAM_ENDPOINT).
then().
statusCode(HttpStatus.SC_CREATED).
header("Location", containsString("/teams/")).
body("object.teamName", equalTo(teamDTO.get("teamName"))).
body("object.captain.profile.displayName", equalTo(captain.getProfile().getDisplayName())).
body("object.members", hasSize(1)).
extract().response().path("object.id");
//@formatter:on

Team team = teamRepository.getOne(new Long(teamId));
Assert.assertNotNull(team);
}

@Test
Expand Down Expand Up @@ -572,7 +581,8 @@ public void testInviteMemberWithoutTicket() {
body(member.getUsername()).
post(TEAM_ENDPOINT + team.getId() + "/invites").
then().
statusCode(HttpStatus.SC_FORBIDDEN);
statusCode(HttpStatus.SC_OK).
body("message", equalTo("User " + member.getUsername() + " successfully invited to Team " + team.getId()));
//@formatter:on
}

Expand Down

0 comments on commit 0823cfb

Please sign in to comment.