Anonymous | Login
Project:
RSS
  
News | My View | View Issues | Roadmap | Summary

View Issue DetailsJump to Notes ] Issue History ] Print ]
ID
0045016
TypeCategorySeverityReproducibilityDate SubmittedLast Update
defect[Retail Modules] Web POSmajorhave not tried2020-09-09 16:122020-09-21 11:44
ReporteralostaleView Statuspublic 
Assigned ToRetail 
PrioritynormalResolutionfixedFixed in VersionRR20Q4
StatusclosedFix in branchFixed in SCM revision
ProjectionnoneETAnoneTarget Version
OSAnyDatabaseAnyJava version
OS VersionDatabase versionAnt version
Product VersionSCM revision 
Review Assigned To
Regression level
Regression date
Regression introduced in release
Regression introduced by commit
Triggers an Emergency PackNo
Summary

0045016: state actions mutate objects

DescriptionSome state actions perform mutations in objects that should be immutable.
Steps To ReproduceSome cases are detected by current tests if they are run in strict mode which does not allow to reassign frozen objects [1].

$ node --use_strict node_modules/.bin/jest

...
Summary of all failing tests
 FAIL modules/org.openbravo.retail.posterminal/web-test/model/business-object/cashup/Cashup-updateCashupFunction-afterTicketDone.test.js
  ● Cashup - updateCashup function › updateCashup in ticket done

    TypeError: Cannot assign to read only property 'amount' of object '#<Object>'

      332 | })[0];
      333 | if (cashupTax) {
    > 334 | cashupTax.amount = OB.DEC.add(
          | ^
      335 | cashupTax.amount,
      336 | newCashupTax.taxAmount
      337 | );

      at forEach (modules/org.openbravo.retail.posterminal/web/org.openbravo.retail.posterminal/app/model/business-object/cashup/CashupUtils.js:334:11)
          at Array.forEach (<anonymous>)
      at Object.countTicketInCashup (modules/org.openbravo.retail.posterminal/web/org.openbravo.retail.posterminal/app/model/business-object/cashup/CashupUtils.js:324:22)
      at Object.updateCashupFromTicket (modules/org.openbravo.retail.posterminal/web/org.openbravo.retail.posterminal/app/model/business-object/cashup/CashupUtils.js:401:51)
      at Object.<anonymous> (modules/org.openbravo.retail.posterminal/web-test/model/business-object/cashup/Cashup-updateCashupFunction-afterTicketDone.test.js:34:46)

 FAIL modules/org.openbravo.retail.posterminal/web-test/model/business-object/ticket/actions/CompleteCreditTicket.test.js
  ● Complete Credit ticket action › should complete ticket with credit, print it and synchronize it

    TypeError: Cannot assign to read only property 'creditUsed' of object '#<Object>'

      27 | // Set complete ticket properties
      28 | newTicket.payOnCredit = true;
    > 29 | newTicket.businessPartner.creditUsed += OB.DEC.mul(
         | ^
      30 | OB.DEC.abs(
      31 | OB.DEC.sub(newTicket.grossAmount, newTicket.paymentWithSign)
      32 | ),

      at Object.completeCreditTicket (modules/org.openbravo.retail.posterminal/web/org.openbravo.retail.posterminal/app/model/business-object/ticket/actions/CompleteCreditTicket.js:29:7)
      at Object.<anonymous> (modules/org.openbravo.retail.posterminal/web-test/model/business-object/ticket/actions/CompleteCreditTicket.test.js:72:45)

 FAIL modules/org.openbravo.retail.posterminal/web-test/model/business-object/cashup/Cashup-initCashup-StateAction-fromLocal.test.js
  ● Cashup - init cashup State Action - from local › initialize cashup from local - new Payment

    TypeError: Cannot assign to read only property 'cashPaymentMethodInfo' of object '#<Object>'

      58 | const cashupWithoutCard = { ...cleanCashup };
      59 | deepfreeze(cashupWithoutCard);
    > 60 | cashupWithoutCard.cashPaymentMethodInfo = cashupWithoutCard.cashPaymentMethodInfo.filter(
         | ^
      61 | payment => payment.name !== 'Card'
      62 | );
      63 | const initialState = { Cashup: cashupWithoutCard };

      at Object.<anonymous> (modules/org.openbravo.retail.posterminal/web-test/model/business-object/cashup/Cashup-initCashup-StateAction-fromLocal.test.js:60:5)

  ● Cashup - init cashup State Action - from local › initialize cashup from local - payment name changed

    TypeError: Cannot assign to read only property 'terminalPayments' of object '#<Object>'

      90 | const payloadPaymentNameChanged = { ...payloadInitFromLocal };
      91 | deepfreeze(payloadPaymentNameChanged);
    > 92 | payloadPaymentNameChanged.terminalPayments = [
         | ^
      93 | ...payloadInitFromLocal.terminalPayments
      94 | ];
      95 | payloadPaymentNameChanged.terminalPayments[0].paymentMethod = {

      at Object.<anonymous> (modules/org.openbravo.retail.posterminal/web-test/model/business-object/cashup/Cashup-initCashup-StateAction-fromLocal.test.js:92:5)

 FAIL modules/org.openbravo.retail.posterminal/web-test/model/business-object/cashup/Cashup-initCashup-StateAction-fromBackend.test.js
  ● Cashup - init cashup State Action - from backend › initialize cashup from backend

    TypeError: Cannot assign to read only property 'totalStartings' of object '#<Object>'

      143 | );
      144 | paymentMethods.push(paymentFromBackend);
    > 145 | currentCashupFromBackend.totalStartings = OB.DEC.add(
          | ^
      146 | currentCashupFromBackend.totalStartings,
      147 | paymentFromBackend.startingCash
      148 | );

      at forEach (modules/org.openbravo.retail.posterminal/web/org.openbravo.retail.posterminal/app/model/business-object/cashup/PaymentMethodUtils.js:145:13)
          at Array.forEach (<anonymous>)
      at Object.addPaymentsFromBackendCashup (modules/org.openbravo.retail.posterminal/web/org.openbravo.retail.posterminal/app/model/business-object/cashup/PaymentMethodUtils.js:119:54)
      at initCashup (modules/org.openbravo.retail.posterminal/web/org.openbravo.retail.posterminal/app/model/business-object/cashup/actions/InitCashup.js:61:71)
      at Object.<anonymous> (modules/org.openbravo.retail.posterminal/web-test/model/business-object/cashup/Cashup-initCashup-StateAction-fromBackend.test.js:66:20)

 FAIL modules/org.openbravo.retail.posterminal/web-test/model/business-object/ticket/CompleteTicketUtils-GenerateInvoice.test.js
  ● Ticket Utils generateInvoice function › should generate invoice when completing an immediate ticket with generateInvoice flag

    TypeError: Cannot add property ignorePromotions, object is not extensible

      292 | invoiceLine.qty = qtyToInvoice;
      293 | invoiceLine.orderLineId = line.id;
    > 294 | invoiceLine.product.ignorePromotions = true;
          | ^
      295 | invoiceLine.product.img = undefined;
      296 |
      297 | if (OB.DEC.abs(qtyAlreadyInvoiced) > 0) {

      at flatMap (modules/org.openbravo.retail.posterminal/web/org.openbravo.retail.posterminal/app/model/business-object/ticket/CompleteTicketUtils.js:294:7)
          at Array.flatMap (<anonymous>)
      at Object.generateInvoice (modules/org.openbravo.retail.posterminal/web/org.openbravo.retail.posterminal/app/model/business-object/ticket/CompleteTicketUtils.js:267:39)
      at Object.<anonymous> (modules/org.openbravo.retail.posterminal/web-test/model/business-object/ticket/CompleteTicketUtils-GenerateInvoice.test.js:25:49)


Test Suites: 5 failed, 99 passed, 104 total
Tests: 6 failed, 1072 passed, 1078 total


---
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Read-only [^]
TagsNo tags attached.
Attached Files

- Relationships Relation Graph ] Dependency Graph ]
related to feature request 0045019 closedRetail run jest tests in strict mode 
related to feature request 0045098 newTriage Platform Base IndexedDB ApplicationState infrastructure could help developers find immutability-related issues 

-  Notes
(0123195)
hgbot (developer)
2020-09-17 22:23

Merge Request created: https://gitlab.com/openbravo/product/pmods/org.openbravo.retail.posterminal/-/merge_requests/102 [^]
(0123259)
hgbot (developer)
2020-09-21 11:44

Directly closing issue as related merge request is already approved.

Repository: https://gitlab.com/openbravo/product/pmods/org.openbravo.retail.posterminal [^]
Changeset: 8e73627033fdfa9696cb667bf9d9e5a12a753c24
Author: Gorka Gil <gorka.gil@openbravo.com>
Date: 2020-09-21T09:44:13+00:00
URL: https://gitlab.com/openbravo/product/pmods/org.openbravo.retail.posterminal/-/commit/8e73627033fdfa9696cb667bf9d9e5a12a753c24 [^]

Fixes ISSUE-45016: avoid mutation in actions

Cashup:
- Fix many tests that freeze the variable before set its desired value
- PaymentMethodUtils.js:
  - remove no needed code that ws mutating the cashup recibed from backend,
    that was passed as payload to the method
- CashupUtils.js:
  - clone newCashup.cashTaxInfo array, and also its elements
    in case they are going to be modified
  - Also fix its test : Cashup - updateCashup function

Complete Ticket :
- CompleteTicketUtils.js: clone invoiceLine.product in generateInvoice method
- CompleteCreditTicket.js:
  - clone newTicket.businessPartner, this fix that selling on credit
    the bp.creditUsed is not updated
  - also fix the test Complete Credit ticket action

---
M web-test/model/business-object/cashup/Cashup-initCashup-StateAction-fromLocal.test.js
M web-test/model/business-object/cashup/Cashup-updateCashupFunction-afterTicketDone.test.js
M web-test/model/business-object/cashup/test-data/cashupBeforeTicketDone.js
M web-test/model/business-object/ticket/actions/CompleteCreditTicket.test.js
M web/org.openbravo.retail.posterminal/app/model/business-object/cashup/CashupUtils.js
M web/org.openbravo.retail.posterminal/app/model/business-object/cashup/PaymentMethodUtils.js
M web/org.openbravo.retail.posterminal/app/model/business-object/ticket/CompleteTicketUtils.js
M web/org.openbravo.retail.posterminal/app/model/business-object/ticket/actions/CompleteCreditTicket.js
---
(0123261)
hgbot (developer)
2020-09-21 11:44

Merge request merged: https://gitlab.com/openbravo/product/pmods/org.openbravo.retail.posterminal/-/merge_requests/102 [^]

- Issue History
Date Modified Username Field Change
2020-09-09 16:12 alostale New Issue
2020-09-09 16:12 alostale Assigned To => Retail
2020-09-09 16:12 alostale Triggers an Emergency Pack => No
2020-09-09 16:19 alostale Relationship added related to 0045019
2020-09-17 22:23 hgbot Note Added: 0123195
2020-09-21 11:28 marvintm Relationship added related to 0045098
2020-09-21 11:44 hgbot Resolution open => fixed
2020-09-21 11:44 hgbot Status new => closed
2020-09-21 11:44 hgbot Fixed in Version => RR20Q4
2020-09-21 11:44 hgbot Note Added: 0123259
2020-09-21 11:44 hgbot Note Added: 0123261


Copyright © 2000 - 2009 MantisBT Group
Powered by Mantis Bugtracker