@open-mercato/checkout 0.8.1-develop.7296.1.2111d779db → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/dist/modules/checkout/commands/links.js +9 -10
  2. package/dist/modules/checkout/commands/links.js.map +2 -2
  3. package/dist/modules/checkout/commands/shared.js +7 -0
  4. package/dist/modules/checkout/commands/shared.js.map +2 -2
  5. package/dist/modules/checkout/commands/templates.js +10 -11
  6. package/dist/modules/checkout/commands/templates.js.map +2 -2
  7. package/dist/modules/checkout/components/LinkTemplateForm.js +18 -0
  8. package/dist/modules/checkout/components/LinkTemplateForm.js.map +2 -2
  9. package/dist/modules/checkout/widgets/notifications/CheckoutTransactionCompletedRenderer.js +2 -2
  10. package/dist/modules/checkout/widgets/notifications/CheckoutTransactionCompletedRenderer.js.map +2 -2
  11. package/dist/modules/checkout/widgets/notifications/CheckoutTransactionFailedRenderer.js +2 -2
  12. package/dist/modules/checkout/widgets/notifications/CheckoutTransactionFailedRenderer.js.map +2 -2
  13. package/dist/modules/checkout/widgets/notifications/CheckoutUsageLimitReachedRenderer.js +2 -2
  14. package/dist/modules/checkout/widgets/notifications/CheckoutUsageLimitReachedRenderer.js.map +2 -2
  15. package/package.json +6 -7
  16. package/src/modules/checkout/commands/__tests__/undo-scope.test.ts +154 -0
  17. package/src/modules/checkout/commands/links.ts +9 -10
  18. package/src/modules/checkout/commands/shared.ts +7 -0
  19. package/src/modules/checkout/commands/templates.ts +10 -11
  20. package/src/modules/checkout/components/LinkTemplateForm.tsx +27 -0
  21. package/src/modules/checkout/components/__tests__/LinkTemplateForm.unparseableAmount.test.tsx +108 -0
  22. package/src/modules/checkout/widgets/notifications/CheckoutTransactionCompletedRenderer.tsx +2 -2
  23. package/src/modules/checkout/widgets/notifications/CheckoutTransactionFailedRenderer.tsx +2 -2
  24. package/src/modules/checkout/widgets/notifications/CheckoutUsageLimitReachedRenderer.tsx +2 -2
