Skip to content

Commit

Permalink
added deleteMessage and deleted createMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
molynx committed Oct 8, 2023
1 parent 0c282e7 commit ceb3cbc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ public ResponseEntity<?> getMessage(@PathVariable Long id) {
public List<MessageResponseDto> getAllMessages() {
return this.messageService.getAllMessages();
}

@PostMapping("/")
public ResponseEntity<MessageResponseDto> createMessage(@RequestBody MessageRequestDto message) {
MessageResponseDto createdMessage = messageService.createMessage(message);
return ResponseEntity.status(HttpStatus.CREATED).body(createdMessage);
}

@DeleteMapping("/{id}")
public ResponseEntity<?> deleteMessage(@PathVariable Long id) {
Expand All @@ -59,4 +53,10 @@ public ResponseEntity<MessageResponseDto> scheduleMessage(@RequestBody MessageRe
MessageResponseDto scheduledMessage = messageService.scheduleMessage(message);
return ResponseEntity.status(HttpStatus.CREATED).body(scheduledMessage);
}

@DeleteMapping("/delete/{id}")
public ResponseEntity<?> deleteItem(@PathVariable Long id) {
this.messageService.deleteMessage(id);
return ResponseEntity.ok("Message deleted properly");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public void setUp() {

@Test
public void createMessageAndFindByIdTest() {
String requestJson = "{\"messageBody\": \"Random message body\","
+ "\"year\": 2023,"
String requestJson = "{\"messageBody\": \"Random message body\","
+ "\"year\": 2027,"
+ "\"month\": 9,"
+ "\"day\": 30,"
+ "\"hour\": 20,"
Expand All @@ -32,7 +32,7 @@ public void createMessageAndFindByIdTest() {
.contentType(ContentType.JSON)
.body(requestJson)
.when()
.post("/api/message/")
.post("/api/message/schedule")
.then()
.contentType(ContentType.JSON)
.body("messageBody", equalTo("Random message body"))
Expand Down Expand Up @@ -68,7 +68,7 @@ public void createMessagesAndFindAllTest() {
.contentType(ContentType.JSON)
.body(requestJson1)
.when()
.post("/api/message/")
.post("/api/message/schedule")
.then()
.contentType(ContentType.JSON)
.body("messageBody", equalTo("Random message body 1"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,6 @@ public void getAllMessageTest() throws Exception {
.andExpect(jsonPath("$[1].messageBody").value(messageResponseDto2.getMessageBody()));
}

@Test
@DisplayName("create a message and verify its existence")
public void createMessageTest() throws Exception {
String messageRequestDtoContent = "{\"messageBody\": \"Random message body\"}";
ZonedDateTime executionTime =ZonedDateTime.of(2023, 9, 24, 17, 46, 0, 0, ZoneId.of("Europe/Madrid"));
LocalDateTime serverExecutionTime = executionTime.withZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime();
MessageResponseDto messageResponseDto = new MessageResponseDto(1L, "Random message body", executionTime, serverExecutionTime, true);

when(messageService.createMessage(any(MessageRequestDto.class))).thenReturn(messageResponseDto);

mockMvc.perform(post("/api/message/")
.contentType(MediaType.APPLICATION_JSON)
.content(messageRequestDtoContent))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.messageBody").value(messageResponseDto.getMessageBody()));
}

@Test
@DisplayName("deletes a message")
public void deleteMessageTest() throws Exception {
Expand Down

0 comments on commit ceb3cbc

Please sign in to comment.