Skip to content

Commit

Permalink
MODTLR-19 Create a client to update DCB transaction statuses (#16)
Browse files Browse the repository at this point in the history
* MODTLR-12 Initial implementation

* MODTLR-12 Rename endpoint to be consistent

* MODTLR-12 Rename copied schemas

* MODTLR-19 Add schema, client

* MODTLR-12 Rename component in yaml

* MODTLR-19 Add schema, mapping

* MODTLR-19 Add GET mapping for transaction status

* MODTLR-12 Fix code smells in unit tests

* MODTLR-19 Fix code smells in unit tests

* MODTLR-19 Change schema, response type

* MODTLR-12 Change schema, response type

* MODTLR-12 Add transaction ID

---------

Co-authored-by: Roman Barannyk <[email protected]>
  • Loading branch information
alexanderkurash and roman-barannyk authored Mar 1, 2024
1 parent 63ffa5e commit 65893ef
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/java/org/folio/client/feign/DcbClient.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.folio.client.feign;

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.GetMapping;
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)
Expand All @@ -15,4 +18,11 @@ public interface DcbClient {
TransactionStatusResponse createDcbTransaction(@PathVariable String dcbTransactionId,
@RequestBody DcbTransaction dcbTransaction);

@GetMapping("/transactions/{dcbTransactionId}/status")
TransactionStatusResponse getDcbTransactionStatus(@PathVariable String dcbTransactionId);

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

}
2 changes: 1 addition & 1 deletion src/main/resources/swagger.api/ecs-tlr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ components:
transactionStatus:
$ref: 'schemas/transactionStatus.yaml#/TransactionStatus'
transactionStatusResponse:
$ref: 'schemas/transactionStatusResponse.yaml#/TransactionStatusResponse'
$ref: 'schemas/transactionStatusResponse.yaml#/TransactionStatusResponse'
errorResponse:
$ref: 'schemas/errors.json'
request:
Expand Down
41 changes: 41 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,7 @@

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;
Expand Down Expand Up @@ -40,4 +41,44 @@ void canCreateDcbTransaction() {
assertEquals(TransactionStatusResponse.RoleEnum.BORROWER, response.getRole());
assertEquals(requestId, response.getRequestId());
}

@Test
void canGetDcbTransactionStatus() {
String requestId = UUID.randomUUID().toString();
String transactionId = UUID.randomUUID().toString();
DcbTransaction dcbTransaction = new DcbTransaction()
.role(DcbTransaction.RoleEnum.BORROWER)
.requestId(requestId);
TransactionStatusResponse transactionStatusResponse = new TransactionStatusResponse()
.status(TransactionStatusResponse.StatusEnum.CANCELLED)
.message("test message")
.item(dcbTransaction.getItem())
.requestId(requestId);
when(dcbClient.getDcbTransactionStatus(transactionId)).thenReturn(transactionStatusResponse);
var response = dcbClient.getDcbTransactionStatus(transactionId);
assertNotNull(response);
assertEquals(TransactionStatusResponse.StatusEnum.CANCELLED, response.getStatus());
}

@Test
void canChangeDcbTransactionStatus() {
String requestId = UUID.randomUUID().toString();
String transactionId = UUID.randomUUID().toString();
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())
.requestId(requestId);
when(dcbClient.changeDcbTransactionStatus(transactionId, targetStatus))
.thenReturn(transactionStatusResponse);
var response = dcbClient.changeDcbTransactionStatus(transactionId, targetStatus);
assertNotNull(response);
assertEquals(TransactionStatusResponse.StatusEnum.CANCELLED, response.getStatus());
}
}

0 comments on commit 65893ef

Please sign in to comment.