Assignments Controller test + authj test fix

This commit is contained in:
Filip Izydorczyk 2020-10-05 16:52:52 +02:00
parent fe5d2d20c3
commit 73104850fe
3 changed files with 33 additions and 9 deletions

View File

@ -30,7 +30,7 @@ public class CommisionService {
}
public Optional<Commision> getNewestCommision(User user) {
return Optional.of(this.repo.getNewestCommision(user.getId()).get(0));
return this.repo.getNewestCommision(user.getId()).stream().findFirst();
}
public long getCommisionsAmmount() {

View File

@ -1,27 +1,51 @@
package com.plannaplan.controllers;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.plannaplan.entities.User;
import com.plannaplan.services.UserService;
import com.plannaplan.types.UserRoles;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
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 org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration
public class AssignmentsControllerTest {
private static final String ASSIGFNMENTS_ENDPOINT = "/api/v1/assignments/getCurrentAssignments";
private static final String TEST_MAIL = "notexistingassignmentuser@mail.domain";
@Autowired
private WebApplicationContext webApplicationContext;
@Autowired
private UserService service;
@Test
public void shouldReturn4xx() {
assertTrue(false);
public void shouldReturn4xx() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(ASSIGFNMENTS_ENDPOINT)).andExpect(status().is4xxClientError());
}
@Test
public void shouldReturnOk() {
assertTrue(false);
public void shouldReturnOk() throws Exception {
this.service.save(new User(null, null, TEST_MAIL, UserRoles.TEST_USER));
final String token = this.service.login(TEST_MAIL);
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(ASSIGFNMENTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().isOk());
}
}

View File

@ -67,8 +67,8 @@ public class ConfigControllerTest {
final String token = this.service.login(TEST_MAIL);
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).header("Bearer ", token))
.andExpect(status().is4xxClientError());
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).header("Authorization", "Bearer " + token))
.andExpect(status().isOk());
}