Skip to content

Commit

Permalink
checked that cart is in correct status. Added unit tests (#116)
Browse files Browse the repository at this point in the history
Co-authored-by: giomella <[email protected]>
  • Loading branch information
gioelemella and giomella authored Jan 8, 2024
1 parent 29d1478 commit ca6e6ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public void run(
) {
logger.info("[{}] function called at {}", context.getFunctionName(), LocalDateTime.now());

if (!cartForReceipt.getStatus().equals(CartStatusType.INSERTED)) {
logger.info("[{}] Cart with id {} not in status {}, this event will be skipped",
context.getFunctionName(), cartForReceipt.getId(), CartStatusType.INSERTED);
return;
}

if (cartForReceipt.getTotalNotice() != cartForReceipt.getCartPaymentId().size()) {
logger.info("[{}] Not all items collected for cart with id {}, this event will be skipped",
context.getFunctionName(), cartForReceipt.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,27 @@ void cartEventToReceiptSuccess() {
}

@Test
void cartEventToReceiptSkip() {
void cartEventToReceiptSkipNotInStatusInserted() {
CartForReceipt cartForReceipt = getCartForReceipt();
cartForReceipt.setStatus(CartStatusType.FAILED);
assertDoesNotThrow(() -> sut.run(cartForReceipt, receiptDocumentdb, cartForReceiptDocumentdb, contextMock));

verify(bizEventToReceiptServiceMock, never()).getCartBizEvents(anyString());
verify(bizEventToReceiptServiceMock, never()).handleSaveReceipt(any());
verify(bizEventToReceiptServiceMock, never()).handleSendMessageToQueue(anyList(), any());

verify(receiptDocumentdb, never()).setValue(receiptCaptor.capture());
verify(cartForReceiptDocumentdb, never()).setValue(cartCaptor.capture());
}

@Test
void cartEventToReceiptSkipNotAllBizEventsCollected() {
Set<String> bizEventIds = new HashSet<>();
bizEventIds.add("id");
CartForReceipt cartForReceipt = CartForReceipt.builder()
.id("123")
.totalNotice(2)
.status(CartStatusType.INSERTED)
.cartPaymentId(bizEventIds)
.build();

Expand Down Expand Up @@ -226,6 +241,7 @@ private CartForReceipt getCartForReceipt() {
return CartForReceipt.builder()
.id("123")
.totalNotice(2)
.status(CartStatusType.INSERTED)
.cartPaymentId(bizEventIds)
.build();
}
Expand Down

0 comments on commit ca6e6ea

Please sign in to comment.