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