@paakd/api 0.0.1 → 0.0.2

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 (201) hide show
  1. package/buf/validate/validate_pb.ts +5001 -0
  2. package/dist/gen/buf/validate/validate_pb.d.ts +4634 -0
  3. package/dist/gen/buf/validate/validate_pb.d.ts.map +1 -0
  4. package/dist/gen/buf/validate/validate_pb.js +414 -0
  5. package/dist/gen/src/proto/auth/v1/entities/auth_pb.d.ts +268 -0
  6. package/dist/gen/src/proto/auth/v1/entities/auth_pb.d.ts.map +1 -0
  7. package/dist/gen/src/proto/auth/v1/entities/auth_pb.js +120 -0
  8. package/dist/gen/src/proto/auth/v1/entities/policy_pb.d.ts +235 -0
  9. package/dist/gen/src/proto/auth/v1/entities/policy_pb.d.ts.map +1 -0
  10. package/dist/gen/src/proto/auth/v1/entities/policy_pb.js +98 -0
  11. package/dist/gen/src/proto/auth/v1/service_pb.d.ts +117 -0
  12. package/dist/gen/src/proto/auth/v1/service_pb.d.ts.map +1 -0
  13. package/dist/gen/src/proto/auth/v1/service_pb.js +22 -0
  14. package/dist/gen/src/proto/customers/v1/entities/address_pb.d.ts +371 -0
  15. package/dist/gen/src/proto/customers/v1/entities/address_pb.d.ts.map +1 -0
  16. package/dist/gen/src/proto/customers/v1/entities/address_pb.js +84 -0
  17. package/dist/gen/src/proto/customers/v1/entities/profile_pb.d.ts +189 -0
  18. package/dist/gen/src/proto/customers/v1/entities/profile_pb.d.ts.map +1 -0
  19. package/dist/gen/src/proto/customers/v1/entities/profile_pb.js +70 -0
  20. package/dist/gen/src/proto/customers/v1/service_pb.d.ts +85 -0
  21. package/dist/gen/src/proto/customers/v1/service_pb.d.ts.map +1 -0
  22. package/dist/gen/src/proto/customers/v1/service_pb.js +22 -0
  23. package/dist/gen/src/proto/products/v1/entities/category_pb.d.ts +234 -0
  24. package/dist/gen/src/proto/products/v1/entities/category_pb.d.ts.map +1 -0
  25. package/dist/gen/src/proto/products/v1/entities/category_pb.js +84 -0
  26. package/dist/gen/src/proto/products/v1/entities/collection_pb.d.ts +159 -0
  27. package/dist/gen/src/proto/products/v1/entities/collection_pb.d.ts.map +1 -0
  28. package/dist/gen/src/proto/products/v1/entities/collection_pb.js +70 -0
  29. package/dist/gen/src/proto/products/v1/entities/product/create_pb.d.ts +146 -0
  30. package/dist/gen/src/proto/products/v1/entities/product/create_pb.d.ts.map +1 -0
  31. package/dist/gen/src/proto/products/v1/entities/product/create_pb.js +32 -0
  32. package/dist/gen/src/proto/products/v1/entities/product/option_pb.d.ts +50 -0
  33. package/dist/gen/src/proto/products/v1/entities/product/option_pb.d.ts.map +1 -0
  34. package/dist/gen/src/proto/products/v1/entities/product/option_pb.js +32 -0
  35. package/dist/gen/src/proto/products/v1/entities/product/shared_pb.d.ts +1042 -0
  36. package/dist/gen/src/proto/products/v1/entities/product/shared_pb.d.ts.map +1 -0
  37. package/dist/gen/src/proto/products/v1/entities/product/shared_pb.js +258 -0
  38. package/dist/gen/src/proto/products/v1/entities/product/update_pb.d.ts +236 -0
  39. package/dist/gen/src/proto/products/v1/entities/product/update_pb.d.ts.map +1 -0
  40. package/dist/gen/src/proto/products/v1/entities/product/update_pb.js +88 -0
  41. package/dist/gen/src/proto/products/v1/entities/tag_pb.d.ts +175 -0
  42. package/dist/gen/src/proto/products/v1/entities/tag_pb.d.ts.map +1 -0
  43. package/dist/gen/src/proto/products/v1/entities/tag_pb.js +84 -0
  44. package/dist/gen/src/proto/products/v1/entities/taxonomy_pb.d.ts +477 -0
  45. package/dist/gen/src/proto/products/v1/entities/taxonomy_pb.d.ts.map +1 -0
  46. package/dist/gen/src/proto/products/v1/entities/taxonomy_pb.js +235 -0
  47. package/dist/gen/src/proto/products/v1/entities/type_pb.d.ts +158 -0
  48. package/dist/gen/src/proto/products/v1/entities/type_pb.d.ts.map +1 -0
  49. package/dist/gen/src/proto/products/v1/entities/type_pb.js +70 -0
  50. package/dist/gen/src/proto/products/v1/entities/variant_pb.d.ts +489 -0
  51. package/dist/gen/src/proto/products/v1/entities/variant_pb.d.ts.map +1 -0
  52. package/dist/gen/src/proto/products/v1/entities/variant_pb.js +147 -0
  53. package/dist/gen/src/proto/products/v1/service_pb.d.ts +316 -0
  54. package/dist/gen/src/proto/products/v1/service_pb.d.ts.map +1 -0
  55. package/dist/gen/src/proto/products/v1/service_pb.js +36 -0
  56. package/dist/src/address.d.ts +53 -0
  57. package/dist/src/address.d.ts.map +1 -0
  58. package/dist/src/address.js +233 -0
  59. package/dist/src/address.spec.d.ts +2 -0
  60. package/dist/src/address.spec.d.ts.map +1 -0
  61. package/dist/src/address.spec.js +488 -0
  62. package/dist/src/auth.d.ts +27 -0
  63. package/dist/src/auth.d.ts.map +1 -0
  64. package/dist/src/auth.js +155 -0
  65. package/dist/src/auth.spec.d.ts +2 -0
  66. package/dist/src/auth.spec.d.ts.map +1 -0
  67. package/dist/src/auth.spec.js +582 -0
  68. package/dist/src/compressor/brotli.d.ts +3 -0
  69. package/dist/src/compressor/brotli.d.ts.map +1 -0
  70. package/dist/src/compressor/brotli.js +30 -0
  71. package/dist/src/index.d.ts +6 -0
  72. package/dist/src/index.d.ts.map +1 -0
  73. package/dist/src/interceptors.d.ts +16 -0
  74. package/dist/src/interceptors.d.ts.map +1 -0
  75. package/dist/src/interceptors.js +156 -0
  76. package/dist/src/interceptors.spec.d.ts +2 -0
  77. package/dist/src/interceptors.spec.d.ts.map +1 -0
  78. package/dist/src/interceptors.spec.js +1063 -0
  79. package/dist/src/policies.d.ts +217 -0
  80. package/dist/src/policies.d.ts.map +1 -0
  81. package/dist/src/policies.js +322 -0
  82. package/dist/src/policies.spec.d.ts +2 -0
  83. package/dist/src/policies.spec.d.ts.map +1 -0
  84. package/dist/src/policies.spec.js +463 -0
  85. package/dist/src/products.d.ts +39 -0
  86. package/dist/src/products.d.ts.map +1 -0
  87. package/dist/src/products.js +95 -0
  88. package/dist/src/products.spec.d.ts +2 -0
  89. package/dist/src/products.spec.d.ts.map +1 -0
  90. package/dist/src/products.spec.js +519 -0
  91. package/dist/src/profile.d.ts +62 -0
  92. package/dist/src/profile.d.ts.map +1 -0
  93. package/dist/src/profile.js +151 -0
  94. package/dist/src/profile.spec.d.ts +2 -0
  95. package/dist/src/profile.spec.d.ts.map +1 -0
  96. package/dist/src/profile.spec.js +475 -0
  97. package/dist/src/registration.d.ts +60 -0
  98. package/dist/src/registration.d.ts.map +1 -0
  99. package/dist/src/registration.js +147 -0
  100. package/dist/src/test-utils.d.ts +87 -0
  101. package/dist/src/test-utils.d.ts.map +1 -0
  102. package/dist/src/test-utils.js +132 -0
  103. package/gen/buf/validate/validate_pb.ts +4799 -0
  104. package/gen/src/proto/auth/v1/authv1connect/service.connect.go +454 -0
  105. package/gen/src/proto/auth/v1/entities/auth.pb.go +818 -0
  106. package/gen/src/proto/auth/v1/entities/auth_pb.ts +348 -0
  107. package/gen/src/proto/auth/v1/entities/policy.pb.go +727 -0
  108. package/gen/src/proto/auth/v1/entities/policy_pb.ts +306 -0
  109. package/gen/src/proto/auth/v1/service-AuthService_connectquery.ts +70 -0
  110. package/gen/src/proto/auth/v1/service.pb.go +119 -0
  111. package/gen/src/proto/auth/v1/service_pb.ts +152 -0
  112. package/gen/src/proto/customers/v1/customersv1connect/service.connect.go +358 -0
  113. package/gen/src/proto/customers/v1/entities/address.pb.go +1073 -0
  114. package/gen/src/proto/customers/v1/entities/address_pb.ts +478 -0
  115. package/gen/src/proto/customers/v1/entities/profile.pb.go +633 -0
  116. package/gen/src/proto/customers/v1/entities/profile_pb.ts +252 -0
  117. package/gen/src/proto/customers/v1/service-CustomerService_connectquery.ts +50 -0
  118. package/gen/src/proto/customers/v1/service.pb.go +110 -0
  119. package/gen/src/proto/customers/v1/service_pb.ts +121 -0
  120. package/gen/src/proto/files/v1/entities/file.pb.go +669 -0
  121. package/gen/src/proto/files/v1/entities/file_pb.ts +265 -0
  122. package/gen/src/proto/files/v1/filesv1connect/service.connect.go +200 -0
  123. package/gen/src/proto/files/v1/service-FileService_connectquery.ts +25 -0
  124. package/gen/src/proto/files/v1/service.pb.go +85 -0
  125. package/gen/src/proto/files/v1/service_pb.ts +65 -0
  126. package/gen/src/proto/products/v1/entities/category.pb.go +744 -0
  127. package/gen/src/proto/products/v1/entities/category_pb.ts +318 -0
  128. package/gen/src/proto/products/v1/entities/collection.pb.go +528 -0
  129. package/gen/src/proto/products/v1/entities/collection_pb.ts +214 -0
  130. package/gen/src/proto/products/v1/entities/product/create.pb.go +453 -0
  131. package/gen/src/proto/products/v1/entities/product/create_pb.ts +199 -0
  132. package/gen/src/proto/products/v1/entities/product/option.pb.go +206 -0
  133. package/gen/src/proto/products/v1/entities/product/option_pb.ts +74 -0
  134. package/gen/src/proto/products/v1/entities/product/shared.pb.go +2890 -0
  135. package/gen/src/proto/products/v1/entities/product/shared_pb.ts +1317 -0
  136. package/gen/src/proto/products/v1/entities/product/update.pb.go +794 -0
  137. package/gen/src/proto/products/v1/entities/product/update_pb.ts +325 -0
  138. package/gen/src/proto/products/v1/entities/tag.pb.go +610 -0
  139. package/gen/src/proto/products/v1/entities/tag_pb.ts +233 -0
  140. package/gen/src/proto/products/v1/entities/taxonomy.pb.go +1352 -0
  141. package/gen/src/proto/products/v1/entities/taxonomy_pb.ts +606 -0
  142. package/gen/src/proto/products/v1/entities/type.pb.go +553 -0
  143. package/gen/src/proto/products/v1/entities/type_pb.ts +215 -0
  144. package/gen/src/proto/products/v1/entities/variant.pb.go +1474 -0
  145. package/gen/src/proto/products/v1/entities/variant_pb.ts +629 -0
  146. package/gen/src/proto/products/v1/productsv1connect/service.connect.go +1195 -0
  147. package/gen/src/proto/products/v1/service-ProductsService_connectquery.ts +199 -0
  148. package/gen/src/proto/products/v1/service.pb.go +250 -0
  149. package/gen/src/proto/products/v1/service_pb.ts +429 -0
  150. package/gen/src/proto/promotions/v1/entities/campaign.pb.go +1229 -0
  151. package/gen/src/proto/promotions/v1/entities/campaign_pb.ts +511 -0
  152. package/gen/src/proto/promotions/v1/promotionsv1connect/service.connect.go +289 -0
  153. package/gen/src/proto/promotions/v1/service-CampaignService_connectquery.ts +42 -0
  154. package/gen/src/proto/promotions/v1/service.pb.go +98 -0
  155. package/gen/src/proto/promotions/v1/service_pb.ts +95 -0
  156. package/gen/src/proto/stocknodes/v1/entities/stocknode.pb.go +1499 -0
  157. package/gen/src/proto/stocknodes/v1/entities/stocknode_pb.ts +655 -0
  158. package/gen/src/proto/stocknodes/v1/service-StockNodesService_connectquery.ts +41 -0
  159. package/gen/src/proto/stocknodes/v1/service.pb.go +98 -0
  160. package/gen/src/proto/stocknodes/v1/service_pb.ts +95 -0
  161. package/gen/src/proto/stocknodes/v1/stocknodesv1connect/service.connect.go +297 -0
  162. package/package.json +5 -2
  163. package/src/address.spec.ts +0 -662
  164. package/src/address.ts +0 -300
  165. package/src/auth.spec.ts +0 -771
  166. package/src/auth.ts +0 -168
  167. package/src/compressor/brotli.ts +0 -26
  168. package/src/index.ts +0 -5
  169. package/src/interceptors.spec.ts +0 -1343
  170. package/src/interceptors.ts +0 -224
  171. package/src/policies.spec.ts +0 -595
  172. package/src/policies.ts +0 -431
  173. package/src/products.spec.ts +0 -710
  174. package/src/products.ts +0 -112
  175. package/src/profile.spec.ts +0 -626
  176. package/src/profile.ts +0 -169
  177. package/src/proto/auth/v1/entities/auth.proto +0 -140
  178. package/src/proto/auth/v1/entities/policy.proto +0 -57
  179. package/src/proto/auth/v1/service.proto +0 -26
  180. package/src/proto/customers/v1/entities/address.proto +0 -101
  181. package/src/proto/customers/v1/entities/profile.proto +0 -118
  182. package/src/proto/customers/v1/service.proto +0 -36
  183. package/src/proto/files/v1/entities/file.proto +0 -62
  184. package/src/proto/files/v1/service.proto +0 -19
  185. package/src/proto/products/v1/entities/category.proto +0 -98
  186. package/src/proto/products/v1/entities/collection.proto +0 -72
  187. package/src/proto/products/v1/entities/product/create.proto +0 -41
  188. package/src/proto/products/v1/entities/product/option.proto +0 -17
  189. package/src/proto/products/v1/entities/product/shared.proto +0 -255
  190. package/src/proto/products/v1/entities/product/update.proto +0 -66
  191. package/src/proto/products/v1/entities/tag.proto +0 -73
  192. package/src/proto/products/v1/entities/taxonomy.proto +0 -146
  193. package/src/proto/products/v1/entities/type.proto +0 -98
  194. package/src/proto/products/v1/entities/variant.proto +0 -127
  195. package/src/proto/products/v1/service.proto +0 -78
  196. package/src/proto/promotions/v1/entities/campaign.proto +0 -145
  197. package/src/proto/promotions/v1/service.proto +0 -17
  198. package/src/proto/stocknodes/v1/entities/stocknode.proto +0 -167
  199. package/src/proto/stocknodes/v1/service.proto +0 -21
  200. package/src/registration.ts +0 -170
  201. package/src/test-utils.ts +0 -176
