From 4c50b40682cf2c6f8b7363de227dd7d4b0fe8191 Mon Sep 17 00:00:00 2001 From: Bill Randall Date: Wed, 25 Oct 2023 12:11:29 -0400 Subject: [PATCH 1/5] Display the debug message from the server --- .../productConfigForm/productConfigForm.component.js | 3 +++ .../productConfigForm/productConfigForm.tpl.html | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/app/productConfig/productConfigForm/productConfigForm.component.js b/src/app/productConfig/productConfigForm/productConfigForm.component.js index fc4aab92b..0b0f53436 100644 --- a/src/app/productConfig/productConfigForm/productConfigForm.component.js +++ b/src/app/productConfig/productConfigForm/productConfigForm.component.js @@ -339,6 +339,9 @@ class ProductConfigFormController { if (includes(error.data, 'already in the cart')) { this.errorAlreadyInCart = true this.onStateChange({ state: 'errorAlreadyInCart' }) + } else if (error?.data?.messages[0]?.id === 'field.invalid.decimal.format') { + this.amountFormatError = error?.data?.messages[0]['debug-message'] + this.onStateChange({ state: 'errorSubmitting' }) } else { this.errorSavingGeneric = true this.$log.error('Error adding or updating item in cart', error) diff --git a/src/app/productConfig/productConfigForm/productConfigForm.tpl.html b/src/app/productConfig/productConfigForm/productConfigForm.tpl.html index f8fa7b430..bc9c4d9af 100644 --- a/src/app/productConfig/productConfigForm/productConfigForm.tpl.html +++ b/src/app/productConfig/productConfigForm/productConfigForm.tpl.html @@ -57,6 +57,10 @@

{{'ADDING_CART_ERROR'}}

+ + From 6855acece123e011a72e073d972ee0e1c3e834e5 Mon Sep 17 00:00:00 2001 From: Bill Randall Date: Wed, 25 Oct 2023 15:10:56 -0400 Subject: [PATCH 2/5] Revert "Display the debug message from the server" --- .../productConfigForm/productConfigForm.component.js | 3 --- .../productConfigForm/productConfigForm.tpl.html | 4 ---- 2 files changed, 7 deletions(-) diff --git a/src/app/productConfig/productConfigForm/productConfigForm.component.js b/src/app/productConfig/productConfigForm/productConfigForm.component.js index 0b0f53436..fc4aab92b 100644 --- a/src/app/productConfig/productConfigForm/productConfigForm.component.js +++ b/src/app/productConfig/productConfigForm/productConfigForm.component.js @@ -339,9 +339,6 @@ class ProductConfigFormController { if (includes(error.data, 'already in the cart')) { this.errorAlreadyInCart = true this.onStateChange({ state: 'errorAlreadyInCart' }) - } else if (error?.data?.messages[0]?.id === 'field.invalid.decimal.format') { - this.amountFormatError = error?.data?.messages[0]['debug-message'] - this.onStateChange({ state: 'errorSubmitting' }) } else { this.errorSavingGeneric = true this.$log.error('Error adding or updating item in cart', error) diff --git a/src/app/productConfig/productConfigForm/productConfigForm.tpl.html b/src/app/productConfig/productConfigForm/productConfigForm.tpl.html index bc9c4d9af..f8fa7b430 100644 --- a/src/app/productConfig/productConfigForm/productConfigForm.tpl.html +++ b/src/app/productConfig/productConfigForm/productConfigForm.tpl.html @@ -57,10 +57,6 @@

{{'ADDING_CART_ERROR'}}

- - From 998635520b751613a8ac2f11a5d3d49df15b731b Mon Sep 17 00:00:00 2001 From: Bill Randall Date: Wed, 25 Oct 2023 16:13:46 -0400 Subject: [PATCH 3/5] Revert "Merge pull request #1066 from CruGlobal/revert-1064-better-error-for-bad-amount" This reverts commit 208fe7522fb2cf5e3f1b796d6282c03b40cf95be, reversing changes made to 9c0480f088c527404eafff9bc8ddc2194569a898. --- .../productConfigForm/productConfigForm.component.js | 3 +++ .../productConfigForm/productConfigForm.tpl.html | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/app/productConfig/productConfigForm/productConfigForm.component.js b/src/app/productConfig/productConfigForm/productConfigForm.component.js index 2c2d6bb0c..c3d41a816 100644 --- a/src/app/productConfig/productConfigForm/productConfigForm.component.js +++ b/src/app/productConfig/productConfigForm/productConfigForm.component.js @@ -340,6 +340,9 @@ class ProductConfigFormController { if (includes(error.data, 'already in the cart')) { this.errorAlreadyInCart = true this.onStateChange({ state: 'errorAlreadyInCart' }) + } else if (error?.data?.messages[0]?.id === 'field.invalid.decimal.format') { + this.amountFormatError = error?.data?.messages[0]['debug-message'] + this.onStateChange({ state: 'errorSubmitting' }) } else { this.errorSavingGeneric = true this.$log.error('Error adding or updating item in cart', error) diff --git a/src/app/productConfig/productConfigForm/productConfigForm.tpl.html b/src/app/productConfig/productConfigForm/productConfigForm.tpl.html index f8fa7b430..bc9c4d9af 100644 --- a/src/app/productConfig/productConfigForm/productConfigForm.tpl.html +++ b/src/app/productConfig/productConfigForm/productConfigForm.tpl.html @@ -57,6 +57,10 @@

{{'ADDING_CART_ERROR'}}

+ + From e17d9c28b7d75178d15fd35c6333f18f7b0937dd Mon Sep 17 00:00:00 2001 From: Bill Randall Date: Wed, 25 Oct 2023 15:54:02 -0400 Subject: [PATCH 4/5] Account for other style of error message --- .../productConfigForm/productConfigForm.component.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/productConfig/productConfigForm/productConfigForm.component.js b/src/app/productConfig/productConfigForm/productConfigForm.component.js index c3d41a816..332be369b 100644 --- a/src/app/productConfig/productConfigForm/productConfigForm.component.js +++ b/src/app/productConfig/productConfigForm/productConfigForm.component.js @@ -340,8 +340,11 @@ class ProductConfigFormController { if (includes(error.data, 'already in the cart')) { this.errorAlreadyInCart = true this.onStateChange({ state: 'errorAlreadyInCart' }) - } else if (error?.data?.messages[0]?.id === 'field.invalid.decimal.format') { - this.amountFormatError = error?.data?.messages[0]['debug-message'] + } else if (error.data.messages[0] && error.data.messages[0].id === 'field.invalid.decimal.format') { + this.amountFormatError = error.data.messages[0]['debug-message'] + this.onStateChange({ state: 'errorSubmitting' }) + } else if (includes(error.data, 'decimal number')) { + this.amountFormatError = error.data this.onStateChange({ state: 'errorSubmitting' }) } else { this.errorSavingGeneric = true From 3ba645337df99b44adf6b17b205a87acabcc808a Mon Sep 17 00:00:00 2001 From: Bill Randall Date: Wed, 25 Oct 2023 16:02:15 -0400 Subject: [PATCH 5/5] Add tests (which found a bug to fix) --- .../productConfigForm.component.js | 2 +- .../productConfigForm.component.spec.js | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/app/productConfig/productConfigForm/productConfigForm.component.js b/src/app/productConfig/productConfigForm/productConfigForm.component.js index 332be369b..0a419c178 100644 --- a/src/app/productConfig/productConfigForm/productConfigForm.component.js +++ b/src/app/productConfig/productConfigForm/productConfigForm.component.js @@ -340,7 +340,7 @@ class ProductConfigFormController { if (includes(error.data, 'already in the cart')) { this.errorAlreadyInCart = true this.onStateChange({ state: 'errorAlreadyInCart' }) - } else if (error.data.messages[0] && error.data.messages[0].id === 'field.invalid.decimal.format') { + } else if (error.data && error.data.messages && error.data.messages[0] && error.data.messages[0].id === 'field.invalid.decimal.format') { this.amountFormatError = error.data.messages[0]['debug-message'] this.onStateChange({ state: 'errorSubmitting' }) } else if (includes(error.data, 'decimal number')) { diff --git a/src/app/productConfig/productConfigForm/productConfigForm.component.spec.js b/src/app/productConfig/productConfigForm/productConfigForm.component.spec.js index 0ea691fb7..58df70abb 100644 --- a/src/app/productConfig/productConfigForm/productConfigForm.component.spec.js +++ b/src/app/productConfig/productConfigForm/productConfigForm.component.spec.js @@ -692,6 +692,41 @@ describe('product config form component', function () { expect($ctrl.errorSavingGeneric).toEqual(false) }) + it('should handle an error when saving a bad decimal amount - old error style', () => { + const error = { data: 'Amount must be a valid decimal number without dollar signs or commas.' } + $ctrl.cartService[operation].mockReturnValue(Observable.throw(error)) + $ctrl.itemConfigForm.$dirty = true + $ctrl.saveGiftToCart() + + expect($ctrl.submittingGift).toEqual(false) + expect($ctrl.cartService[operation]).toHaveBeenCalledWith(...operationArgs) + expect($ctrl.onStateChange).toHaveBeenCalledWith({ state: 'errorSubmitting' }) + expect($ctrl.errorAlreadyInCart).toEqual(false) + expect($ctrl.errorSavingGeneric).toEqual(false) + expect($ctrl.amountFormatError).toEqual = error.data + }) + + it('should handle an error when saving a bad decimal amount - new error style', () => { + const error = { + data: { + messages: [{ + id: 'field.invalid.decimal.format', + 'debug-message': 'Amount must be a valid decimal number without dollar signs or commas.' + }] + } + } + $ctrl.cartService[operation].mockReturnValue(Observable.throw(error)) + $ctrl.itemConfigForm.$dirty = true + $ctrl.saveGiftToCart() + + expect($ctrl.submittingGift).toEqual(false) + expect($ctrl.cartService[operation]).toHaveBeenCalledWith(...operationArgs) + expect($ctrl.onStateChange).toHaveBeenCalledWith({ state: 'errorSubmitting' }) + expect($ctrl.errorAlreadyInCart).toEqual(false) + expect($ctrl.errorSavingGeneric).toEqual(false) + expect($ctrl.amountFormatError).toEqual = error.data.messages[0]['debug-message'] + }) + it('should clear the cover fee decision when editing the amount of an item in the cart', () => { if (isEdit) { jest.spyOn($ctrl.orderService, 'clearCoverFees')