Skip to content

Commit

Permalink
MODINVOICE-534. Provide more params for acq units response (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
SerhiiNosko authored Mar 14, 2024
1 parent f2f7875 commit 7eee8a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/java/org/folio/services/order/OrderLineService.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public Future<CompositePoLine> getPoLine(String poLineId, RequestContext request
return restClient.get(requestEntry, CompositePoLine.class, requestContext)
.recover(cause -> {
if (ExceptionUtil.matches(cause, USER_NOT_A_MEMBER_OF_THE_ACQ)) {
var causeParam = new Parameter().withKey("cause").withValue(cause.getMessage());
throw new HttpException(403, USER_NOT_A_MEMBER_OF_THE_ACQ, List.of(causeParam));
var typeParam = new Parameter().withKey("type").withValue("order");
throw new HttpException(403, USER_NOT_A_MEMBER_OF_THE_ACQ, List.of(typeParam));
} else {
var param = new Parameter().withKey("poLineId").withValue(poLineId);
var causeParam = new Parameter().withKey("cause").withValue(cause.getMessage());
Expand All @@ -65,8 +65,9 @@ public Future<Void> updateCompositePoLines(List<CompositePoLine> poLines, Reques
.map(poLine -> updatePoLine(poLine, requestContext)
.recover(cause -> {
if (ExceptionUtil.matches(cause, USER_NOT_A_MEMBER_OF_THE_ACQ)) {
var causeParam = new Parameter().withKey("cause").withValue(cause.getMessage());
throw new HttpException(403, USER_NOT_A_MEMBER_OF_THE_ACQ, List.of(causeParam));
var typeParam = new Parameter().withKey("type").withValue("order");
var poLineNumberParam = new Parameter().withKey("poLineNumber").withValue(poLine.getPoLineNumber());
throw new HttpException(403, USER_NOT_A_MEMBER_OF_THE_ACQ, List.of(typeParam, poLineNumberParam));
} else {
var causeParam = new Parameter().withKey("cause").withValue(cause.getMessage());
throw new HttpException(400, PO_LINE_UPDATE_FAILURE, List.of(causeParam));
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/folio/services/order/OrderServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.folio.invoices.utils.ErrorCodes.CANNOT_DELETE_INVOICE_LINE;
import static org.folio.invoices.utils.ErrorCodes.USER_NOT_A_MEMBER_OF_THE_ACQ;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
Expand All @@ -27,6 +28,7 @@
import org.folio.rest.core.models.RequestContext;
import org.folio.rest.core.models.RequestEntry;
import org.folio.rest.jaxrs.model.Error;
import org.folio.rest.jaxrs.model.Parameter;
import org.folio.services.invoice.InvoiceLineService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -153,6 +155,10 @@ void shouldRethrowUserNotAMemberOfTheAcqWhenUpdatePoLine(VertxTestContext vertxT
assertEquals(HttpStatus.HTTP_FORBIDDEN.toInt(), httpException.getCode());
Error error = httpException.getErrors().getErrors().get(0);
assertEquals(USER_NOT_A_MEMBER_OF_THE_ACQ.getCode(), error.getCode());
Parameter typeParam = error.getParameters().stream().filter(param -> "type".equals(param.getKey())).findFirst().get();
assertEquals("order", typeParam.getValue());
Parameter poLineNumberParam = error.getParameters().stream().filter(param -> "poLineNumber".equals(param.getKey())).findFirst().get();
assertNotNull(poLineNumberParam);
vertxTestContext.completeNow();
});
}
Expand All @@ -172,6 +178,8 @@ void shouldRethrowUserNotAMemberOfTheAcqWhenGetPoLine(VertxTestContext vertxTest
HttpException httpException = (HttpException) result.cause();
assertEquals(HttpStatus.HTTP_FORBIDDEN.toInt(), httpException.getCode());
Error error = httpException.getErrors().getErrors().get(0);
Parameter typeParam = error.getParameters().stream().filter(param -> "type".equals(param.getKey())).findFirst().get();
assertEquals("order", typeParam.getValue());
assertEquals(USER_NOT_A_MEMBER_OF_THE_ACQ.getCode(), error.getCode());
vertxTestContext.completeNow();
});
Expand Down

0 comments on commit 7eee8a0

Please sign in to comment.