@@ -1,662 +0,0 @@
1
- import { Code, createClient } from '@connectrpc/connect'
2
- import { createGrpcTransport } from '@connectrpc/connect-node'
3
- import { getCheckoutConfig } from '@paakd/config'
4
- import {
5
- addAddress,
6
- deleteAddress,
7
- getAddress,
8
- getAddresses,
9
- updateAddress,
10
- } from './address'
11
- import {
12
- createAuthenticationInterceptor,
13
- createCustomerAuthenticationInterceptor,
14
- createHeadersInterceptor,
15
- } from './interceptors'
16
- import {
17
- type BaseTestContext,
18
- type MockServiceClient,
19
- clearAllMocks,
20
- createMockConnectError,
21
- setupCommonMocks,
22
- } from './test-utils'
23
-
24
- // Mock dependencies
25
- vi.mock('@connectrpc/connect', async () => {
26
- const actual = await vi.importActual('@connectrpc/connect')
27
- return {
28
- ...actual,
29
- createClient: vi.fn(),
30
- }
31
- })
32
-
33
- vi.mock('@connectrpc/connect-node', () => ({
34
- createGrpcTransport: vi.fn(),
35
- }))
36
-
37
- vi.mock('@paakd/config', () => ({
38
- getCheckoutConfig: vi.fn(),
39
- }))
40
-
41
- vi.mock('./interceptors', () => ({
42
- createAuthenticationInterceptor: vi.fn(),
43
- createCustomerAuthenticationInterceptor: vi.fn(),
44
- createHeadersInterceptor: vi.fn(),
45
- }))
46
-
47
- vi.mock('./compressor/brotli', () => ({
48
- brotliCompression: {
49
- name: 'brotli',
50
- compress: vi.fn(),
51
- decompress: vi.fn(),
52
- },
53
- }))
54
-
55
- vi.mock('../gen/src/proto/customers/v1/service_pb', () => ({
56
- CustomerService: {},
57
- }))
58
-
59
- const mockGetCheckoutConfig = vi.mocked(getCheckoutConfig)
60
- const mockCreateGrpcTransport = vi.mocked(createGrpcTransport)
61
- const mockCreateClient = vi.mocked(createClient)
62
- const mockCreateHeadersInterceptor = vi.mocked(createHeadersInterceptor)
63
- const mockCreateAuthenticationInterceptor = vi.mocked(
64
- createAuthenticationInterceptor
65
- )
66
- const mockCreateCustomerAuthenticationInterceptor = vi.mocked(
67
- createCustomerAuthenticationInterceptor
68
- )
69
-
70
- /**
71
- * Extended test context for address service
72
- */
73
- interface AddressTestContext extends BaseTestContext {
74
- client: MockServiceClient
75
- }
76
-
77
- function setupAddressService(): AddressTestContext {
78
- clearAllMocks()
79
- const { config, interceptors, transport } = setupCommonMocks()
80
-
81
- const client: MockServiceClient = {
82
- getAddresses: vi.fn(),
83
- getAddress: vi.fn(),
84
- addAddress: vi.fn(),
85
- updateAddress: vi.fn(),
86
- deleteAddress: vi.fn(),
87
- }
88
-
89
- mockGetCheckoutConfig.mockResolvedValue(config)
90
- mockCreateGrpcTransport.mockReturnValue(transport)
91
- mockCreateHeadersInterceptor.mockImplementation(() => next => async req => {
92
- return await next(req)
93
- })
94
- mockCreateAuthenticationInterceptor.mockImplementation(
95
- () => next => async req => {
96
- return await next(req)
97
- }
98
- )
99
- mockCreateCustomerAuthenticationInterceptor.mockImplementation(
100
- () => next => async req => {
101
- return await next(req)
102
- }
103
- )
104
- mockCreateClient.mockReturnValue(client as any)
105
-
106
- return {
107
- client,
108
- config,
109
- interceptors,
110
- transport,
111
- }
112
- }
113
-
114
- describe('Address Service', () => {
115
- let consoleSpy: any
116
-
117
- beforeEach(() => {
118
- consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
119
- })
120
-
121
- afterEach(() => {
122
- consoleSpy.mockRestore()
123
- })
124
-
125
- describe('getAddresses', () => {
126
- it('should successfully fetch all addresses for a customer', async () => {
127
- const { client } = setupAddressService()
128
-
129
- const mockAddresses = [
130
- {
131
- id: 'addr-1',
132
- customerId: 'cust-1',
133
- street: '123 Main St',
134
- city: 'New York',
135
- },
136
- {
137
- id: 'addr-2',
138
- customerId: 'cust-1',
139
- street: '456 Oak Ave',
140
- city: 'Los Angeles',
141
- },
142
- ]
143
-
144
- client.getAddresses.mockResolvedValue({ addresses: mockAddresses })
145
-
146
- const result = await getAddresses({
147
- body: {
148
- customerId: 'cust-1',
149
- jwt: 'token-123',
150
- },
151
- headers: {},
152
- })
153
-
154
- expect(result.status === 'success' && result.value).toBe(mockAddresses)
155
- })
156
-
157
- it('should handle customer not found error', async () => {
158
- const { client } = setupAddressService()
159
-
160
- const error = createMockConnectError(5, 'NOT_FOUND', 'Customer not found')
161
- client.getAddresses.mockRejectedValue(error)
162
-
163
- const result = await getAddresses({
164
- body: {
165
- customerId: 'invalid-customer',
166
- jwt: 'token-123',
167
- },
168
- headers: {},
169
- })
170
-
171
- expect((result as any).status).toBe('failed')
172
- expect((result as any).code).toBe(5)
173
- })
174
-
175
- it('should reject request with invalid JWT', async () => {
176
- const { client } = setupAddressService()
177
-
178
- const error = createMockConnectError(
179
- 16,
180
- 'UNAUTHENTICATED',
181
- 'Invalid JWT token'
182
- )
183
- client.getAddresses.mockRejectedValue(error)
184
-
185
- const result = await getAddresses({
186
- body: {
187
- customerId: 'cust-1',
188
- jwt: 'invalid-token',
189
- },
190
- headers: {},
191
- })
192
-
193
- expect((result as any).status).toBe('failed')
194
- })
195
-
196
- it('should return empty list when customer has no addresses', async () => {
197
- const { client } = setupAddressService()
198
-
199
- client.getAddresses.mockResolvedValue({ addresses: [] })
200
-
201
- const result = await getAddresses({
202
- body: {
203
- customerId: 'cust-1',
204
- jwt: 'token-123',
205
- },
206
- headers: {},
207
- })
208
-
209
- expect((result as any).status).toBe('success')
210
- expect((result as any).value).toEqual([])
211
- })
212
- })
213
-
214
- describe('getAddress', () => {
215
- it('should successfully fetch a single address', async () => {
216
- const { client } = setupAddressService()
217
-
218
- const mockAddress = {
219
- id: 'addr-1',
220
- customerId: 'cust-1',
221
- street: '123 Main St',
222
- city: 'New York',
223
- state: 'NY',
224
- zipCode: '10001',
225
- }
226
-
227
- client.getAddress.mockResolvedValue(mockAddress)
228
-
229
- const result = await getAddress({
230
- body: {
231
- customerId: 'cust-1',
232
- addressId: 'addr-1',
233
- jwt: 'token-123',
234
- },
235
- headers: {},
236
- })
237
-
238
- expect((result as any).status).toBe('success')
239
- expect((result as any).value).toEqual(mockAddress)
240
- })
241
-
242
- it('should return not found when address does not exist', async () => {
243
- const { client } = setupAddressService()
244
-
245
- const error = createMockConnectError(5, 'NOT_FOUND', 'Address not found')
246
- client.getAddress.mockRejectedValue(error)
247
-
248
- const result = await getAddress({
249
- body: {
250
- customerId: 'cust-1',
251
- addressId: 'invalid-addr',
252
- jwt: 'token-123',
253
- },
254
- headers: {},
255
- })
256
-
257
- expect((result as any).status).toBe('failed')
258
- })
259
-
260
- it('should require valid JWT', async () => {
261
- const { client } = setupAddressService()
262
-
263
- const error = createMockConnectError(
264
- 16,
265
- 'UNAUTHENTICATED',
266
- 'Unauthenticated'
267
- )
268
- client.getAddress.mockRejectedValue(error)
269
-
270
- const result = await getAddress({
271
- body: {
272
- customerId: 'cust-1',
273
- addressId: 'addr-1',
274
- jwt: '',
275
- },
276
- headers: {},
277
- })
278
-
279
- expect((result as any).status).toBe('failed')
280
- })
281
- })
282
-
283
- describe('addAddress', () => {
284
- it('should successfully add a new address', async () => {
285
- const { client } = setupAddressService()
286
-
287
- const newAddress = {
288
- customerId: 'cust-1',
289
- firstName: 'Jane',
290
- lastName: 'Doe',
291
- address1: '789 Pine St',
292
- address2: '',
293
- address3: '',
294
- city: 'Chicago',
295
- zipCode: '60601',
296
- country: 'US',
297
- phoneNumber: '555-9999',
298
- }
299
-
300
- const mockResponse = {
301
- address: {
302
- id: 'addr-3',
303
- ...newAddress,
304
- },
305
- }
306
-
307
- client.addAddress.mockResolvedValue(mockResponse)
308
-
309
- const result = await addAddress({
310
- body: {
311
- ...newAddress,
312
- jwt: 'token-123',
313
- } as any,
314
- headers: {},
315
- })
316
-
317
- expect((result as any).status).toBe('success')
318
- expect((result as any).value).toEqual(mockResponse.address)
319
- })
320
-
321
- it('should reject invalid address data', async () => {
322
- const { client } = setupAddressService()
323
-
324
- const error = createMockConnectError(
325
- 3,
326
- 'INVALID_ARGUMENT',
327
- 'Invalid address data'
328
- )
329
- client.addAddress.mockRejectedValue(error)
330
-
331
- const result = await addAddress({
332
- body: {
333
- customerId: 'cust-1',
334
- firstName: 'Jane',
335
- lastName: 'Doe',
336
- address1: '',
337
- address2: '',
338
- address3: '',
339
- city: '',
340
- zipCode: '',
341
- country: 'US',
342
- phoneNumber: '555-1234',
343
- jwt: 'token-123',
344
- } as any,
345
- headers: {},
346
- })
347
-
348
- expect((result as any).status).toBe('failed')
349
- })
350
-
351
- it('should reject requests without authentication', async () => {
352
- const { client } = setupAddressService()
353
-
354
- const error = createMockConnectError(
355
- 16,
356
- 'UNAUTHENTICATED',
357
- 'Authentication required'
358
- )
359
- client.addAddress.mockRejectedValue(error)
360
-
361
- const result = await addAddress({
362
- body: {
363
- customerId: 'cust-1',
364
- firstName: 'Jane',
365
- lastName: 'Doe',
366
- address1: '789 Pine St',
367
- address2: '',
368
- address3: '',
369
- city: 'Chicago',
370
- zipCode: '60601',
371
- country: 'US',
372
- phoneNumber: '555-1234',
373
- jwt: 'invalid-token',
374
- } as any,
375
- headers: {},
376
- })
377
-
378
- expect((result as any).status).toBe('failed')
379
- })
380
- })
381
-
382
- describe('updateAddress', () => {
383
- it('should successfully update an existing address', async () => {
384
- const { client } = setupAddressService()
385
-
386
- const updateData = {
387
- id: 'addr-1',
388
- customerId: 'cust-1',
389
- firstName: 'John',
390
- lastName: 'Doe',
391
- address1: '123 Main St Updated',
392
- address2: '',
393
- address3: '',
394
- city: 'New York',
395
- zipCode: '10001',
396
- country: 'US',
397
- phoneNumber: '555-1234',
398
- }
399
-
400
- const mockResponse = {
401
- address: {
402
- ...updateData,
403
- zipCode: '10001',
404
- },
405
- }
406
-
407
- client.updateAddress.mockResolvedValue(mockResponse)
408
-
409
- const result = await updateAddress({
410
- body: {
411
- ...updateData,
412
- jwt: 'token-123',
413
- } as any,
414
- headers: {},
415
- })
416
-
417
- expect((result as any).status).toBe('success')
418
- expect((result as any).value).toEqual(mockResponse.address)
419
- })
420
-
421
- it('should return not found for non-existent address', async () => {
422
- const { client } = setupAddressService()
423
-
424
- const error = createMockConnectError(5, 'NOT_FOUND', 'Address not found')
425
- client.updateAddress.mockRejectedValue(error)
426
-
427
- const result = await updateAddress({
428
- body: {
429
- id: 'addr-1',
430
- customerId: 'cust-1',
431
- firstName: 'John',
432
- lastName: 'Doe',
433
- addressId: 'addr-1',
434
- street: 'Some St',
435
- address1: 'Some St',
436
- address2: '',
437
- city: 'Some City',
438
- state: 'NY',
439
- zipCode: '10001',
440
- country: 'US',
441
- phoneNumber: '555-1234',
442
- jwt: 'token-123',
443
- } as any,
444
- headers: {},
445
- })
446
-
447
- expect((result as any).status).toBe('failed')
448
- })
449
-
450
- it('should reject updates with invalid data', async () => {
451
- const { client } = setupAddressService()
452
-
453
- const error = createMockConnectError(
454
- 3,
455
- 'INVALID_ARGUMENT',
456
- 'Invalid update data'
457
- )
458
- client.updateAddress.mockRejectedValue(error)
459
-
460
- const result = await updateAddress({
461
- body: {
462
- id: 'addr-1',
463
- customerId: 'cust-1',
464
- street: '',
465
- city: '',
466
- jwt: 'token-123',
467
- } as any,
468
- headers: {},
469
- })
470
-
471
- expect((result as any).status).toBe('failed')
472
- })
473
- })
474
-
475
- describe('deleteAddress', () => {
476
- it('should successfully delete an address', async () => {
477
- const { client } = setupAddressService()
478
-
479
- const mockResponse = {
480
- success: true,
481
- }
482
-
483
- client.deleteAddress.mockResolvedValue(mockResponse)
484
-
485
- const result = await deleteAddress({
486
- body: {
487
- customerId: 'cust-1',
488
- addressId: 'addr-1',
489
- jwt: 'token-123',
490
- },
491
- headers: {},
492
- })
493
-
494
- expect((result as any).status).toBe('success')
495
- expect((result as any).value).toEqual(mockResponse)
496
- })
497
-
498
- it('should return not found when address does not exist', async () => {
499
- const { client } = setupAddressService()
500
-
501
- const error = createMockConnectError(5, 'NOT_FOUND', 'Address not found')
502
- client.deleteAddress.mockRejectedValue(error)
503
-
504
- const result = await deleteAddress({
505
- body: {
506
- customerId: 'cust-1',
507
- addressId: 'invalid-addr',
508
- jwt: 'token-123',
509
- },
510
- headers: {},
511
- })
512
-
513
- expect((result as any).status).toBe('failed')
514
- })
515
-
516
- it('should reject deletion without authentication', async () => {
517
- const { client } = setupAddressService()
518
-
519
- const error = createMockConnectError(
520
- 16,
521
- 'UNAUTHENTICATED',
522
- 'Authentication required'
523
- )
524
- client.deleteAddress.mockRejectedValue(error)
525
-
526
- const result = await deleteAddress({
527
- body: {
528
- customerId: 'cust-1',
529
- addressId: 'addr-1',
530
- jwt: 'invalid-token',
531
- },
532
- headers: {},
533
- })
534
-
535
- expect((result as any).status).toBe('failed')
536
- })
537
-
538
- it('should handle service errors gracefully', async () => {
539
- const { client } = setupAddressService()
540
-
541
- const error = createMockConnectError(
542
- 13,
543
- 'INTERNAL',
544
- 'Internal server error'
545
- )
546
- client.deleteAddress.mockRejectedValue(error)
547
-
548
- const result = await deleteAddress({
549
- body: {
550
- customerId: 'cust-1',
551
- addressId: 'addr-1',
552
- jwt: 'token-123',
553
- },
554
- headers: {},
555
- })
556
-
557
- expect((result as any).status).toBe('failed')
558
- expect((result as any).code).toBe(Code.Internal)
559
- })
560
- })
561
-
562
- describe('Address Service - Common Behavior', () => {
563
- it('should apply all interceptors correctly', async () => {
564
- const { client } = setupAddressService()
565
-
566
- client.getAddresses.mockResolvedValue({ addresses: [] })
567
-
568
- const headers = {
569
- 'x-shop-id': '123',
570
- 'x-locale': 'en-US',
571
- }
572
-
573
- await getAddresses({
574
- body: {
575
- customerId: 'cust-1',
576
- jwt: 'token-123',
577
- },
578
- headers,
579
- })
580
-
581
- expect(mockCreateHeadersInterceptor).toHaveBeenCalledWith(headers)
582
- expect(mockCreateAuthenticationInterceptor).toHaveBeenCalled()
583
- expect(mockCreateCustomerAuthenticationInterceptor).toHaveBeenCalledWith(
584
- 'token-123'
585
- )
586
- })
587
-
588
- it('should load configuration for each request', async () => {
589
- const { client } = setupAddressService()
590
-
591
- client.getAddresses.mockResolvedValue({ addresses: [] })
592
-
593
- await getAddresses({
594
- body: {
595
- customerId: 'cust-1',
596
- jwt: 'token-123',
597
- },
598
- headers: {},
599
- })
600
-
601
- expect(mockGetCheckoutConfig).toHaveBeenCalled()
602
- })
603
-
604
- it('should create transport with compression enabled', async () => {
605
- const { client } = setupAddressService()
606
-
607
- client.getAddresses.mockResolvedValue({ addresses: [] })
608
-
609
- await getAddresses({
610
- body: {
611
- customerId: 'cust-1',
612
- jwt: 'token-123',
613
- },
614
- headers: {},
615
- })
616
-
617
- expect(mockCreateGrpcTransport).toHaveBeenCalledWith(
618
- expect.objectContaining({
619
- acceptCompression: expect.any(Array),
620
- sendCompression: expect.any(Object),
621
- })
622
- )
623
- })
624
-
625
- it('should handle concurrent requests independently', async () => {
626
- const { client } = setupAddressService()
627
-
628
- const mockAddresses = [
629
- { id: 'addr-1', customerId: 'cust-1', street: '123 Main St' },
630
- ]
631
-
632
- client.getAddresses.mockResolvedValue({ addresses: mockAddresses })
633
-
634
- const results = await Promise.all([
635
- getAddresses({
636
- body: {
637
- customerId: 'cust-1',
638
- jwt: 'token-1',
639
- },
640
- headers: {},
641
- }),
642
- getAddresses({
643
- body: {
644
- customerId: 'cust-2',
645
- jwt: 'token-2',
646
- },
647
- headers: {},
648
- }),
649
- getAddresses({
650
- body: {
651
- customerId: 'cust-3',
652
- jwt: 'token-3',
653
- },
654
- headers: {},
655
- }),
656
- ])
657
-
658
- expect(results).toHaveLength(3)
659
- expect(results.every(r => (r as any).status === 'success')).toBe(true)
660
- })
661
- })
662
- })