jaikamat / clubhouse-pos-importer

Monorepo for an LGS's inventory management system
1 stars 0 forks source link

Improve sale validation #345

Closed jaikamat closed 3 years ago

jaikamat commented 3 years ago

Summary

Found a bug in development that could have caused some confusion if it ever bubbled up to userland. I suspect the small and controlled scale of the application affected why this never showed up in production, but it should be dealt with nonetheless.

To reproduce:

  1. Open a tab and add 2 copies of a card through manage inventory
  2. Open another tab, go to make a new sale, and attempt to add the two cards to the sale list
  3. Navigate back to tab 1 and remove the cards from inventory
  4. Switch back to sales and click "finalize sale". The sale completes, despite those cards not being in inventory!

Usually step 4 is mitigated by the fact that employees physically pull cards to inspect them prior to sale. However, we perform this validation on sale suspension, so it naturally makes sense for us to do the same with proper sales.

In this PR, I've extracted the validation interactor that originally existed in createSuspendedSale, tested it, and integrated it into the finishSaleValidationController to stop sales in their tracks should it throw an error.

Note: Unsuspended sales are deleted entirely on submission, and inventory is restored prior to selling one, so they remain un-affected as inventory is reconciled properly.