From 6e6aeaa62bcf44b810ef450927a5f16d03e7ca80 Mon Sep 17 00:00:00 2001
From: evilimkova <evilimkova@onpointserv.com>
Date: Thu, 6 Apr 2023 09:18:50 +0200
Subject: [PATCH] Fixing findForUserAndCourse tests

---
 .../CertificateControllerTests.java           | 22 ++++++++++++++-----
 1 file changed, 16 insertions(+), 6 deletions(-)

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 75a08a33..20a1ec68 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
@@ -9,12 +9,16 @@ import org.fuseri.model.dto.course.ProficiencyLevelDto;
 import org.fuseri.model.dto.user.AddressDto;
 import org.fuseri.model.dto.user.UserDto;
 import org.junit.jupiter.api.Test;
+import org.springdoc.core.converters.models.Pageable;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.data.domain.PageRequest;
 import org.springframework.http.MediaType;
 import org.springframework.test.web.servlet.MockMvc;
 
+import java.util.List;
+
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
 
@@ -101,30 +105,30 @@ class CertificateControllerTests {
 
     @Test
     void findCertificateIdForUserAndCourse() throws Exception {
-        mockMvc.perform(get("/certificates/getId")
+        mockMvc.perform(get("/certificates/findForUserAndCourse")
                         .param("userId", "0")
                         .param("courseId", "0"))
                 .andExpect(status().isOk())
-                .andExpect(content().string("0"));
+                .andExpect(content().string("[]"));
     }
 
     @Test
     void findCertificateIdWithoutUserId() throws Exception {
-        mockMvc.perform(get("/certificates/getId")
+        mockMvc.perform(get("/certificates/findForUserAndCourse")
                         .param("courseId", "0"))
                 .andExpect(status().is4xxClientError());
     }
 
     @Test
     void findCertificateIdWithoutCourseId() throws Exception {
-        mockMvc.perform(get("/certificates/getId")
+        mockMvc.perform(get("/certificates/findForUserAndCourse")
                         .param("userId", "0"))
                 .andExpect(status().is4xxClientError());
     }
 
     @Test
     void findCertificateIdWithoutParams() throws Exception {
-        mockMvc.perform(get("/certificates/getId"))
+        mockMvc.perform(get("/certificates/findForUserAndCourse"))
                 .andExpect(status().is4xxClientError());
     }
 
@@ -144,8 +148,14 @@ class CertificateControllerTests {
 
     @Test
     void findAllCertificates() throws Exception {
+        mockMvc.perform(post("/certificates/generate")
+                        .content(asJsonString(new CertificateCreateDto(USER, COURSE)))
+                        .contentType(MediaType.APPLICATION_JSON))
+                .andExpect(status().isOk());
+
         mockMvc.perform(get("/certificates/findAll")
-                        .param("page", "1"))
+                .content("{ \"page\": 0, \"size\": 1, \"sort\": []}")
+                .contentType(MediaType.APPLICATION_JSON))
                 .andExpect(status().isOk());
     }
 
-- 
GitLab