diff --git a/application/model/src/main/java/org/fuseri/model/dto/course/CourseCertificateDto.java b/application/model/src/main/java/org/fuseri/model/dto/course/CourseCertificateDto.java index d32664564ebbf2387f4c8e0f4c0ac7413728ccfc..8a7e5982f48e0b9edbd0e513eec26dafaca26c77 100644 --- a/application/model/src/main/java/org/fuseri/model/dto/course/CourseCertificateDto.java +++ b/application/model/src/main/java/org/fuseri/model/dto/course/CourseCertificateDto.java @@ -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; diff --git a/application/model/src/main/java/org/fuseri/model/dto/user/UserDto.java b/application/model/src/main/java/org/fuseri/model/dto/user/UserDto.java index 0e3ebf029e28af0b99d1d9c47fadfc2bf776c780..fa78c2648fcae1460c0c998b69f0093af72ef6f6 100644 --- a/application/model/src/main/java/org/fuseri/model/dto/user/UserDto.java +++ b/application/model/src/main/java/org/fuseri/model/dto/user/UserDto.java @@ -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; + } } diff --git a/application/module-certificate/src/test/java/org/fuseri/modulecertificate/CertificateControllerTests.java b/application/module-certificate/src/test/java/org/fuseri/modulecertificate/CertificateControllerTests.java index 6733239b1a5efb5b5f2baae737685e50374724a0..e9a10decaa74c2fb326121092ed69a03a8e89f7f 100644 --- a/application/module-certificate/src/test/java/org/fuseri/modulecertificate/CertificateControllerTests.java +++ b/application/module-certificate/src/test/java/org/fuseri/modulecertificate/CertificateControllerTests.java @@ -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()); }