Skip to content

Commit 8a2cb46

Browse files
authored
Merge pull request #90 from SpringNoobs/89-ajustar-a-classe-remindercontrollertest-para-total-cobertura-dos-testes
89 ajustar a classe remindercontrollertest para total cobertura dos testes
2 parents e164145 + d004e0c commit 8a2cb46

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/docs/asciidoc/index-en-US.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ A `POST` request will create a new reminder.
8282

8383
operation::create-reminder[snippets='http-request,curl-request,http-response,request-body']
8484

85+
==== Create a reminder (Internal failure)
86+
87+
A `POST` request to create a reminder may result in an internal failure.
88+
89+
operation::create-reminder-scheduler-error[snippets='http-response']
90+
8591
==== Create a reminder (past date)
8692

8793
operation::create-reminder-past-date[snippets='http-response']

src/docs/asciidoc/index-pt-BR.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ Uma requisição `POST` criará um novo lembrete.
8282

8383
operation::create-reminder[snippets='http-request,curl-request,http-response,request-body']
8484

85+
==== Criar um lembrete (Falha interna)
86+
87+
Uma requisição `POST` para criar um lembrete pode resultar em falha interna.
88+
89+
operation::create-reminder-scheduler-error[snippets='http-response']
90+
8591
==== Criar um lembrete (data no passado)
8692

8793
operation::create-reminder-past-date[snippets='http-response']

src/test/java/br/com/springnoobs/reminderapi/reminder/controller/ReminderControllerTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import br.com.springnoobs.reminderapi.reminder.dto.response.ReminderResponseDTO;
1414
import br.com.springnoobs.reminderapi.reminder.exception.NotFoundException;
1515
import br.com.springnoobs.reminderapi.reminder.exception.PastDueDateException;
16+
import br.com.springnoobs.reminderapi.reminder.exception.ReminderSchedulerException;
1617
import br.com.springnoobs.reminderapi.reminder.service.ReminderService;
1718
import br.com.springnoobs.reminderapi.user.dto.request.ContactRequestDTO;
1819
import br.com.springnoobs.reminderapi.user.dto.request.CreateUserRequestDTO;
@@ -128,6 +129,24 @@ void shouldReturnBadRequestWhenCreatingReminderWithPastDate() throws Exception {
128129
.andDo(document("create-reminder-past-date"));
129130
}
130131

132+
@Test
133+
void shouldReturnInternalServerErrorWhenSchedulerFailsOnCreate() throws Exception {
134+
CreateUserRequestDTO createUserRequestDTO = new CreateUserRequestDTO(
135+
"First Name", "Last Name", new ContactRequestDTO("email@test.com", "123456789"));
136+
137+
var request = new CreateReminderRequestDTO("New Reminder", Instant.now().plusSeconds(60), createUserRequestDTO);
138+
139+
when(service.create(request)).thenThrow(new ReminderSchedulerException("Scheduler error on create"));
140+
141+
mockMvc.perform(post("/reminders")
142+
.contentType(MediaType.APPLICATION_JSON)
143+
.content(objectMapper.writeValueAsString(request)))
144+
.andExpect(status().isInternalServerError())
145+
.andExpect(jsonPath("$.title").value("Internal Server Error"))
146+
.andExpect(jsonPath("$.detail").value("Scheduler error on create"))
147+
.andDo(document("create-reminder-scheduler-error"));
148+
}
149+
131150
@Test
132151
void shouldUpdateReminderWhenRequestIsValid() throws Exception {
133152
long reminderId = 1L;

0 commit comments

Comments
 (0)