Skip to content

Commit

Permalink
MODTLR-19 Add schema, mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkurash committed Feb 16, 2024
1 parent 31ae21d commit 7b24ac7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/org/folio/client/feign/DcbClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

import org.folio.domain.dto.DcbTransaction;
import org.folio.domain.dto.TransactionStatus;
import org.folio.domain.dto.TransactionStatusResponse;
import org.folio.spring.config.FeignClientConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

@FeignClient(name = "dcb", url = "${folio.okapi-url}", configuration = FeignClientConfiguration.class)
public interface DcbClient {

@PostMapping("/ecs-tlr-transactions")
DcbTransaction createDcbTransaction(DcbTransaction dcbTransaction);

@PostMapping("/transactions")
DcbTransaction changeDcbTransactionStatus(String transactionId, TransactionStatus newStatus);
@PutMapping("/transactions/{dcbTransactionId}/status")
TransactionStatusResponse changeDcbTransactionStatus(@PathVariable String dcbTransactionId,
@RequestBody TransactionStatus newStatus);

}
2 changes: 2 additions & 0 deletions src/main/resources/swagger.api/ecs-tlr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ components:
$ref: 'schemas/dcbTransaction.yaml#/DcbTransaction'
transactionStatus:
$ref: 'schemas/transactionStatus.yaml#/TransactionStatus'
transactionStatusResponse:
$ref: 'schemas/transactionStatusResponse.yaml#/TransactionStatusResponse'
errorResponse:
$ref: 'schemas/errors.json'
request:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TransactionStatusResponse:
allOf:
- $ref: 'transactionStatus.yaml#/TransactionStatus'
- $ref: 'dcbTransaction.yaml#/DcbTransaction'
28 changes: 28 additions & 0 deletions src/test/java/org/folio/client/DcbClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import org.folio.client.feign.DcbClient;
import org.folio.domain.dto.DcbTransaction;
import org.folio.domain.dto.TransactionStatus;
import org.folio.domain.dto.TransactionStatusResponse;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
Expand All @@ -30,4 +32,30 @@ void canCreateDcbTransaction() {
assertEquals(response.getRole(), DcbTransaction.RoleEnum.BORROWER);
assertEquals(response.getRequestId(), requestId);
}

@Test
void canChangeDcbTransactionStatus() {
String requestId = UUID.randomUUID().toString();
String transactionId = UUID.randomUUID().toString();
TransactionStatus initialStatus = new TransactionStatus()
.status(TransactionStatus.StatusEnum.AWAITING_PICKUP);
TransactionStatus targetStatus = new TransactionStatus()
.status(TransactionStatus.StatusEnum.CANCELLED)
.message("test message");
DcbTransaction dcbTransaction = new DcbTransaction()
.role(DcbTransaction.RoleEnum.BORROWER)
.requestId(requestId);
TransactionStatusResponse transactionStatusResponse = new TransactionStatusResponse()
.status(TransactionStatusResponse.StatusEnum.CANCELLED)
.message("test message")
.item(dcbTransaction.getItem())
.patron(dcbTransaction.getPatron())
.pickup(dcbTransaction.getPickup())
.requestId(requestId);
when(dcbClient.changeDcbTransactionStatus(transactionId, targetStatus))
.thenReturn(transactionStatusResponse);
var response = dcbClient.changeDcbTransactionStatus(transactionId, targetStatus);
assertNotNull(response);
assertEquals(response.getStatus(), TransactionStatusResponse.StatusEnum.CANCELLED);
}
}

0 comments on commit 7b24ac7

Please sign in to comment.