@paakd/api 0.0.1
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/dist/src/index.js +21 -0
- package/package.json +59 -0
- package/src/address.spec.ts +662 -0
- package/src/address.ts +300 -0
- package/src/auth.spec.ts +771 -0
- package/src/auth.ts +168 -0
- package/src/compressor/brotli.ts +26 -0
- package/src/index.ts +5 -0
- package/src/interceptors.spec.ts +1343 -0
- package/src/interceptors.ts +224 -0
- package/src/policies.spec.ts +595 -0
- package/src/policies.ts +431 -0
- package/src/products.spec.ts +710 -0
- package/src/products.ts +112 -0
- package/src/profile.spec.ts +626 -0
- package/src/profile.ts +169 -0
- package/src/proto/auth/v1/entities/auth.proto +140 -0
- package/src/proto/auth/v1/entities/policy.proto +57 -0
- package/src/proto/auth/v1/service.proto +26 -0
- package/src/proto/customers/v1/entities/address.proto +101 -0
- package/src/proto/customers/v1/entities/profile.proto +118 -0
- package/src/proto/customers/v1/service.proto +36 -0
- package/src/proto/files/v1/entities/file.proto +62 -0
- package/src/proto/files/v1/service.proto +19 -0
- package/src/proto/products/v1/entities/category.proto +98 -0
- package/src/proto/products/v1/entities/collection.proto +72 -0
- package/src/proto/products/v1/entities/product/create.proto +41 -0
- package/src/proto/products/v1/entities/product/option.proto +17 -0
- package/src/proto/products/v1/entities/product/shared.proto +255 -0
- package/src/proto/products/v1/entities/product/update.proto +66 -0
- package/src/proto/products/v1/entities/tag.proto +73 -0
- package/src/proto/products/v1/entities/taxonomy.proto +146 -0
- package/src/proto/products/v1/entities/type.proto +98 -0
- package/src/proto/products/v1/entities/variant.proto +127 -0
- package/src/proto/products/v1/service.proto +78 -0
- package/src/proto/promotions/v1/entities/campaign.proto +145 -0
- package/src/proto/promotions/v1/service.proto +17 -0
- package/src/proto/stocknodes/v1/entities/stocknode.proto +167 -0
- package/src/proto/stocknodes/v1/service.proto +21 -0
- package/src/registration.ts +170 -0
- package/src/test-utils.ts +176 -0
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
import { Code, createClient } from '@connectrpc/connect'
|
|
2
|
+
import { createGrpcTransport } from '@connectrpc/connect-node'
|
|
3
|
+
import { getCheckoutConfig } from '@paakd/config'
|
|
4
|
+
import {
|
|
5
|
+
getBasicProfile,
|
|
6
|
+
getProfile,
|
|
7
|
+
updateProfile,
|
|
8
|
+
type UpdateProfileProps,
|
|
9
|
+
} from './profile'
|
|
10
|
+
import {
|
|
11
|
+
createAuthenticationInterceptor,
|
|
12
|
+
createCustomerAuthenticationInterceptor,
|
|
13
|
+
createHeadersInterceptor,
|
|
14
|
+
} from './interceptors'
|
|
15
|
+
import {
|
|
16
|
+
type BaseTestContext,
|
|
17
|
+
type MockServiceClient,
|
|
18
|
+
clearAllMocks,
|
|
19
|
+
createMockConnectError,
|
|
20
|
+
setupCommonMocks,
|
|
21
|
+
} from './test-utils'
|
|
22
|
+
|
|
23
|
+
// Mock dependencies
|
|
24
|
+
vi.mock('@connectrpc/connect', async () => {
|
|
25
|
+
const actual = await vi.importActual('@connectrpc/connect')
|
|
26
|
+
return {
|
|
27
|
+
...actual,
|
|
28
|
+
createClient: vi.fn(),
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
vi.mock('@connectrpc/connect-node', () => ({
|
|
33
|
+
createGrpcTransport: vi.fn(),
|
|
34
|
+
}))
|
|
35
|
+
|
|
36
|
+
vi.mock('@paakd/config', () => ({
|
|
37
|
+
getCheckoutConfig: vi.fn(),
|
|
38
|
+
}))
|
|
39
|
+
|
|
40
|
+
vi.mock('./interceptors', () => ({
|
|
41
|
+
createAuthenticationInterceptor: vi.fn(),
|
|
42
|
+
createCustomerAuthenticationInterceptor: vi.fn(),
|
|
43
|
+
createHeadersInterceptor: vi.fn(),
|
|
44
|
+
}))
|
|
45
|
+
|
|
46
|
+
vi.mock('./compressor/brotli', () => ({
|
|
47
|
+
brotliCompression: {
|
|
48
|
+
name: 'brotli',
|
|
49
|
+
compress: vi.fn(),
|
|
50
|
+
decompress: vi.fn(),
|
|
51
|
+
},
|
|
52
|
+
}))
|
|
53
|
+
|
|
54
|
+
vi.mock('../gen/src/proto/customers/v1/service_pb', () => ({
|
|
55
|
+
CustomerService: {},
|
|
56
|
+
}))
|
|
57
|
+
|
|
58
|
+
const mockGetCheckoutConfig = vi.mocked(getCheckoutConfig)
|
|
59
|
+
const mockCreateGrpcTransport = vi.mocked(createGrpcTransport)
|
|
60
|
+
const mockCreateClient = vi.mocked(createClient)
|
|
61
|
+
const mockCreateAuthenticationInterceptor = vi.mocked(
|
|
62
|
+
createAuthenticationInterceptor
|
|
63
|
+
)
|
|
64
|
+
const mockCreateCustomerAuthenticationInterceptor = vi.mocked(
|
|
65
|
+
createCustomerAuthenticationInterceptor
|
|
66
|
+
)
|
|
67
|
+
const mockCreateHeadersInterceptor = vi.mocked(createHeadersInterceptor)
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Extended test context for profile service
|
|
71
|
+
*/
|
|
72
|
+
interface ProfileTestContext extends BaseTestContext {
|
|
73
|
+
client: MockServiceClient
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function setupProfileService(): ProfileTestContext {
|
|
77
|
+
clearAllMocks()
|
|
78
|
+
const { config, interceptors, transport } = setupCommonMocks()
|
|
79
|
+
|
|
80
|
+
const client: MockServiceClient = {
|
|
81
|
+
basicProfile: vi.fn(),
|
|
82
|
+
profile: vi.fn(),
|
|
83
|
+
updateProfile: vi.fn(),
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
mockGetCheckoutConfig.mockResolvedValue(config)
|
|
87
|
+
mockCreateGrpcTransport.mockReturnValue(transport)
|
|
88
|
+
mockCreateHeadersInterceptor.mockImplementation(() => next => async req => {
|
|
89
|
+
return await next(req)
|
|
90
|
+
})
|
|
91
|
+
mockCreateAuthenticationInterceptor.mockImplementation(
|
|
92
|
+
() => next => async req => {
|
|
93
|
+
return await next(req)
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
mockCreateCustomerAuthenticationInterceptor.mockImplementation(
|
|
97
|
+
() => next => async req => {
|
|
98
|
+
return await next(req)
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
mockCreateClient.mockReturnValue(client as any)
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
client,
|
|
105
|
+
config,
|
|
106
|
+
interceptors,
|
|
107
|
+
transport,
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
describe('Profile Service', () => {
|
|
112
|
+
let consoleSpy: any
|
|
113
|
+
|
|
114
|
+
beforeEach(() => {
|
|
115
|
+
consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
afterEach(() => {
|
|
119
|
+
consoleSpy.mockRestore()
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
describe('getBasicProfile', () => {
|
|
123
|
+
it('should successfully fetch basic profile for customer', async () => {
|
|
124
|
+
const { client } = setupProfileService()
|
|
125
|
+
|
|
126
|
+
const mockProfile = {
|
|
127
|
+
customerId: 'cust-1',
|
|
128
|
+
email: 'user@example.com',
|
|
129
|
+
firstName: 'John',
|
|
130
|
+
lastName: 'Doe',
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
client.basicProfile.mockResolvedValue(mockProfile)
|
|
134
|
+
|
|
135
|
+
const result = await getBasicProfile({
|
|
136
|
+
body: {
|
|
137
|
+
customerId: 'cust-1',
|
|
138
|
+
jwt: 'token-123',
|
|
139
|
+
},
|
|
140
|
+
headers: {},
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
expect((result as any).status).toBe('success')
|
|
144
|
+
expect((result as any).value).toEqual(mockProfile)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('should reject request without authentication', async () => {
|
|
148
|
+
const { client } = setupProfileService()
|
|
149
|
+
|
|
150
|
+
const error = createMockConnectError(
|
|
151
|
+
16,
|
|
152
|
+
'UNAUTHENTICATED',
|
|
153
|
+
'Invalid JWT token'
|
|
154
|
+
)
|
|
155
|
+
client.basicProfile.mockRejectedValue(error)
|
|
156
|
+
|
|
157
|
+
const result = await getBasicProfile({
|
|
158
|
+
body: {
|
|
159
|
+
customerId: 'cust-1',
|
|
160
|
+
jwt: 'invalid-token',
|
|
161
|
+
},
|
|
162
|
+
headers: {},
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
expect((result as any).status).toBe('failed')
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('should handle customer not found error', async () => {
|
|
169
|
+
const { client } = setupProfileService()
|
|
170
|
+
|
|
171
|
+
const error = createMockConnectError(5, 'NOT_FOUND', 'Customer not found')
|
|
172
|
+
client.basicProfile.mockRejectedValue(error)
|
|
173
|
+
|
|
174
|
+
const result = await getBasicProfile({
|
|
175
|
+
body: {
|
|
176
|
+
customerId: 'invalid-cust',
|
|
177
|
+
jwt: 'token-123',
|
|
178
|
+
},
|
|
179
|
+
headers: {},
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
expect((result as any).status).toBe('failed')
|
|
183
|
+
expect((result as any).code).toBe(5)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it('should apply customer authentication interceptor', async () => {
|
|
187
|
+
const { client } = setupProfileService()
|
|
188
|
+
const jwt = 'user-jwt-token'
|
|
189
|
+
|
|
190
|
+
client.basicProfile.mockResolvedValue({
|
|
191
|
+
customerId: 'cust-1',
|
|
192
|
+
email: 'user@example.com',
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
await getBasicProfile({
|
|
196
|
+
body: {
|
|
197
|
+
customerId: 'cust-1',
|
|
198
|
+
jwt,
|
|
199
|
+
},
|
|
200
|
+
headers: {},
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
expect(mockCreateCustomerAuthenticationInterceptor).toHaveBeenCalledWith(
|
|
204
|
+
jwt
|
|
205
|
+
)
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
describe('getProfile', () => {
|
|
210
|
+
it('should successfully fetch full profile for customer', async () => {
|
|
211
|
+
const { client } = setupProfileService()
|
|
212
|
+
|
|
213
|
+
const mockProfile = {
|
|
214
|
+
customerId: 'cust-1',
|
|
215
|
+
email: 'user@example.com',
|
|
216
|
+
firstName: 'John',
|
|
217
|
+
lastName: 'Doe',
|
|
218
|
+
phone: '555-1234',
|
|
219
|
+
dateOfBirth: '1990-01-01',
|
|
220
|
+
preferences: {
|
|
221
|
+
newsletter: true,
|
|
222
|
+
sms: false,
|
|
223
|
+
},
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
client.profile.mockResolvedValue(mockProfile)
|
|
227
|
+
|
|
228
|
+
const result = await getProfile({
|
|
229
|
+
body: {
|
|
230
|
+
customerId: 'cust-1',
|
|
231
|
+
jwt: 'token-123',
|
|
232
|
+
},
|
|
233
|
+
headers: {},
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
expect((result as any).status).toBe('success')
|
|
237
|
+
expect((result as any).value).toEqual(mockProfile)
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
it('should reject unauthenticated requests', async () => {
|
|
241
|
+
const { client } = setupProfileService()
|
|
242
|
+
|
|
243
|
+
const error = createMockConnectError(
|
|
244
|
+
16,
|
|
245
|
+
'UNAUTHENTICATED',
|
|
246
|
+
'Session expired'
|
|
247
|
+
)
|
|
248
|
+
client.profile.mockRejectedValue(error)
|
|
249
|
+
|
|
250
|
+
const result = await getProfile({
|
|
251
|
+
body: {
|
|
252
|
+
customerId: 'cust-1',
|
|
253
|
+
jwt: 'expired-token',
|
|
254
|
+
},
|
|
255
|
+
headers: {},
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
expect((result as any).status).toBe('failed')
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
it('should handle service unavailability', async () => {
|
|
262
|
+
const { client } = setupProfileService()
|
|
263
|
+
|
|
264
|
+
const error = createMockConnectError(
|
|
265
|
+
14,
|
|
266
|
+
'UNAVAILABLE',
|
|
267
|
+
'Service temporarily unavailable'
|
|
268
|
+
)
|
|
269
|
+
client.profile.mockRejectedValue(error)
|
|
270
|
+
|
|
271
|
+
const result = await getProfile({
|
|
272
|
+
body: {
|
|
273
|
+
customerId: 'cust-1',
|
|
274
|
+
jwt: 'token-123',
|
|
275
|
+
},
|
|
276
|
+
headers: {},
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
expect((result as any).status).toBe('failed')
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
it('should use checkout config for enterprise URL', async () => {
|
|
283
|
+
const { client, config } = setupProfileService()
|
|
284
|
+
|
|
285
|
+
client.profile.mockResolvedValue({
|
|
286
|
+
customerId: 'cust-1',
|
|
287
|
+
email: 'user@example.com',
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
await getProfile({
|
|
291
|
+
body: {
|
|
292
|
+
customerId: 'cust-1',
|
|
293
|
+
jwt: 'token-123',
|
|
294
|
+
},
|
|
295
|
+
headers: {},
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
expect(mockCreateGrpcTransport).toHaveBeenCalledWith(
|
|
299
|
+
expect.objectContaining({
|
|
300
|
+
baseUrl: config.enterpriseURL,
|
|
301
|
+
})
|
|
302
|
+
)
|
|
303
|
+
})
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
describe('updateProfile', () => {
|
|
307
|
+
it('should successfully update customer profile', async () => {
|
|
308
|
+
const { client } = setupProfileService()
|
|
309
|
+
|
|
310
|
+
const updateData: UpdateProfileProps = {
|
|
311
|
+
body: {
|
|
312
|
+
customerId: 'cust-1',
|
|
313
|
+
firstName: 'Jane',
|
|
314
|
+
lastName: 'Doe',
|
|
315
|
+
email: 'jane@example.com',
|
|
316
|
+
otherNames: 'Jane Marie',
|
|
317
|
+
dateOfBirth: '1990-01-01',
|
|
318
|
+
gender: 'female',
|
|
319
|
+
phone: '555-1234',
|
|
320
|
+
jwt: 'token-123',
|
|
321
|
+
} as any,
|
|
322
|
+
headers: {},
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const mockResponse = {
|
|
326
|
+
customerId: 'cust-1',
|
|
327
|
+
firstName: 'Jane',
|
|
328
|
+
lastName: 'Smith',
|
|
329
|
+
email: 'user@example.com',
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
client.updateProfile.mockResolvedValue(mockResponse)
|
|
333
|
+
|
|
334
|
+
const result = await updateProfile(updateData)
|
|
335
|
+
|
|
336
|
+
expect((result as any).status).toBe('success')
|
|
337
|
+
expect((result as any).value).toEqual(mockResponse)
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
it('should reject invalid profile data', async () => {
|
|
341
|
+
const { client } = setupProfileService()
|
|
342
|
+
|
|
343
|
+
const error = createMockConnectError(
|
|
344
|
+
3,
|
|
345
|
+
'INVALID_ARGUMENT',
|
|
346
|
+
'Invalid profile data'
|
|
347
|
+
)
|
|
348
|
+
client.updateProfile.mockRejectedValue(error)
|
|
349
|
+
|
|
350
|
+
const result = await updateProfile({
|
|
351
|
+
body: {
|
|
352
|
+
customerId: 'cust-1',
|
|
353
|
+
firstName: '',
|
|
354
|
+
jwt: 'token-123',
|
|
355
|
+
} as any,
|
|
356
|
+
headers: {},
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
expect((result as any).status).toBe('failed')
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
it('should reject update without authentication', async () => {
|
|
363
|
+
const { client } = setupProfileService()
|
|
364
|
+
|
|
365
|
+
const error = createMockConnectError(16, 'UNAUTHENTICATED', 'Invalid JWT')
|
|
366
|
+
client.updateProfile.mockRejectedValue(error)
|
|
367
|
+
|
|
368
|
+
const result = await updateProfile({
|
|
369
|
+
body: {
|
|
370
|
+
customerId: 'cust-1',
|
|
371
|
+
firstName: 'John',
|
|
372
|
+
jwt: 'invalid-token',
|
|
373
|
+
} as any,
|
|
374
|
+
headers: {},
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
expect((result as any).status).toBe('failed')
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
it('should handle permission denied error', async () => {
|
|
381
|
+
const { client } = setupProfileService()
|
|
382
|
+
|
|
383
|
+
const error = createMockConnectError(
|
|
384
|
+
7,
|
|
385
|
+
'PERMISSION_DENIED',
|
|
386
|
+
'Cannot update profile for another customer'
|
|
387
|
+
)
|
|
388
|
+
client.updateProfile.mockRejectedValue(error)
|
|
389
|
+
|
|
390
|
+
const result = await updateProfile({
|
|
391
|
+
body: {
|
|
392
|
+
customerId: 'other-cust',
|
|
393
|
+
firstName: 'Jane',
|
|
394
|
+
jwt: 'user-jwt',
|
|
395
|
+
} as any,
|
|
396
|
+
headers: {},
|
|
397
|
+
})
|
|
398
|
+
|
|
399
|
+
expect((result as any).status).toBe('failed')
|
|
400
|
+
})
|
|
401
|
+
|
|
402
|
+
it('should not include JWT in service request body', async () => {
|
|
403
|
+
const { client } = setupProfileService()
|
|
404
|
+
|
|
405
|
+
client.updateProfile.mockResolvedValue({
|
|
406
|
+
customerId: 'cust-1',
|
|
407
|
+
firstName: 'Jane',
|
|
408
|
+
})
|
|
409
|
+
|
|
410
|
+
const jwt = 'user-jwt-token'
|
|
411
|
+
const updateData: UpdateProfileProps = {
|
|
412
|
+
body: {
|
|
413
|
+
customerId: 'cust-1',
|
|
414
|
+
firstName: 'Jane',
|
|
415
|
+
lastName: 'Doe',
|
|
416
|
+
email: 'jane@example.com',
|
|
417
|
+
otherNames: 'Jane Marie',
|
|
418
|
+
dateOfBirth: '1990-01-01',
|
|
419
|
+
gender: 'female',
|
|
420
|
+
phone: '555-1234',
|
|
421
|
+
jwt,
|
|
422
|
+
} as any,
|
|
423
|
+
headers: {},
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
await updateProfile(updateData)
|
|
427
|
+
|
|
428
|
+
const callArgs = client.updateProfile.mock.calls[0][0]
|
|
429
|
+
expect(callArgs).not.toHaveProperty('jwt')
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
it('should apply three interceptors in correct order', async () => {
|
|
433
|
+
const { client } = setupProfileService()
|
|
434
|
+
|
|
435
|
+
client.updateProfile.mockResolvedValue({
|
|
436
|
+
customerId: 'cust-1',
|
|
437
|
+
firstName: 'Jane',
|
|
438
|
+
})
|
|
439
|
+
|
|
440
|
+
const headers = {
|
|
441
|
+
'x-shop-id': '123',
|
|
442
|
+
}
|
|
443
|
+
const jwt = 'user-jwt-token'
|
|
444
|
+
|
|
445
|
+
await updateProfile({
|
|
446
|
+
body: {
|
|
447
|
+
customerId: 'cust-1',
|
|
448
|
+
firstName: 'Jane',
|
|
449
|
+
lastName: 'Doe',
|
|
450
|
+
email: 'jane@example.com',
|
|
451
|
+
otherNames: 'Jane Marie',
|
|
452
|
+
dateOfBirth: '1990-01-01',
|
|
453
|
+
gender: 'female',
|
|
454
|
+
phone: '555-1234',
|
|
455
|
+
jwt,
|
|
456
|
+
} as any,
|
|
457
|
+
headers,
|
|
458
|
+
})
|
|
459
|
+
|
|
460
|
+
expect(mockCreateHeadersInterceptor).toHaveBeenCalledWith(headers)
|
|
461
|
+
expect(mockCreateAuthenticationInterceptor).toHaveBeenCalled()
|
|
462
|
+
expect(mockCreateCustomerAuthenticationInterceptor).toHaveBeenCalledWith(
|
|
463
|
+
jwt
|
|
464
|
+
)
|
|
465
|
+
})
|
|
466
|
+
|
|
467
|
+
it('should handle database errors gracefully', async () => {
|
|
468
|
+
const { client } = setupProfileService()
|
|
469
|
+
|
|
470
|
+
const error = createMockConnectError(13, 'INTERNAL', 'Database error')
|
|
471
|
+
client.updateProfile.mockRejectedValue(error)
|
|
472
|
+
|
|
473
|
+
const result = await updateProfile({
|
|
474
|
+
body: {
|
|
475
|
+
customerId: 'cust-1',
|
|
476
|
+
firstName: 'Jane',
|
|
477
|
+
jwt: 'token-123',
|
|
478
|
+
} as any,
|
|
479
|
+
headers: {},
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
expect((result as any).status).toBe('failed')
|
|
483
|
+
expect((result as any).code).toBe(Code.Internal)
|
|
484
|
+
})
|
|
485
|
+
})
|
|
486
|
+
|
|
487
|
+
describe('Profile Service - Common Behavior', () => {
|
|
488
|
+
it('should load configuration for each request', async () => {
|
|
489
|
+
const { client } = setupProfileService()
|
|
490
|
+
|
|
491
|
+
client.basicProfile.mockResolvedValue({
|
|
492
|
+
customerId: 'cust-1',
|
|
493
|
+
email: 'user@example.com',
|
|
494
|
+
})
|
|
495
|
+
|
|
496
|
+
await getBasicProfile({
|
|
497
|
+
body: {
|
|
498
|
+
customerId: 'cust-1',
|
|
499
|
+
firstName: 'John',
|
|
500
|
+
lastName: 'Doe',
|
|
501
|
+
email: 'john@example.com',
|
|
502
|
+
otherNames: 'John Michael',
|
|
503
|
+
dateOfBirth: '1985-05-15',
|
|
504
|
+
gender: 'male',
|
|
505
|
+
phone: '555-5678',
|
|
506
|
+
jwt: 'token-123',
|
|
507
|
+
} as any,
|
|
508
|
+
headers: {},
|
|
509
|
+
})
|
|
510
|
+
|
|
511
|
+
expect(mockGetCheckoutConfig).toHaveBeenCalled()
|
|
512
|
+
})
|
|
513
|
+
|
|
514
|
+
it('should enable compression for all operations', async () => {
|
|
515
|
+
const { client } = setupProfileService()
|
|
516
|
+
|
|
517
|
+
client.basicProfile.mockResolvedValue({
|
|
518
|
+
customerId: 'cust-1',
|
|
519
|
+
email: 'user@example.com',
|
|
520
|
+
})
|
|
521
|
+
|
|
522
|
+
await getBasicProfile({
|
|
523
|
+
body: {
|
|
524
|
+
customerId: 'cust-1',
|
|
525
|
+
firstName: 'John',
|
|
526
|
+
lastName: 'Doe',
|
|
527
|
+
email: 'john@example.com',
|
|
528
|
+
otherNames: 'John Michael',
|
|
529
|
+
dateOfBirth: '1985-05-15',
|
|
530
|
+
gender: 'male',
|
|
531
|
+
phone: '555-5678',
|
|
532
|
+
jwt: 'token-123',
|
|
533
|
+
} as any,
|
|
534
|
+
headers: {},
|
|
535
|
+
})
|
|
536
|
+
|
|
537
|
+
const transportConfig = (mockCreateGrpcTransport as any).mock.calls[0][0]
|
|
538
|
+
expect(transportConfig).toHaveProperty('acceptCompression')
|
|
539
|
+
expect(transportConfig).toHaveProperty('sendCompression')
|
|
540
|
+
})
|
|
541
|
+
|
|
542
|
+
it('should handle concurrent profile operations', async () => {
|
|
543
|
+
const { client } = setupProfileService()
|
|
544
|
+
|
|
545
|
+
const mockProfile1 = {
|
|
546
|
+
customerId: 'cust-1',
|
|
547
|
+
email: 'user1@example.com',
|
|
548
|
+
firstName: 'John',
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const mockProfile2 = {
|
|
552
|
+
customerId: 'cust-2',
|
|
553
|
+
email: 'user2@example.com',
|
|
554
|
+
firstName: 'Jane',
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
client.basicProfile.mockResolvedValueOnce(mockProfile1)
|
|
558
|
+
client.basicProfile.mockResolvedValueOnce(mockProfile2)
|
|
559
|
+
|
|
560
|
+
const results = await Promise.all([
|
|
561
|
+
getBasicProfile({
|
|
562
|
+
body: {
|
|
563
|
+
customerId: 'cust-1',
|
|
564
|
+
jwt: 'token-1',
|
|
565
|
+
},
|
|
566
|
+
headers: {},
|
|
567
|
+
}),
|
|
568
|
+
getBasicProfile({
|
|
569
|
+
body: {
|
|
570
|
+
customerId: 'cust-2',
|
|
571
|
+
jwt: 'token-2',
|
|
572
|
+
},
|
|
573
|
+
headers: {},
|
|
574
|
+
}),
|
|
575
|
+
])
|
|
576
|
+
|
|
577
|
+
expect(results).toHaveLength(2)
|
|
578
|
+
expect(results.every(r => (r as any).status === 'success')).toBe(true)
|
|
579
|
+
})
|
|
580
|
+
|
|
581
|
+
it('should handle edge cases with special characters in data', async () => {
|
|
582
|
+
const { client } = setupProfileService()
|
|
583
|
+
|
|
584
|
+
const mockProfile = {
|
|
585
|
+
customerId: 'cust-1',
|
|
586
|
+
email: 'user+tag@example.com',
|
|
587
|
+
firstName: "O'Connor",
|
|
588
|
+
lastName: 'François',
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
client.basicProfile.mockResolvedValue(mockProfile)
|
|
592
|
+
|
|
593
|
+
const result = await getBasicProfile({
|
|
594
|
+
body: {
|
|
595
|
+
customerId: 'cust-1',
|
|
596
|
+
jwt: 'token-123',
|
|
597
|
+
},
|
|
598
|
+
headers: {},
|
|
599
|
+
})
|
|
600
|
+
|
|
601
|
+
expect((result as any).status).toBe('success')
|
|
602
|
+
expect((result as any).value).toEqual(mockProfile)
|
|
603
|
+
})
|
|
604
|
+
|
|
605
|
+
it('should handle null or undefined headers gracefully', async () => {
|
|
606
|
+
const { client } = setupProfileService()
|
|
607
|
+
|
|
608
|
+
client.basicProfile.mockResolvedValue({
|
|
609
|
+
customerId: 'cust-1',
|
|
610
|
+
email: 'user@example.com',
|
|
611
|
+
})
|
|
612
|
+
|
|
613
|
+
const result = await getBasicProfile({
|
|
614
|
+
body: {
|
|
615
|
+
customerId: 'cust-1',
|
|
616
|
+
jwt: 'token-123',
|
|
617
|
+
},
|
|
618
|
+
headers: {
|
|
619
|
+
'x-header': null,
|
|
620
|
+
},
|
|
621
|
+
})
|
|
622
|
+
|
|
623
|
+
expect((result as any).status).toBe('success')
|
|
624
|
+
})
|
|
625
|
+
})
|
|
626
|
+
})
|