Skip to content
Snippets Groups Projects
Commit 6a69715a authored by Jan Pokorný's avatar Jan Pokorný :lifter_tone2:
Browse files

Course fixes

parent 8f178eb6
No related branches found
No related tags found
1 merge request!35M2 fix language school
...@@ -9,7 +9,6 @@ import org.fuseri.model.dto.course.CourseCreateDto; ...@@ -9,7 +9,6 @@ import org.fuseri.model.dto.course.CourseCreateDto;
import org.fuseri.model.dto.course.CourseDto; import org.fuseri.model.dto.course.CourseDto;
import org.fuseri.model.dto.course.LanguageTypeDto; import org.fuseri.model.dto.course.LanguageTypeDto;
import org.fuseri.model.dto.course.ProficiencyLevelDto; import org.fuseri.model.dto.course.ProficiencyLevelDto;
import org.fuseri.model.dto.user.UserDto;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
...@@ -103,6 +102,7 @@ public class CourseController { ...@@ -103,6 +102,7 @@ public class CourseController {
List<CourseDto> courseDtos = courseFacade.findAll(lang); List<CourseDto> courseDtos = courseFacade.findAll(lang);
return ResponseEntity.ok(courseDtos); return ResponseEntity.ok(courseDtos);
} }
/** /**
* Retrieves a paginated list of courses of a given language and proficiency * Retrieves a paginated list of courses of a given language and proficiency
* *
...@@ -117,7 +117,7 @@ public class CourseController { ...@@ -117,7 +117,7 @@ public class CourseController {
@ApiResponse(code = 400, message = "Invalid request body") @ApiResponse(code = 400, message = "Invalid request body")
}) })
public ResponseEntity<List<CourseDto>> findAll(@RequestParam LanguageTypeDto lang, public ResponseEntity<List<CourseDto>> findAll(@RequestParam LanguageTypeDto lang,
@RequestParam ProficiencyLevelDto prof) { @RequestParam ProficiencyLevelDto prof) {
List<CourseDto> courses = courseFacade.findAll(lang, prof); List<CourseDto> courses = courseFacade.findAll(lang, prof);
return ResponseEntity.ok(courses); return ResponseEntity.ok(courses);
} }
...@@ -188,8 +188,8 @@ public class CourseController { ...@@ -188,8 +188,8 @@ public class CourseController {
@ApiResponse(code = 200, message = "Successfully expelled student from course"), @ApiResponse(code = 200, message = "Successfully expelled student from course"),
@ApiResponse(code = 404, message = "Course not found") @ApiResponse(code = 404, message = "Course not found")
}) })
public ResponseEntity<CourseDto> expel(@PathVariable Long id, @RequestBody UserDto student) { public ResponseEntity<CourseDto> expel(@PathVariable Long id, @RequestParam Long studentId) {
CourseDto updatedCourse = courseFacade.expel(id, student); CourseDto updatedCourse = courseFacade.expel(id, studentId);
return ResponseEntity.ok(updatedCourse); return ResponseEntity.ok(updatedCourse);
} }
......
...@@ -4,7 +4,6 @@ import org.fuseri.model.dto.course.CourseCreateDto; ...@@ -4,7 +4,6 @@ import org.fuseri.model.dto.course.CourseCreateDto;
import org.fuseri.model.dto.course.CourseDto; import org.fuseri.model.dto.course.CourseDto;
import org.fuseri.model.dto.course.LanguageTypeDto; import org.fuseri.model.dto.course.LanguageTypeDto;
import org.fuseri.model.dto.course.ProficiencyLevelDto; import org.fuseri.model.dto.course.ProficiencyLevelDto;
import org.fuseri.model.dto.user.UserDto;
import org.fuseri.modulelanguageschool.user.UserMapper; import org.fuseri.modulelanguageschool.user.UserMapper;
import org.fuseri.modulelanguageschool.user.UserService; import org.fuseri.modulelanguageschool.user.UserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -71,7 +70,8 @@ public class CourseFacade { ...@@ -71,7 +70,8 @@ public class CourseFacade {
return courseMapper.mapToDto(courseService.enrol(id, student)); return courseMapper.mapToDto(courseService.enrol(id, student));
} }
public CourseDto expel(Long id, UserDto student) { public CourseDto expel(Long id, Long studentId) {
return courseMapper.mapToDto(courseService.expel(id, userMapper.fromDto(student))); var student = userService.find(studentId);
return courseMapper.mapToDto(courseService.expel(id, student));
} }
} }
...@@ -21,8 +21,6 @@ import org.springframework.http.MediaType; ...@@ -21,8 +21,6 @@ import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
...@@ -116,7 +114,7 @@ public class CourseControllerTest { ...@@ -116,7 +114,7 @@ public class CourseControllerTest {
@Test @Test
void findAllWithoutPage() throws Exception { void findAllWithoutPage() throws Exception {
mockMvc.perform(get("/courses/findAll")) mockMvc.perform(get("/courses/findAll"))
.andExpect(status().is4xxClientError()); .andExpect(status().is5xxServerError());
} }
...@@ -130,12 +128,13 @@ public class CourseControllerTest { ...@@ -130,12 +128,13 @@ public class CourseControllerTest {
.param("lang", lang.toString())) .param("lang", lang.toString()))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andReturn().getResponse().getContentAsString(); .andReturn().getResponse().getContentAsString();
assertTrue(response.endsWith("[]")); } assertTrue(response.endsWith("[]"));
}
@Test @Test
void findAllByLangWithoutLang() throws Exception { void findAllByLangWithoutLang() throws Exception {
mockMvc.perform(get("/courses/findAllByLang")) mockMvc.perform(get("/courses/findAllByLang"))
.andExpect(status().is4xxClientError()); .andExpect(status().is5xxServerError());
} }
@Test @Test
...@@ -154,14 +153,14 @@ public class CourseControllerTest { ...@@ -154,14 +153,14 @@ public class CourseControllerTest {
@Test @Test
void findAllByLangProfWithoutParameters() throws Exception { void findAllByLangProfWithoutParameters() throws Exception {
mockMvc.perform(get("/courses/findAllByLangProf")) mockMvc.perform(get("/courses/findAllByLangProf"))
.andExpect(status().is4xxClientError()); .andExpect(status().is5xxServerError());
} }
@Test @Test
void findAllByLangProfWithoutLangProf() throws Exception { void findAllByLangProfWithoutLangProf() throws Exception {
String page = "0"; String page = "0";
mockMvc.perform(get("/courses/findAllByLangProf").param("page", page)) mockMvc.perform(get("/courses/findAllByLangProf").param("page", page))
.andExpect(status().is4xxClientError()); .andExpect(status().is5xxServerError());
} }
@Test @Test
...@@ -229,7 +228,7 @@ public class CourseControllerTest { ...@@ -229,7 +228,7 @@ public class CourseControllerTest {
@Test @Test
void enrolCourseWithoutUserParameter() throws Exception { void enrolCourseWithoutUserParameter() throws Exception {
mockMvc.perform(patch("/courses/enrol/" + 0L)) mockMvc.perform(patch("/courses/enrol/" + 0L))
.andExpect(status().is4xxClientError()); .andExpect(status().is5xxServerError());
} }
@Test @Test
...@@ -247,14 +246,14 @@ public class CourseControllerTest { ...@@ -247,14 +246,14 @@ public class CourseControllerTest {
void expelCourse() throws Exception { void expelCourse() throws Exception {
Long id = 0L; Long id = 0L;
Mockito.when(courseFacade.expel(ArgumentMatchers.eq(id), Mockito.when(courseFacade.expel(ArgumentMatchers.eq(id),
ArgumentMatchers.isA(UserDto.class))) ArgumentMatchers.isA(Long.class)))
.thenReturn(courseDto); .thenReturn(courseDto);
UserDto student = new UserDto("novakovat", "novakova@gamil.com", "Tereza", UserDto student = new UserDto("novakovat", "novakova@gamil.com", "Tereza",
"Nováková", new AddressDto(), UserType.STUDENT); "Nováková", new AddressDto(), UserType.STUDENT);
student.setId(0L);
mockMvc.perform(patch("/courses/expel/" + id) mockMvc.perform(patch("/courses/expel/" + id + "?studentId=" + student.getId())
.content(asJsonString(student))
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.name").value("english b2 course")) .andExpect(jsonPath("$.name").value("english b2 course"))
...@@ -267,7 +266,7 @@ public class CourseControllerTest { ...@@ -267,7 +266,7 @@ public class CourseControllerTest {
@Test @Test
void expelCourseWithoutUserParameter() throws Exception { void expelCourseWithoutUserParameter() throws Exception {
mockMvc.perform(patch("/courses/expel/" + 0L)) mockMvc.perform(patch("/courses/expel/" + 0L))
.andExpect(status().is4xxClientError()); .andExpect(status().is5xxServerError());
} }
@Test @Test
......
...@@ -9,7 +9,7 @@ import org.fuseri.model.dto.user.AddressDto; ...@@ -9,7 +9,7 @@ import org.fuseri.model.dto.user.AddressDto;
import org.fuseri.model.dto.user.UserDto; import org.fuseri.model.dto.user.UserDto;
import org.fuseri.model.dto.user.UserType; import org.fuseri.model.dto.user.UserType;
import org.fuseri.modulelanguageschool.user.User; import org.fuseri.modulelanguageschool.user.User;
import org.fuseri.modulelanguageschool.user.UserMapper; import org.fuseri.modulelanguageschool.user.UserService;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
...@@ -58,7 +58,7 @@ final class CourseFacadeTest { ...@@ -58,7 +58,7 @@ final class CourseFacadeTest {
private CourseMapper courseMapper; private CourseMapper courseMapper;
@MockBean @MockBean
private UserMapper userMapper; private UserService userService;
@Test @Test
void create() { void create() {
...@@ -142,15 +142,14 @@ final class CourseFacadeTest { ...@@ -142,15 +142,14 @@ final class CourseFacadeTest {
void testExpel() { void testExpel() {
Long id = 0L; Long id = 0L;
when(courseMapper.mapToDto(course)).thenReturn(courseDto); when(courseMapper.mapToDto(course)).thenReturn(courseDto);
when(userMapper.fromDto(USER)).thenReturn(user); when(userService.find(0L)).thenReturn(user);
when(courseService.expel(anyLong(), any(User.class))).thenReturn(course); when(courseService.expel(anyLong(), any(User.class))).thenReturn(course);
CourseDto actualDto = courseFacade.expel(id, USER); CourseDto actualDto = courseFacade.expel(id, 0L);
assertNotNull(actualDto); assertNotNull(actualDto);
assertEquals(courseDto, actualDto); assertEquals(courseDto, actualDto);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment