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) {
|
public List<Commision> getUsersCommisions(User user) {
|
||||||
Long id = user.getId();
|
return this.repo.getUsers(user.getId());
|
||||||
return this.repo.getUsers(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Commision> getNewestCommision(User user) {
|
public Optional<Commision> getNewestCommision(User user) {
|
||||||
|
@ -1,36 +1,79 @@
|
|||||||
package com.plannaplan.controllers;
|
package com.plannaplan.controllers;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
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)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class CommisionControllerTest {
|
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
|
@Test
|
||||||
public void shouldReturn4xxAddingCommision() {
|
public void shouldReturn4xxAddingCommision() throws Exception {
|
||||||
assertTrue(false);
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnOkAddingCommision() {
|
public void shouldReturnOkAddingCommision() throws Exception {
|
||||||
assertTrue(false);
|
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
|
@Test
|
||||||
public void shouldReturn4xxGettingAllCommisions() {
|
public void shouldReturn4xxGettingAllCommisions() throws Exception {
|
||||||
assertTrue(false);
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(get(GET_COMMISIONS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnOkGettingAllCommisions() {
|
public void shouldReturnOkGettingAllCommisions() throws Exception {
|
||||||
assertTrue(false);
|
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