3/4 Commisions test
This commit is contained in:
parent
73104850fe
commit
f9dd6e38c3
@ -25,8 +25,7 @@ public class CommisionService {
|
||||
}
|
||||
|
||||
public List<Commision> getUsersCommisions(User user) {
|
||||
Long id = user.getId();
|
||||
return this.repo.getUsers(id);
|
||||
return this.repo.getUsers(user.getId());
|
||||
}
|
||||
|
||||
public Optional<Commision> getNewestCommision(User user) {
|
||||
|
@ -1,36 +1,79 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
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.result.MockMvcResultMatchers.status;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.services.UserService;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class CommisionControllerTest {
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext webApplicationContext;
|
||||
|
||||
@Autowired
|
||||
private UserService service;
|
||||
|
||||
private static User user;
|
||||
|
||||
private static final String ADD_COMMISION_ENDPOINT = "/api/v1/commisions/add";
|
||||
private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/getAllCommisions";
|
||||
private static final String TEST_COMMISIONS_EMAIL = "commisions@notexisting.domain";
|
||||
|
||||
@Test
|
||||
public void shouldReturn4xxAddingCommision() {
|
||||
assertTrue(false);
|
||||
public void shouldReturn4xxAddingCommision() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnOkAddingCommision() {
|
||||
assertTrue(false);
|
||||
public void shouldReturnOkAddingCommision() throws Exception {
|
||||
this.checkUser();
|
||||
final String token = this.service.login(TEST_COMMISIONS_EMAIL);
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturn4xxGettingAllCommisions() {
|
||||
assertTrue(false);
|
||||
public void shouldReturn4xxGettingAllCommisions() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(GET_COMMISIONS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnOkGettingAllCommisions() {
|
||||
assertTrue(false);
|
||||
public void shouldReturnOkGettingAllCommisions() throws Exception {
|
||||
this.checkUser();
|
||||
final String token = this.service.login(TEST_COMMISIONS_EMAIL);
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(GET_COMMISIONS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
private void checkUser() {
|
||||
if (CommisionControllerTest.user == null) {
|
||||
CommisionControllerTest.user = new User(null, null, TEST_COMMISIONS_EMAIL, UserRoles.TEST_USER);
|
||||
this.service.save(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user