Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODTLR-19 Create a client to update DCB transaction statuses #16

Merged
merged 18 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}