@akinon/pz-checkout-gift-pack 2.0.7-beta.0 → 2.0.7-rc.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 CHANGED
@@ -1,6 +1,11 @@
1
1
  # @akinon/pz-checkout-gift-pack
2
2
 
3
- ## 2.0.7-beta.0
3
+ ## 2.0.7-rc.0
4
+
5
+ ### Patch Changes
6
+
7
+ - eba125b2: ZERO-4202: Add Jest configuration and initial tests for checkout gift pack functionality
8
+ - 823a4449: ZERO-4193: Upgrade TypeScript to version 5.2.2 across multiple packages
4
9
 
5
10
  ## 2.0.6
6
11
 
package/jest.config.js ADDED
@@ -0,0 +1,7 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} **/
2
+ module.exports = {
3
+ testEnvironment: 'node',
4
+ transform: {
5
+ '^.+.tsx?$': ['ts-jest', {}]
6
+ }
7
+ };
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "@akinon/pz-checkout-gift-pack",
3
- "version": "2.0.7-beta.0",
3
+ "version": "2.0.7-rc.0",
4
4
  "license": "MIT",
5
5
  "main": "src/index.tsx",
6
+ "scripts": {
7
+ "test": "jest",
8
+ "test:watch": "jest --watch"
9
+ },
6
10
  "peerDependencies": {
7
11
  "react": "^18.0.0 || ^19.0.0",
8
12
  "react-dom": "^18.0.0 || ^19.0.0"
9
13
  },
10
14
  "devDependencies": {
15
+ "@types/jest": "^29.5.14",
11
16
  "@types/node": "^18.7.8",
12
17
  "@types/react": "^18.0.17",
13
18
  "@types/react-dom": "^18.0.6",
@@ -0,0 +1,82 @@
1
+ const mockBuildClientRequestUrl = jest.fn(
2
+ (path: string, options?: Record<string, unknown>) => ({
3
+ path,
4
+ options
5
+ })
6
+ );
7
+
8
+ const mockInjectEndpoints = jest.fn();
9
+
10
+ jest.mock('@akinon/next/utils', () => ({
11
+ buildClientRequestUrl: mockBuildClientRequestUrl
12
+ }));
13
+
14
+ jest.mock('@akinon/next/data/client/api', () => ({
15
+ api: {
16
+ injectEndpoints: mockInjectEndpoints
17
+ }
18
+ }));
19
+
20
+ describe('checkout gift pack endpoints', () => {
21
+ beforeEach(() => {
22
+ jest.resetModules();
23
+ jest.clearAllMocks();
24
+
25
+ mockInjectEndpoints.mockImplementation((config) => ({
26
+ endpoints: {},
27
+ useAddGiftPackMutation: jest.fn(),
28
+ useRemoveGiftPackMutation: jest.fn(),
29
+ ...config
30
+ }));
31
+ });
32
+
33
+ it('registers addGiftPack mutation with the expected request contract', async () => {
34
+ await import('../endpoints');
35
+
36
+ const [{ endpoints, overrideExisting }] = mockInjectEndpoints.mock.calls[0];
37
+ const mutation = jest.fn((definition) => definition);
38
+ const definitions = endpoints({ mutation });
39
+ const request = definitions.addGiftPack.query({ note: 'Happy birthday' });
40
+
41
+ expect(overrideExisting).toBe(false);
42
+ expect(mutation).toHaveBeenCalledTimes(2);
43
+ expect(mockBuildClientRequestUrl).toHaveBeenCalledWith(
44
+ '/orders/checkout?page=GiftBoxPage',
45
+ {
46
+ useFormData: true
47
+ }
48
+ );
49
+ expect(request).toEqual({
50
+ url: {
51
+ path: '/orders/checkout?page=GiftBoxPage',
52
+ options: {
53
+ useFormData: true
54
+ }
55
+ },
56
+ method: 'POST',
57
+ body: {
58
+ note: 'Happy birthday'
59
+ }
60
+ });
61
+ });
62
+
63
+ it('registers removeGiftPack mutation with the expected request contract', async () => {
64
+ await import('../endpoints');
65
+
66
+ const [{ endpoints }] = mockInjectEndpoints.mock.calls[0];
67
+ const mutation = jest.fn((definition) => definition);
68
+ const definitions = endpoints({ mutation });
69
+ const request = definitions.removeGiftPack.query();
70
+
71
+ expect(mockBuildClientRequestUrl).toHaveBeenCalledWith(
72
+ '/orders/checkout?page=GiftBoxIndexPage'
73
+ );
74
+ expect(request).toEqual({
75
+ url: {
76
+ path: '/orders/checkout?page=GiftBoxIndexPage',
77
+ options: undefined
78
+ },
79
+ method: 'POST'
80
+ });
81
+ });
82
+ });