Skip to content
Snippets Groups Projects
Commit daaebee4 authored by evilimkova's avatar evilimkova
Browse files

Fixing generateCertificate test

parent e7a1978d
No related branches found
No related tags found
1 merge request!36M2 fix certificate
......@@ -37,6 +37,7 @@ public class CourseCertificateDto extends DomainObjectDto {
private ProficiencyLevelDto proficiency;
public CourseCertificateDto(String name, Integer capacity, LanguageTypeDto languageTypeDto, ProficiencyLevelDto proficiencyLevelDto) {
setId(0L);
this.name = name;
this.capacity = capacity;
this.language = languageTypeDto;
......
......@@ -3,10 +3,8 @@ package org.fuseri.model.dto.user;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;
import lombok.*;
import org.fuseri.model.dto.common.DomainObjectDto;
import lombok.Getter;
import lombok.Setter;
import org.fuseri.model.dto.course.LanguageTypeDto;
import org.fuseri.model.dto.course.ProficiencyLevelDto;
......@@ -15,6 +13,7 @@ import java.util.Map;
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
public class UserDto extends DomainObjectDto {
@NotBlank
......@@ -47,4 +46,16 @@ public class UserDto extends DomainObjectDto {
this.address = address;
this.userType = userType;
}
public UserDto(String username, String email, String firstName, String lastName, AddressDto address, UserType userType,Map<LanguageTypeDto, ProficiencyLevelDto> languageProficiency) {
setId(0L);
this.username = username;
this.email = email;
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.userType = userType;
this.languageProficiency = languageProficiency;
}
}
......@@ -24,6 +24,7 @@ import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
......@@ -35,7 +36,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
class CertificateControllerTests {
private final UserDto USER = new UserDto("novakovat",
"novakova@gamil.com", "Tereza", "Nováková", new AddressDto(), UserType.STUDENT);
"novakova@gamil.com", "Tereza", "Nováková",
new AddressDto("USA", "New York", "Main Street", "123", "10001"),
UserType.STUDENT, new HashMap<>());
private final CourseCertificateDto COURSE = new CourseCertificateDto("AJ1", 10,
LanguageTypeDto.ENGLISH, ProficiencyLevelDto.A1);
private final CertificateCreateDto certificateCreateDto = new CertificateCreateDto(USER, COURSE);
......@@ -56,9 +59,26 @@ class CertificateControllerTests {
}
}
@Test
void generateCertificate() throws Exception {
Mockito.when(certificateFacade.generate(ArgumentMatchers.any(CertificateCreateDto.class)))
.thenReturn(certificateDto);
mockMvc.perform(post("/certificates")
.content(asJsonString(certificateCreateDto))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is2xxSuccessful())
.andExpect(jsonPath("$.id").value(certificateDto.getId()))
.andExpect(jsonPath("$.userId").value(certificateDto.getUserId()))
.andExpect(jsonPath("$.generatedAt").value(certificateDto.getGeneratedAt().toString()))
.andExpect(jsonPath("$.courseId").value(certificateDto.getCourseId()))
.andExpect(jsonPath("$.certificateFile").value(certificateDto.getCertificateFile()))
.andExpect(jsonPath("$.certificateFileName").value(certificateDto.getCertificateFileName()));
}
@Test
void generateCertificateWithNullUser() throws Exception {
mockMvc.perform(post("/certificates/generate")
mockMvc.perform(post("/certificates")
.content(asJsonString(new CertificateCreateDto(null, COURSE)))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is5xxServerError());
......@@ -66,7 +86,7 @@ class CertificateControllerTests {
@Test
void generateCertificateWithNullCourse() throws Exception {
mockMvc.perform(post("/certificates/generate")
mockMvc.perform(post("/certificates")
.content(asJsonString(new CertificateCreateDto(USER, null)))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is5xxServerError());
......@@ -74,7 +94,7 @@ class CertificateControllerTests {
@Test
void generateCertificateWithoutParams() throws Exception {
mockMvc.perform(post("/certificates/generate")
mockMvc.perform(post("/certificates")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is5xxServerError());
}
......
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