@@ -0,0 +1,108 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ *
4
+ * Regression test for issue #6311.
5
+ *
6
+ * `toSubmittedAmount` returns `null` for text the locale-aware parser cannot read (`abc`, or an
7
+ * ambiguous mixed-separator value such as `10.9,5`). The form used to send that `null` (a
8
+ * price-list row sent `NaN`, which `JSON.stringify` also writes as `null`), and the API's
9
+ * `z.coerce.number()` coerced it to `0` — so the row amount was saved as 0 with no error shown.
10
+ * `collectUnparseableAmountPaths` now finds those fields before submission so the form stops
11
+ * with a localized field error instead.
12
+ */
13
+
14
+ jest.mock('lucide-react', () => {
15
+ const IconStub = () => null
16
+ return new Proxy(
17
+ { __esModule: true },
18
+ { get: (target, prop) => (prop in target ? (target as Record<string | symbol, unknown>)[prop] : IconStub) },
19
+ )
20
+ })
21
+
22
+ jest.mock('next/navigation', () => ({
23
+ useSearchParams: () => new URLSearchParams(),
24
+ }))
25
+
26
+ jest.mock('@open-mercato/ui/backend/detail', () => ({
27
+ RecordNotFoundState: () => null,
28
+ }))
29
+
30
+ jest.mock('@open-mercato/shared/lib/i18n/context', () => ({
31
+ useT: () => (key: string, fallback?: unknown) => (typeof fallback === 'string' ? fallback : key),
32
+ useLocale: () => 'pl-PL',
33
+ }))
34
+
35
+ jest.mock('../CheckoutCurrencySelect', () => ({
36
+ CheckoutCurrencySelect: () => null,
37
+ }))
38
+
39
+ jest.mock('../CustomerFieldsEditor', () => ({
40
+ CustomerFieldsEditor: () => null,
41
+ }))
42
+
43
+ jest.mock('../GatewaySettingsFields', () => ({
44
+ GatewaySettingsFields: () => null,
45
+ }))
46
+
47
+ jest.mock('../LogoUploadField', () => ({
48
+ LogoUploadField: () => null,
49
+ }))
50
+
51
+ import { collectUnparseableAmountPaths } from '../LinkTemplateForm'
52
+
53
+ const TEST_LOCALE = 'pl-PL'
54
+
55
+ function priceListValues(amounts: unknown[]) {
56
+ return {
57
+ pricingMode: 'price_list',
58
+ priceListItems: amounts.map((amount, index) => ({
59
+ id: `item-${index + 1}`,
60
+ description: 'Item',
61
+ amount,
62
+ currencyCode: 'PLN',
63
+ })),
64
+ }
65
+ }
66
+
67
+ describe('LinkTemplateForm unparseable amount input (issue #6311)', () => {
68
+ it.each(['10.9,5', 'abc', '12.5,6'])('flags a price-list row amount of %p instead of letting it save as 0', (raw) => {
69
+ expect(collectUnparseableAmountPaths(priceListValues(['25,99', raw]), TEST_LOCALE)).toEqual([
70
+ 'priceListItems.1.amount',
71
+ ])
72
+ })
73
+
74
+ it('accepts price-list amounts with a single comma or dot decimal separator, numbers and blanks', () => {
75
+ expect(collectUnparseableAmountPaths(priceListValues(['110,70', '110.70', 15, '']), TEST_LOCALE)).toEqual([])
76
+ })
77
+
78
+ it('flags unparseable fixed price and compare-at amounts', () => {
79
+ expect(
80
+ collectUnparseableAmountPaths(
81
+ { pricingMode: 'fixed', fixedPriceAmount: 'abc', fixedPriceOriginalAmount: '10.9,5' },
82
+ TEST_LOCALE,
83
+ ),
84
+ ).toEqual(['fixedPriceAmount', 'fixedPriceOriginalAmount'])
85
+ })
86
+
87
+ it('treats a missing pricing mode as fixed', () => {
88
+ expect(collectUnparseableAmountPaths({ fixedPriceAmount: 'abc' }, TEST_LOCALE)).toEqual(['fixedPriceAmount'])
89
+ })
90
+
91
+ it('flags unparseable custom amount bounds', () => {
92
+ expect(
93
+ collectUnparseableAmountPaths(
94
+ { pricingMode: 'custom_amount', customAmountMin: '1,5', customAmountMax: 'abc' },
95
+ TEST_LOCALE,
96
+ ),
97
+ ).toEqual(['customAmountMax'])
98
+ })
99
+
100
+ it('ignores leftover text in fields the active pricing mode does not submit', () => {
101
+ expect(
102
+ collectUnparseableAmountPaths(
103
+ { pricingMode: 'custom_amount', fixedPriceAmount: 'abc', customAmountMin: '10', customAmountMax: '20' },
104
+ TEST_LOCALE,
105
+ ),
106
+ ).toEqual([])
107
+ })
108
+ })
@@ -26,7 +26,7 @@ export function CheckoutTransactionCompletedRenderer({
26
26
  const viewAction = actions.find((action) => action.id === 'view') ?? actions[0] ?? null
27
27
 
28
28
  const handleView = async () => {
29
- if (!viewAction) {
29
+ if (!viewAction || notification.status === 'actioned') {
30
30
  if (notification.linkHref) router.push(notification.linkHref)
31
31
  return
32
32
  }
@@ -83,7 +83,7 @@ export function CheckoutTransactionCompletedRenderer({
83
83
  variant="default"
84
84
  size="sm"
85
85
  onClick={(e) => { e.stopPropagation(); handleView() }}
86
- disabled={executing || (!viewAction && !notification.linkHref)}
86
+ disabled={executing || (!viewAction && !notification.linkHref) || (notification.status === 'actioned' && !notification.linkHref)}
87
87
  className="gap-1"
88
88
  >
89
89
  <ExternalLink className="h-3 w-3" />
@@ -24,7 +24,7 @@ export function CheckoutTransactionFailedRenderer({
24
24
  const viewAction = actions.find((action) => action.id === 'view') ?? actions[0] ?? null
25
25
 
26
26
  const handleView = async () => {
27
- if (!viewAction) {
27
+ if (!viewAction || notification.status === 'actioned') {
28
28
  if (notification.linkHref) router.push(notification.linkHref)
29
29
  return
30
30
  }
@@ -76,7 +76,7 @@ export function CheckoutTransactionFailedRenderer({
76
76
  variant="default"
77
77
  size="sm"
78
78
  onClick={(e) => { e.stopPropagation(); handleView() }}
79
- disabled={executing || (!viewAction && !notification.linkHref)}
79
+ disabled={executing || (!viewAction && !notification.linkHref) || (notification.status === 'actioned' && !notification.linkHref)}
80
80
  className="gap-1"
81
81
  >
82
82
  <ExternalLink className="h-3 w-3" />
@@ -25,7 +25,7 @@ export function CheckoutUsageLimitReachedRenderer({
25
25
  const viewAction = actions.find((action) => action.id === 'view') ?? actions[0] ?? null
26
26
 
27
27
  const handleView = async () => {
28
- if (!viewAction) {
28
+ if (!viewAction || notification.status === 'actioned') {
29
29
  if (notification.linkHref) router.push(notification.linkHref)
30
30
  return
31
31
  }
@@ -82,7 +82,7 @@ export function CheckoutUsageLimitReachedRenderer({
82
82
  variant="default"
83
83
  size="sm"
84
84
  onClick={(e) => { e.stopPropagation(); handleView() }}
85
- disabled={executing || (!viewAction && !notification.linkHref)}
85
+ disabled={executing || (!viewAction && !notification.linkHref) || (notification.status === 'actioned' && !notification.linkHref)}
86
86
  className="gap-1"
87
87
  >
88
88
  <ExternalLink className="h-3 w-3" />