Skip to content

Commit

Permalink
task-api-done
Browse files Browse the repository at this point in the history
  • Loading branch information
yacekmm committed Dec 6, 2024
1 parent 7021d4b commit d46d549
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import com.bottega.sharedlib.dto.ErrorDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.*;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.MediaType.APPLICATION_JSON;

@ControllerAdvice
Expand All @@ -18,8 +17,7 @@ public ResponseEntity<ErrorDto> convertToResponse(ErrorException exception) {
ErrorResult error = exception.getError();
log.info("Mapping Error to HTTP code: {}, error: {}", error.getType().getHttpStatus(), error);
return ResponseEntity
//TODO should it return 500 always?
.status(INTERNAL_SERVER_ERROR)
.status(error.getType().getHttpStatus())
.contentType(APPLICATION_JSON)
.body(ErrorDto.from(error));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public ErrorJsonAssert isNotFound(String expectedDescription) {
}

public ErrorJsonAssert isBadRequest(String expectedDesc) {
//TODO implement
return null;
errorResponse.statusCode(SC_BAD_REQUEST);
return hasType(BAD_REQUEST)
.hasCode(invalid_request)
.hasDescription(expectedDesc);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ public void createConcert_OK_onValidRequest() {

@Test
public void createConcert_returnsBadRequest_onDateTooSoon() {
//TODO implement
//given
ConcertHttpClient.ConcertRequest concertRequest = ConcertHttpClient.ConcertRequest.builder().date(TEST_TIME).build();

//when
ValidatableResponse response = concertFixtures.concertHttpClient.createConcert(concertRequest);

//then

assertThatError(response)
.isBadRequest("invalid_date");
}


Expand Down

0 comments on commit d46d549

Please sign in to comment.