-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODDCB-90 Accept existing circulation request ID
- Loading branch information
1 parent
25ceb19
commit 3ad3189
Showing
4 changed files
with
101 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/test/java/org/folio/dcb/controller/EcsRequestTransactionsApiControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.folio.dcb.controller; | ||
|
||
import org.folio.dcb.domain.entity.TransactionAuditEntity; | ||
import org.folio.dcb.repository.TransactionAuditRepository; | ||
import org.folio.dcb.repository.TransactionRepository; | ||
import org.folio.spring.service.SystemUserScopedExecutionService; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import static org.folio.dcb.domain.dto.DcbTransaction.RoleEnum.LENDER; | ||
import static org.folio.dcb.utils.EntityUtils.DCB_TRANSACTION_ID; | ||
import static org.folio.dcb.utils.EntityUtils.createEcsRequestTransactionByRole; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
public class EcsRequestTransactionsApiControllerTest extends BaseIT { | ||
|
||
private static final String TRANSACTION_AUDIT_DUPLICATE_ERROR_ACTION = "DUPLICATE_ERROR"; | ||
private static final String DUPLICATE_ERROR_TRANSACTION_ID = "-1"; | ||
|
||
@Autowired | ||
private TransactionRepository transactionRepository; | ||
@Autowired | ||
private TransactionAuditRepository transactionAuditRepository; | ||
@Autowired | ||
private SystemUserScopedExecutionService systemUserScopedExecutionService; | ||
|
||
@Test | ||
void createLendingEcsRequestTest() throws Exception { | ||
removeExistedTransactionFromDbIfSoExists(); | ||
|
||
this.mockMvc.perform( | ||
post("/ecs-request-transactions/" + DCB_TRANSACTION_ID) | ||
.content(asJsonString(createEcsRequestTransactionByRole(LENDER))) | ||
.headers(defaultHeaders()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.accept(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isCreated()); | ||
|
||
//Trying to create another transaction with same transaction id | ||
this.mockMvc.perform( | ||
post("/ecs-request-transactions/" + DCB_TRANSACTION_ID) | ||
.content(asJsonString(createEcsRequestTransactionByRole(LENDER))) | ||
.headers(defaultHeaders()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.accept(MediaType.APPLICATION_JSON)) | ||
.andExpectAll(status().is4xxClientError(), | ||
jsonPath("$.errors[0].code", is("DUPLICATE_ERROR"))); | ||
|
||
// check for DUPLICATE_ERROR propagated into transactions_audit. | ||
systemUserScopedExecutionService.executeAsyncSystemUserScoped( | ||
TENANT, | ||
() -> { | ||
TransactionAuditEntity auditExisting = transactionAuditRepository | ||
.findLatestTransactionAuditEntityByDcbTransactionId(DCB_TRANSACTION_ID) | ||
.orElse(null); | ||
Assertions.assertNotNull(auditExisting); | ||
Assertions.assertNotEquals(TRANSACTION_AUDIT_DUPLICATE_ERROR_ACTION, auditExisting.getAction()); | ||
Assertions.assertNotEquals(DUPLICATE_ERROR_TRANSACTION_ID, auditExisting.getTransactionId()); } | ||
); | ||
} | ||
|
||
private void removeExistedTransactionFromDbIfSoExists() { | ||
systemUserScopedExecutionService.executeAsyncSystemUserScoped(TENANT, () -> { | ||
if (transactionRepository.existsById(DCB_TRANSACTION_ID)){ | ||
transactionRepository.deleteById(DCB_TRANSACTION_ID); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"mappings": [ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"url": "/request-storage/requests/398501a2-5c97-4ba6-9ee7-d1cd6433cb98" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"body": "{\n \"id\" : \"05f09b87-9022-4036-a94b-3dca1bc11f70\",\n \"requestLevel\" : \"Item\",\n \"requestType\" : \"Page\",\n \"requestDate\" : \"2024-03-07T13:54:08.655+00:00\",\n \"requesterId\" : \"2205005b-ca51-4a04-87fd-938eefa8f6de\",\n \"instanceId\" : \"5bf370e0-8cca-4d9c-82e4-5170ab2a0a39\",\n \"holdingsRecordId\" : \"e3ff6133-b9a2-4d4c-a1c9-dc1867d4df19\",\n \"itemId\" : \"100d10bf-2f06-4aa0-be15-0b95b2d9f9e3\",\n \"status\" : \"Open - Not yet filled\",\n \"position\" : 1,\n \"instance\" : {\n \"title\" : \"A semantic web primer\",\n \"identifiers\" : [ {\n \"identifierTypeId\" : \"8261054f-be78-422d-bd51-4ed9f33c3422\",\n \"value\" : \"0262012103\"\n }, {\n \"identifierTypeId\" : \"8261054f-be78-422d-bd51-4ed9f33c3422\",\n \"value\" : \"9780262012102\"\n }, {\n \"identifierTypeId\" : \"c858e4f2-2b6b-4385-842b-60732ee14abb\",\n \"value\" : \"2003065165\"\n } ],\n \"contributorNames\" : [ {\n \"name\" : \"Antoniou, Grigoris\"\n }, {\n \"name\" : \"Van Harmelen, Frank\"\n } ],\n \"publication\" : [ {\n \"publisher\" : \"MIT Press\",\n \"place\" : \"Cambridge, Mass. \",\n \"dateOfPublication\" : \"c2004\",\n \"role\" : \"Publisher\"\n } ]\n },\n \"item\" : {\n \"barcode\" : \"90000\",\n \"location\" : {\n \"name\" : \"Annex\",\n \"libraryName\" : \"Datalogisk Institut\",\n \"code\" : \"KU/CC/DI/A\"\n },\n \"enumeration\" : \"\",\n \"status\" : \"Paged\",\n \"callNumber\" : \"TK5105.88815 . A58 2004 FT MEADE\",\n \"callNumberComponents\" : {\n \"callNumber\" : \"TK5105.88815 . A58 2004 FT MEADE\"\n }\n },\n \"requester\" : {\n \"lastName\" : \"rick\",\n \"firstName\" : \"psych\",\n \"barcode\" : \"123\",\n \"patronGroup\" : {\n \"id\" : \"3684a786-6671-4268-8ed0-9db82ebca60b\",\n \"group\" : \"staff\",\n \"desc\" : \"Staff Member\"\n },\n \"patronGroupId\" : \"3684a786-6671-4268-8ed0-9db82ebca60b\"\n },\n \"fulfillmentPreference\" : \"Hold Shelf\",\n \"pickupServicePointId\" : \"3a40852d-49fd-4df2-a1f9-6e2641a6e91f\",\n \"metadata\" : {\n \"createdDate\" : \"2024-03-07T13:54:13.484+00:00\",\n \"createdByUserId\" : \"5600bae3-4ca8-42dd-bef5-4502aaea6dc7\",\n \"updatedDate\" : \"2024-03-07T13:54:14.768+00:00\",\n \"updatedByUserId\" : \"5600bae3-4ca8-42dd-bef5-4502aaea6dc7\"\n },\n \"pickupServicePoint\" : {\n \"name\" : \"Circ Desk 1\",\n \"code\" : \"cd1\",\n \"discoveryDisplayName\" : \"Circulation Desk -- Hallway\",\n \"description\" : null,\n \"shelvingLagTime\" : null,\n \"pickupLocation\" : true\n }\n }", | ||
"headers": { | ||
"Content-Type": "application/json" | ||
} | ||
} | ||
} | ||
] | ||
} |