Checkpoint: ownedGroups.contains(groupId) and tests

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2021-01-10 10:57:33 +01:00
parent e24938dfce
commit c7feb10997
Signed by: y0rune
GPG Key ID: F204C385F57EB348
2 changed files with 72 additions and 6 deletions

View File

@ -3,6 +3,8 @@ package com.plannaplan.controllers;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import com.plannaplan.App; import com.plannaplan.App;
import com.plannaplan.entities.Assignment; import com.plannaplan.entities.Assignment;
@ -37,12 +39,6 @@ import io.swagger.annotations.ApiOperation;
@Api(tags = { "Exchange" }, value = "Exchange", description = "Endpoint to exchange with accepted assignments.") @Api(tags = { "Exchange" }, value = "Exchange", description = "Endpoint to exchange with accepted assignments.")
public class ExchangeController extends TokenBasedController{ public class ExchangeController extends TokenBasedController{
/*
* Endpoint do wylistowania exchangow użytkownika
* Endpoint do usuwania exchanga
*/
@Autowired @Autowired
private GroupService groupService; private GroupService groupService;
@ -61,6 +57,11 @@ public class ExchangeController extends TokenBasedController{
.orElseThrow(() -> new UserNotFoundException("Invalid token")); .orElseThrow(() -> new UserNotFoundException("Invalid token"));
final Long assignmentId = exchangeRequest.get("assignment"); final Long assignmentId = exchangeRequest.get("assignment");
final Long groupId = exchangeRequest.get("group"); final Long groupId = exchangeRequest.get("group");
final List<Long> ownedGroups = asker.getStudentRegisteredGrups().stream().map(Groups::getId).collect(Collectors.toList());
if(ownedGroups.contains(groupId)){
return new ResponseEntity<>("User has already got this group.", HttpStatus.BAD_REQUEST);
}
if(assignmentId == null || groupId == null ){ if(assignmentId == null || groupId == null ){
return new ResponseEntity<>("Some of values are missing", HttpStatus.BAD_REQUEST); return new ResponseEntity<>("Some of values are missing", HttpStatus.BAD_REQUEST);

View File

@ -0,0 +1,65 @@
package com.plannaplan.controllers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import static org.junit.Assert.assertTrue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import javax.validation.constraints.AssertTrue;
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration
public class ExchangeControllerTest extends AbstractControllerTest{
@Test
public void shouldGetAllUsersExchanges(){
assertTrue(false);
}
@Test
public void shouldFailGettingExchange(){
assertTrue(false);
}
@Test
public void shouldFailPostDueToExchangeNoFound(){
assertTrue(false);
}
@Test
public void shouldInsertExchange(){
assertTrue(false);
}
@Test
public void shouldDenyExchangeDueToAssigmentOverlapping(){
assertTrue(false);
}
@Test
public void shouldDenyPostDueToAssignmentNotAccepted(){
assertTrue(false);
}
@Test
public void shouldFailDeleteDueToWrongPermissions(){
assertTrue(false);
}
@Test
public void shouldFailDeleteDueToExchangeNoFound(){
assertTrue(false);
}
@Test
public void shouldFailPostDueToGroupAlreadyAccepted(){
assertTrue(false);
}
}