@reservamos/browser-analytics 1.1.5-alpha.0 → 1.1.6-alpha.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.
- package/CHANGELOG.md +10 -1
- package/README.md +5 -5
- package/dist/browser-analytics.cjs +1 -1
- package/dist/browser-analytics.cjs.map +1 -1
- package/dist/browser-analytics.d.ts +12 -12
- package/dist/browser-analytics.esm.js +5 -5
- package/dist/browser-analytics.esm.js.map +1 -1
- package/dist/browser-analytics.iife.js +1 -1
- package/dist/browser-analytics.iife.js.map +1 -1
- package/package.json +1 -1
- package/src/events/purchaseConfirmation/purchaseConfirmation.test.ts +36 -23
- package/src/events/purchaseConfirmation/purchaseConfirmationSchema.ts +4 -4
package/package.json
CHANGED
|
@@ -10,8 +10,8 @@ vi.mock('@/track', () => ({
|
|
|
10
10
|
describe('purchaseConfirmationSchema', () => {
|
|
11
11
|
it('accepts a valid confirmed payload', () => {
|
|
12
12
|
const payload = {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
'Operation Id': 'MOB-123',
|
|
14
|
+
'Payment Status': 'confirmed',
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
expect(purchaseConfirmationSchema.parse(payload)).toEqual(payload);
|
|
@@ -19,42 +19,53 @@ describe('purchaseConfirmationSchema', () => {
|
|
|
19
19
|
|
|
20
20
|
it('accepts a valid pending_pix payload with optional fields', () => {
|
|
21
21
|
const payload = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
'Operation Id': 'MOB-123',
|
|
23
|
+
'Payment Status': 'pending_pix',
|
|
24
|
+
'Payment Type': 'pix',
|
|
25
|
+
'Total': 199.9,
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
expect(purchaseConfirmationSchema.parse(payload)).toEqual(payload);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
it('rejects a payload missing
|
|
31
|
+
it('rejects a payload missing Operation Id', () => {
|
|
32
32
|
expect(() =>
|
|
33
|
-
purchaseConfirmationSchema.parse({
|
|
33
|
+
purchaseConfirmationSchema.parse({ 'Payment Status': 'confirmed' }),
|
|
34
34
|
).toThrow();
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
it('rejects a payload missing
|
|
37
|
+
it('rejects a payload missing Payment Status', () => {
|
|
38
38
|
expect(() =>
|
|
39
|
-
purchaseConfirmationSchema.parse({
|
|
39
|
+
purchaseConfirmationSchema.parse({ 'Operation Id': 'MOB-123' }),
|
|
40
40
|
).toThrow();
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
it('rejects an invalid
|
|
43
|
+
it('rejects an invalid Payment Status value', () => {
|
|
44
44
|
expect(() =>
|
|
45
45
|
purchaseConfirmationSchema.parse({
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
'Operation Id': 'MOB-123',
|
|
47
|
+
'Payment Status': 'refunded',
|
|
48
48
|
}),
|
|
49
49
|
).toThrow();
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
it('rejects unknown fields', () => {
|
|
53
|
+
expect(() =>
|
|
54
|
+
purchaseConfirmationSchema.parse({
|
|
55
|
+
'Operation Id': 'MOB-123',
|
|
56
|
+
'Payment Status': 'confirmed',
|
|
57
|
+
'extra_field': 'not allowed',
|
|
58
|
+
}),
|
|
59
|
+
).toThrow();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('rejects snake_case property names', () => {
|
|
53
63
|
expect(() =>
|
|
54
64
|
purchaseConfirmationSchema.parse({
|
|
55
65
|
order_number: 'MOB-123',
|
|
56
|
-
payment_status: '
|
|
57
|
-
|
|
66
|
+
payment_status: 'pending_pix',
|
|
67
|
+
payment_type: 'pix',
|
|
68
|
+
total: 199.9,
|
|
58
69
|
}),
|
|
59
70
|
).toThrow();
|
|
60
71
|
});
|
|
@@ -63,12 +74,13 @@ describe('purchaseConfirmationSchema', () => {
|
|
|
63
74
|
describe('trackPurchaseConfirmation', () => {
|
|
64
75
|
it('sends the Purchase Confirmation Viewed event with the given data and meta', async () => {
|
|
65
76
|
trackEventMock.mockClear();
|
|
66
|
-
const trackPurchaseConfirmation = (
|
|
67
|
-
|
|
77
|
+
const trackPurchaseConfirmation = (
|
|
78
|
+
await import('./trackPurchaseConfirmation')
|
|
79
|
+
).default;
|
|
68
80
|
|
|
69
81
|
const eventData = {
|
|
70
|
-
|
|
71
|
-
|
|
82
|
+
'Operation Id': 'MOB-123',
|
|
83
|
+
'Payment Status': 'confirmed' as const,
|
|
72
84
|
};
|
|
73
85
|
const meta = { source: 'checkout' };
|
|
74
86
|
|
|
@@ -83,12 +95,13 @@ describe('trackPurchaseConfirmation', () => {
|
|
|
83
95
|
|
|
84
96
|
it('defaults meta to an empty object when not provided', async () => {
|
|
85
97
|
trackEventMock.mockClear();
|
|
86
|
-
const trackPurchaseConfirmation = (
|
|
87
|
-
|
|
98
|
+
const trackPurchaseConfirmation = (
|
|
99
|
+
await import('./trackPurchaseConfirmation')
|
|
100
|
+
).default;
|
|
88
101
|
|
|
89
102
|
const eventData = {
|
|
90
|
-
|
|
91
|
-
|
|
103
|
+
'Operation Id': 'MOB-456',
|
|
104
|
+
'Payment Status': 'pending_pix' as const,
|
|
92
105
|
};
|
|
93
106
|
|
|
94
107
|
trackPurchaseConfirmation(eventData);
|
|
@@ -2,10 +2,10 @@ import { z } from 'zod';
|
|
|
2
2
|
|
|
3
3
|
const purchaseConfirmationSchema = z
|
|
4
4
|
.object({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
'Operation Id': z.string().min(1, 'Operation Id is required'),
|
|
6
|
+
'Payment Status': z.enum(['confirmed', 'pending_pix']),
|
|
7
|
+
'Payment Type': z.string().optional(),
|
|
8
|
+
'Total': z.number().optional(),
|
|
9
9
|
})
|
|
10
10
|
.strict();
|
|
11
11
|
|