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

GreenCityUBS bug in saving events #975

Merged
merged 4 commits into from
Jan 31, 2023
Merged

Conversation

LiliaMokhnatska
Copy link
Contributor

@LiliaMokhnatska LiliaMokhnatska commented Jan 29, 2023

Green City UBS bug in writing order history PR

Summary Of Issue :

Create a new order. Change the confirmed number of bags. Open order history. The changed order details show that the quantity has been changed from 0 to "Підтверджена к-ть" .
image

It is expected that the changed order details show that the quantity has been changed from "Планована к-ть" to "Підтверджена к-ть"

image

Issue Link :

ita-social-projects/GreenCity#5058

Summary Of Changes :

  1. add getAmount method in UpdateOrderDetailRepository
  2. change method collectEventAboutSetOrderDetails in UBSManagementServiceImpl
  3. add test for new lines of code

Code reviewers

  • @github_username

Added

add getAmount method in UpdateOrderDetailRepository
add test for new lines of code

Changed

change method collectEventAboutSetOrderDetails in UBSManagementServiceImpl

Deleted

How to test :

  1. User need to be logged in http://localhost:8060/swagger-ui.html#/own-security-controller
  2. Register Token
  3. Create an order https://www.testgreencity.ga/GreenCityClient/#/ubs/order
  4. Admin need to be logged in http://localhost:8060/swagger-ui.html#/own-security-controller
  5. Register Token
  6. Choose "Деталі замовлення" https://www.testgreencity.ga/GreenCityClient/#/ubs-admin/order/1116
  7. Choose "Підтверджена к-ть" change and submit
  8. Choose "Історія замовлення"

CHECK LIST

  • Code is up-to-date with the dev branch.
  • You've successfully built and run the tests locally.
  • There are new or updated unit tests validating the change.
  • JIRA/ Github Issue number & title in PR title (ISSUE-#5058: Ticket title)
  • This template filled (above this section).
  • Sonar's report does not contain bugs, vulnerabilities, security issues, code smells ar duplication
  • NEED_REVIEW and READY_FOR_REVIEW labels are added.
  • All files reviewed before sending to reviewers

@LiliaMokhnatska LiliaMokhnatska changed the title change method collectEventAboutSetOrderDetails GreenCityUBS bug in saving events Jan 30, 2023
@@ -981,6 +981,7 @@ void testSetOrderDetailIfPaidAndPriceLessThanPaidSum() {
verify(orderRepository).updateOrderPointsToUse(1L, 0);
}

//

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to delete it, I forgot

}
if (entry.getValue().longValue() != confirmWasteWas.orElse(0L)) {
if (countOfChanges == 0) {
values.append(OrderHistory.CHANGE_ORDER_DETAILS + " ");
}
values.append(bag.getName()).append(" ").append(capacity).append(" л: ")
.append(confirmWasteWas.orElse(0L))
.append(confirmWasteWas.orElse(startAmount.orElse(0L)))
.append(" шт на ").append(entry.getValue()).append(" шт.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this text be localized?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be localized. Here is a link to this issue: ita-social-projects/GreenCity#5117

if (bagOptional.isPresent() && checkOrderStatusAboutConfirmWaste(order)) {
Optional<Long> confirmWasteWas = Optional.empty();
Optional<Long> startAmount = Optional.empty();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is better to use initial instead of start

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree

Bag bag = bagOptional.get();
if (Boolean.TRUE.equals(updateOrderRepository.ifRecordExist(orderId, entry.getKey().longValue()) > 0)) {
confirmWasteWas =
Optional.ofNullable(updateOrderRepository.getConfirmWaste(orderId, entry.getKey().longValue()));
startAmount =
Optional.ofNullable(updateOrderRepository.getAmount(orderId, entry.getKey().longValue()));
}
if (entry.getValue().longValue() != confirmWasteWas.orElse(0L)) {
if (countOfChanges == 0) {
values.append(OrderHistory.CHANGE_ORDER_DETAILS + " ");
}
values.append(bag.getName()).append(" ").append(capacity).append(" л: ")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here
should this text be localized?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will be solved in the next issue: ita-social-projects/GreenCity#5117

when(orderRepository.getOrderDetails(anyLong()))
.thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto()));
when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag()));
when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplication

*/
@Query(value = "SELECT AMOUNT FROM ORDER_BAG_MAPPING "
+ "WHERE ORDER_ID = :orderId AND BAG_ID = :bagId", nativeQuery = true)
Long getAmount(Long orderId, Long bagId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use JPA naming here and not use nativeQuery?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I'll change it

@@ -1000,6 +1001,27 @@ void testSetOrderDetailConfirmed() {
verify(updateOrderRepository).updateConfirm(anyInt(), anyLong(), anyLong());
}

@Test
void testSetOrderDetailConfirmed2() {
when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusConfirmedDto()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add verify

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@Test
void testSetOrderDetailConfirmed2() {
when(orderRepository.findById(1L)).thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusConfirmedDto()));
when(bagRepository.findCapacityById(1)).thenReturn(1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add verify

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

doNothing().when(updateOrderRepository).updateConfirm(anyInt(), anyLong(), anyLong());
when(orderRepository.getOrderDetails(anyLong()))
.thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto()));
when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add verify

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

.thenReturn(Optional.ofNullable(ModelUtils.getOrdersStatusFormedDto()));
when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag()));
when(bagRepository.findById(1)).thenReturn(Optional.of(ModelUtils.getTariffBag()));
when(updateOrderRepository.ifRecordExist(any(), any())).thenReturn(1L);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add verify

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Bag bag = bagOptional.get();
if (Boolean.TRUE.equals(updateOrderRepository.ifRecordExist(orderId, entry.getKey().longValue()) > 0)) {
confirmWasteWas =
Optional.ofNullable(updateOrderRepository.getConfirmWaste(orderId, entry.getKey().longValue()));
initialAmount =
Optional.ofNullable(updateOrderRepository.getAmount(orderId, entry.getKey().longValue()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the UpdateOrderRepository class should be renamed because it not only updates orders

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I renamed this interface and variables accordingly.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

90.6% 90.6% Coverage
0.0% 0.0% Duplication

@LiliaMokhnatska LiliaMokhnatska merged commit e934675 into dev Jan 31, 2023
@LiliaMokhnatska LiliaMokhnatska deleted the UBS_bug_history_order branch January 31, 2023 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants