few small fixes

This commit is contained in:
2025-06-13 17:51:35 +02:00
parent d9a8ffe4bd
commit 86e902bbfe
4 changed files with 11 additions and 92 deletions

View File

@@ -1,76 +0,0 @@
package _11.asktpk.artisanconnectbackend;
import _11.asktpk.artisanconnectbackend.security.JwtUtil;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
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.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
@SpringBootTest
@AutoConfigureMockMvc
class EmailControllerIntegrationTest {
@Autowired
private MockMvc mockMvc;
@Autowired
private JwtUtil jwtUtil;
@Test
@DisplayName("Wysyłanie Maila z waznym tokenem")
void testSendEmailWithValidAuthToken() throws Exception {
System.out.println("Startowanie testSendEmailWithValidAuthToken");
String jsonPayload = """
{
"to": "test@example.com",
"subject": "Test Subject",
"body": "Test Body"
}
""";
System.out.println("Wysyłanie JSON payload: " + jsonPayload);
String jwtToken = "Bearer " + jwtUtil.generateToken("test@example.com", "USER", 1L);
MvcResult result = mockMvc.perform(post("/api/v1/email/send")
.header("Authorization", jwtToken)
.contentType(MediaType.APPLICATION_JSON)
.content(jsonPayload))
.andExpect(status().isOk())
.andExpect(content().string("Email wysłany pomyślnie"))
.andReturn();
System.out.println("Status odpowiedzi: " + result.getResponse().getStatus());
System.out.println("Treść odpowiedzi: " + result.getResponse().getContentAsString());
}
@Test
@DisplayName("Wysyłanie Maila bez tokena")
void testSendEmailWithoutAuthToken() throws Exception {
System.out.println("Startowanie testSendEmailWithoutAuthToken");
String jsonPayload = """
{
"to": "test@example.com",
"subject": "Test Subject",
"body": "Test Body"
}
""";
System.out.println("Wysyłanie JSON payload: " + jsonPayload);
MvcResult result = mockMvc.perform(post("/api/v1/email/send")
.contentType(MediaType.APPLICATION_JSON)
.content(jsonPayload))
.andExpect(status().isForbidden())
.andReturn();
System.out.println("Status odpowiedzi: " + result.getResponse().getStatus());
System.out.println("Treść odpowiedzi: " + result.getResponse().getContentAsString());
}
}

View File

@@ -39,6 +39,9 @@ class NoticeServiceTest {
@Mock
private AttributeValuesRepository attributeValuesRepository;
@Mock
private AttributesNoticeRepository attributesNoticeRepository;
@InjectMocks
private NoticeService noticeService;
@@ -121,8 +124,8 @@ class NoticeServiceTest {
@DisplayName("Dodanie ogłoszenia z atrybutami")
void addNotice_WithAttributes_ShouldSaveAttributes() {
AttributeDto attributeDto = new AttributeDto();
attributeDto.setName("Materiał");
attributeDto.setValue("Drewno");
attributeDto.setName("Kolor");
attributeDto.setValue("Zielony");
sampleNoticeRequest.setAttributes(List.of(attributeDto));
when(clientRepository.findById(1L)).thenReturn(Optional.of(sampleClient));