@paakd/api 0.0.4 → 0.0.6

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 (65) hide show
  1. package/dist/gen/src/proto/files/v1/entities/file_pb.d.ts +199 -0
  2. package/dist/gen/src/proto/files/v1/entities/file_pb.d.ts.map +1 -0
  3. package/dist/gen/src/proto/files/v1/entities/file_pb.js +77 -0
  4. package/dist/gen/src/proto/files/v1/service_pb.d.ts +44 -0
  5. package/dist/gen/src/proto/files/v1/service_pb.d.ts.map +1 -0
  6. package/dist/gen/src/proto/files/v1/service_pb.js +18 -0
  7. package/dist/gen/src/proto/promotions/v1/entities/campaign_pb.d.ts +391 -0
  8. package/dist/gen/src/proto/promotions/v1/entities/campaign_pb.d.ts.map +1 -0
  9. package/dist/gen/src/proto/promotions/v1/entities/campaign_pb.js +140 -0
  10. package/dist/gen/src/proto/promotions/v1/service_pb.d.ts +68 -0
  11. package/dist/gen/src/proto/promotions/v1/service_pb.d.ts.map +1 -0
  12. package/dist/gen/src/proto/promotions/v1/service_pb.js +18 -0
  13. package/dist/gen/src/proto/stocknodes/v1/entities/stocknode_pb.d.ts +508 -0
  14. package/dist/gen/src/proto/stocknodes/v1/entities/stocknode_pb.d.ts.map +1 -0
  15. package/dist/gen/src/proto/stocknodes/v1/entities/stocknode_pb.js +150 -0
  16. package/dist/gen/src/proto/stocknodes/v1/service_pb.d.ts +68 -0
  17. package/dist/gen/src/proto/stocknodes/v1/service_pb.d.ts.map +1 -0
  18. package/dist/gen/src/proto/stocknodes/v1/service_pb.js +18 -0
  19. package/dist/src/index.d.ts +828 -5
  20. package/dist/src/index.d.ts.map +1 -1
  21. package/dist/src/index.js +48 -5
  22. package/dist/src/interceptors.d.ts +1 -1
  23. package/dist/src/interceptors.d.ts.map +1 -1
  24. package/dist/src/interceptors.js +1 -4
  25. package/dist/src/interceptors.spec.js +0 -94
  26. package/package.json +6 -6
  27. package/dist/src/address.d.ts +0 -53
  28. package/dist/src/address.d.ts.map +0 -1
  29. package/dist/src/address.js +0 -233
  30. package/dist/src/address.spec.d.ts +0 -2
  31. package/dist/src/address.spec.d.ts.map +0 -1
  32. package/dist/src/address.spec.js +0 -488
  33. package/dist/src/auth.d.ts +0 -27
  34. package/dist/src/auth.d.ts.map +0 -1
  35. package/dist/src/auth.js +0 -155
  36. package/dist/src/auth.spec.d.ts +0 -2
  37. package/dist/src/auth.spec.d.ts.map +0 -1
  38. package/dist/src/auth.spec.js +0 -582
  39. package/dist/src/compressor/brotli.d.ts +0 -3
  40. package/dist/src/compressor/brotli.d.ts.map +0 -1
  41. package/dist/src/compressor/brotli.js +0 -30
  42. package/dist/src/policies.d.ts +0 -217
  43. package/dist/src/policies.d.ts.map +0 -1
  44. package/dist/src/policies.js +0 -322
  45. package/dist/src/policies.spec.d.ts +0 -2
  46. package/dist/src/policies.spec.d.ts.map +0 -1
  47. package/dist/src/policies.spec.js +0 -463
  48. package/dist/src/products.d.ts +0 -39
  49. package/dist/src/products.d.ts.map +0 -1
  50. package/dist/src/products.js +0 -95
  51. package/dist/src/products.spec.d.ts +0 -2
  52. package/dist/src/products.spec.d.ts.map +0 -1
  53. package/dist/src/products.spec.js +0 -519
  54. package/dist/src/profile.d.ts +0 -62
  55. package/dist/src/profile.d.ts.map +0 -1
  56. package/dist/src/profile.js +0 -151
  57. package/dist/src/profile.spec.d.ts +0 -2
  58. package/dist/src/profile.spec.d.ts.map +0 -1
  59. package/dist/src/profile.spec.js +0 -475
  60. package/dist/src/registration.d.ts +0 -60
  61. package/dist/src/registration.d.ts.map +0 -1
  62. package/dist/src/registration.js +0 -147
  63. package/dist/src/test-utils.d.ts +0 -87
  64. package/dist/src/test-utils.d.ts.map +0 -1
  65. package/dist/src/test-utils.js +0 -132
@@ -1,151 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.getBasicProfile = getBasicProfile;
24
- exports.getProfile = getProfile;
25
- exports.updateProfile = updateProfile;
26
- const connect_1 = require("@connectrpc/connect");
27
- const connect_node_1 = require("@connectrpc/connect-node");
28
- const config_1 = require("@paakd/config");
29
- const service_pb_1 = require("../gen/src/proto/customers/v1/service_pb");
30
- const brotli_1 = require("./compressor/brotli");
31
- const interceptors_1 = require("./interceptors");
32
- function getBasicProfile(_a) {
33
- return __awaiter(this, arguments, void 0, function* ({ body: { customerId, jwt }, headers, }) {
34
- try {
35
- const checkoutConfig = yield (0, config_1.getCheckoutConfig)();
36
- const profileClient = (0, connect_1.createClient)(service_pb_1.CustomerService, (0, connect_node_1.createGrpcTransport)({
37
- baseUrl: checkoutConfig.enterpriseURL,
38
- interceptors: [
39
- (0, interceptors_1.createHeadersInterceptor)(headers),
40
- (0, interceptors_1.createAuthenticationInterceptor)(checkoutConfig),
41
- (0, interceptors_1.createCustomerAuthenticationInterceptor)(jwt),
42
- ],
43
- acceptCompression: [brotli_1.brotliCompression],
44
- sendCompression: brotli_1.brotliCompression,
45
- }));
46
- const value = yield profileClient.basicProfile({
47
- customerId,
48
- });
49
- return {
50
- value,
51
- status: 'success',
52
- };
53
- }
54
- catch (err) {
55
- if (err instanceof connect_1.ConnectError) {
56
- return {
57
- code: err.code,
58
- rawMessage: err.rawMessage,
59
- message: err.rawMessage,
60
- status: 'failed',
61
- };
62
- }
63
- return {
64
- code: connect_1.Code.Internal,
65
- rawMessage: 'An unexpected error occurred while fetching the profile.',
66
- message: 'An unexpected error occurred while fetching the profile.',
67
- status: 'failed',
68
- };
69
- }
70
- });
71
- }
72
- function getProfile(_a) {
73
- return __awaiter(this, arguments, void 0, function* ({ body: { customerId, jwt }, headers, }) {
74
- try {
75
- const checkoutConfig = yield (0, config_1.getCheckoutConfig)();
76
- const profileClient = (0, connect_1.createClient)(service_pb_1.CustomerService, (0, connect_node_1.createGrpcTransport)({
77
- baseUrl: checkoutConfig.enterpriseURL,
78
- interceptors: [
79
- (0, interceptors_1.createHeadersInterceptor)(headers),
80
- (0, interceptors_1.createAuthenticationInterceptor)(checkoutConfig),
81
- (0, interceptors_1.createCustomerAuthenticationInterceptor)(jwt),
82
- ],
83
- acceptCompression: [brotli_1.brotliCompression],
84
- sendCompression: brotli_1.brotliCompression,
85
- }));
86
- const value = yield profileClient.profile({
87
- customerId,
88
- });
89
- return {
90
- value,
91
- status: 'success',
92
- };
93
- }
94
- catch (err) {
95
- if (err instanceof connect_1.ConnectError) {
96
- return {
97
- code: err.code,
98
- rawMessage: err.rawMessage,
99
- message: err.rawMessage,
100
- status: 'failed',
101
- };
102
- }
103
- return {
104
- code: connect_1.Code.Internal,
105
- rawMessage: 'An unexpected error occurred while fetching the profile.',
106
- message: 'An unexpected error occurred while fetching the profile.',
107
- status: 'failed',
108
- };
109
- }
110
- });
111
- }
112
- function updateProfile(_a) {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- var _b = _a.body, { jwt } = _b, prop = __rest(_b, ["jwt"]), { headers } = _a;
115
- const checkoutConfig = yield (0, config_1.getCheckoutConfig)();
116
- const transport = (0, connect_node_1.createGrpcTransport)({
117
- baseUrl: checkoutConfig.enterpriseURL,
118
- interceptors: [
119
- (0, interceptors_1.createHeadersInterceptor)(headers),
120
- (0, interceptors_1.createAuthenticationInterceptor)(checkoutConfig),
121
- (0, interceptors_1.createCustomerAuthenticationInterceptor)(jwt),
122
- ],
123
- acceptCompression: [brotli_1.brotliCompression],
124
- sendCompression: brotli_1.brotliCompression,
125
- });
126
- const profile = (0, connect_1.createClient)(service_pb_1.CustomerService, transport);
127
- try {
128
- const value = yield profile.updateProfile(prop);
129
- return {
130
- value,
131
- status: 'success',
132
- };
133
- }
134
- catch (err) {
135
- if (err instanceof connect_1.ConnectError) {
136
- return {
137
- code: err.code,
138
- rawMessage: err.rawMessage,
139
- message: err.rawMessage,
140
- status: 'failed',
141
- };
142
- }
143
- return {
144
- code: connect_1.Code.Internal,
145
- rawMessage: 'profile update failed',
146
- message: 'An unexpected error occurred during profile update.',
147
- status: 'failed',
148
- };
149
- }
150
- });
151
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=profile.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"profile.spec.d.ts","sourceRoot":"","sources":["../../src/profile.spec.ts"],"names":[],"mappings":""}
@@ -1,475 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const connect_1 = require("@connectrpc/connect");
13
- const connect_node_1 = require("@connectrpc/connect-node");
14
- const config_1 = require("@paakd/config");
15
- const profile_1 = require("./profile");
16
- const interceptors_1 = require("./interceptors");
17
- const test_utils_1 = require("./test-utils");
18
- // Mock dependencies
19
- vi.mock('@connectrpc/connect', () => __awaiter(void 0, void 0, void 0, function* () {
20
- const actual = yield vi.importActual('@connectrpc/connect');
21
- return Object.assign(Object.assign({}, actual), { createClient: vi.fn() });
22
- }));
23
- vi.mock('@connectrpc/connect-node', () => ({
24
- createGrpcTransport: vi.fn(),
25
- }));
26
- vi.mock('@paakd/config', () => ({
27
- getCheckoutConfig: vi.fn(),
28
- }));
29
- vi.mock('./interceptors', () => ({
30
- createAuthenticationInterceptor: vi.fn(),
31
- createCustomerAuthenticationInterceptor: vi.fn(),
32
- createHeadersInterceptor: vi.fn(),
33
- }));
34
- vi.mock('./compressor/brotli', () => ({
35
- brotliCompression: {
36
- name: 'brotli',
37
- compress: vi.fn(),
38
- decompress: vi.fn(),
39
- },
40
- }));
41
- vi.mock('../gen/src/proto/customers/v1/service_pb', () => ({
42
- CustomerService: {},
43
- }));
44
- const mockGetCheckoutConfig = vi.mocked(config_1.getCheckoutConfig);
45
- const mockCreateGrpcTransport = vi.mocked(connect_node_1.createGrpcTransport);
46
- const mockCreateClient = vi.mocked(connect_1.createClient);
47
- const mockCreateAuthenticationInterceptor = vi.mocked(interceptors_1.createAuthenticationInterceptor);
48
- const mockCreateCustomerAuthenticationInterceptor = vi.mocked(interceptors_1.createCustomerAuthenticationInterceptor);
49
- const mockCreateHeadersInterceptor = vi.mocked(interceptors_1.createHeadersInterceptor);
50
- function setupProfileService() {
51
- (0, test_utils_1.clearAllMocks)();
52
- const { config, interceptors, transport } = (0, test_utils_1.setupCommonMocks)();
53
- const client = {
54
- basicProfile: vi.fn(),
55
- profile: vi.fn(),
56
- updateProfile: vi.fn(),
57
- };
58
- mockGetCheckoutConfig.mockResolvedValue(config);
59
- mockCreateGrpcTransport.mockReturnValue(transport);
60
- mockCreateHeadersInterceptor.mockImplementation(() => next => (req) => __awaiter(this, void 0, void 0, function* () {
61
- return yield next(req);
62
- }));
63
- mockCreateAuthenticationInterceptor.mockImplementation(() => next => (req) => __awaiter(this, void 0, void 0, function* () {
64
- return yield next(req);
65
- }));
66
- mockCreateCustomerAuthenticationInterceptor.mockImplementation(() => next => (req) => __awaiter(this, void 0, void 0, function* () {
67
- return yield next(req);
68
- }));
69
- mockCreateClient.mockReturnValue(client);
70
- return {
71
- client,
72
- config,
73
- interceptors,
74
- transport,
75
- };
76
- }
77
- describe('Profile Service', () => {
78
- let consoleSpy;
79
- beforeEach(() => {
80
- consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
81
- });
82
- afterEach(() => {
83
- consoleSpy.mockRestore();
84
- });
85
- describe('getBasicProfile', () => {
86
- it('should successfully fetch basic profile for customer', () => __awaiter(void 0, void 0, void 0, function* () {
87
- const { client } = setupProfileService();
88
- const mockProfile = {
89
- customerId: 'cust-1',
90
- email: 'user@example.com',
91
- firstName: 'John',
92
- lastName: 'Doe',
93
- };
94
- client.basicProfile.mockResolvedValue(mockProfile);
95
- const result = yield (0, profile_1.getBasicProfile)({
96
- body: {
97
- customerId: 'cust-1',
98
- jwt: 'token-123',
99
- },
100
- headers: {},
101
- });
102
- expect(result.status).toBe('success');
103
- expect(result.value).toEqual(mockProfile);
104
- }));
105
- it('should reject request without authentication', () => __awaiter(void 0, void 0, void 0, function* () {
106
- const { client } = setupProfileService();
107
- const error = (0, test_utils_1.createMockConnectError)(16, 'UNAUTHENTICATED', 'Invalid JWT token');
108
- client.basicProfile.mockRejectedValue(error);
109
- const result = yield (0, profile_1.getBasicProfile)({
110
- body: {
111
- customerId: 'cust-1',
112
- jwt: 'invalid-token',
113
- },
114
- headers: {},
115
- });
116
- expect(result.status).toBe('failed');
117
- }));
118
- it('should handle customer not found error', () => __awaiter(void 0, void 0, void 0, function* () {
119
- const { client } = setupProfileService();
120
- const error = (0, test_utils_1.createMockConnectError)(5, 'NOT_FOUND', 'Customer not found');
121
- client.basicProfile.mockRejectedValue(error);
122
- const result = yield (0, profile_1.getBasicProfile)({
123
- body: {
124
- customerId: 'invalid-cust',
125
- jwt: 'token-123',
126
- },
127
- headers: {},
128
- });
129
- expect(result.status).toBe('failed');
130
- expect(result.code).toBe(5);
131
- }));
132
- it('should apply customer authentication interceptor', () => __awaiter(void 0, void 0, void 0, function* () {
133
- const { client } = setupProfileService();
134
- const jwt = 'user-jwt-token';
135
- client.basicProfile.mockResolvedValue({
136
- customerId: 'cust-1',
137
- email: 'user@example.com',
138
- });
139
- yield (0, profile_1.getBasicProfile)({
140
- body: {
141
- customerId: 'cust-1',
142
- jwt,
143
- },
144
- headers: {},
145
- });
146
- expect(mockCreateCustomerAuthenticationInterceptor).toHaveBeenCalledWith(jwt);
147
- }));
148
- });
149
- describe('getProfile', () => {
150
- it('should successfully fetch full profile for customer', () => __awaiter(void 0, void 0, void 0, function* () {
151
- const { client } = setupProfileService();
152
- const mockProfile = {
153
- customerId: 'cust-1',
154
- email: 'user@example.com',
155
- firstName: 'John',
156
- lastName: 'Doe',
157
- phone: '555-1234',
158
- dateOfBirth: '1990-01-01',
159
- preferences: {
160
- newsletter: true,
161
- sms: false,
162
- },
163
- };
164
- client.profile.mockResolvedValue(mockProfile);
165
- const result = yield (0, profile_1.getProfile)({
166
- body: {
167
- customerId: 'cust-1',
168
- jwt: 'token-123',
169
- },
170
- headers: {},
171
- });
172
- expect(result.status).toBe('success');
173
- expect(result.value).toEqual(mockProfile);
174
- }));
175
- it('should reject unauthenticated requests', () => __awaiter(void 0, void 0, void 0, function* () {
176
- const { client } = setupProfileService();
177
- const error = (0, test_utils_1.createMockConnectError)(16, 'UNAUTHENTICATED', 'Session expired');
178
- client.profile.mockRejectedValue(error);
179
- const result = yield (0, profile_1.getProfile)({
180
- body: {
181
- customerId: 'cust-1',
182
- jwt: 'expired-token',
183
- },
184
- headers: {},
185
- });
186
- expect(result.status).toBe('failed');
187
- }));
188
- it('should handle service unavailability', () => __awaiter(void 0, void 0, void 0, function* () {
189
- const { client } = setupProfileService();
190
- const error = (0, test_utils_1.createMockConnectError)(14, 'UNAVAILABLE', 'Service temporarily unavailable');
191
- client.profile.mockRejectedValue(error);
192
- const result = yield (0, profile_1.getProfile)({
193
- body: {
194
- customerId: 'cust-1',
195
- jwt: 'token-123',
196
- },
197
- headers: {},
198
- });
199
- expect(result.status).toBe('failed');
200
- }));
201
- it('should use checkout config for enterprise URL', () => __awaiter(void 0, void 0, void 0, function* () {
202
- const { client, config } = setupProfileService();
203
- client.profile.mockResolvedValue({
204
- customerId: 'cust-1',
205
- email: 'user@example.com',
206
- });
207
- yield (0, profile_1.getProfile)({
208
- body: {
209
- customerId: 'cust-1',
210
- jwt: 'token-123',
211
- },
212
- headers: {},
213
- });
214
- expect(mockCreateGrpcTransport).toHaveBeenCalledWith(expect.objectContaining({
215
- baseUrl: config.enterpriseURL,
216
- }));
217
- }));
218
- });
219
- describe('updateProfile', () => {
220
- it('should successfully update customer profile', () => __awaiter(void 0, void 0, void 0, function* () {
221
- const { client } = setupProfileService();
222
- const updateData = {
223
- body: {
224
- customerId: 'cust-1',
225
- firstName: 'Jane',
226
- lastName: 'Doe',
227
- email: 'jane@example.com',
228
- otherNames: 'Jane Marie',
229
- dateOfBirth: '1990-01-01',
230
- gender: 'female',
231
- phone: '555-1234',
232
- jwt: 'token-123',
233
- },
234
- headers: {},
235
- };
236
- const mockResponse = {
237
- customerId: 'cust-1',
238
- firstName: 'Jane',
239
- lastName: 'Smith',
240
- email: 'user@example.com',
241
- };
242
- client.updateProfile.mockResolvedValue(mockResponse);
243
- const result = yield (0, profile_1.updateProfile)(updateData);
244
- expect(result.status).toBe('success');
245
- expect(result.value).toEqual(mockResponse);
246
- }));
247
- it('should reject invalid profile data', () => __awaiter(void 0, void 0, void 0, function* () {
248
- const { client } = setupProfileService();
249
- const error = (0, test_utils_1.createMockConnectError)(3, 'INVALID_ARGUMENT', 'Invalid profile data');
250
- client.updateProfile.mockRejectedValue(error);
251
- const result = yield (0, profile_1.updateProfile)({
252
- body: {
253
- customerId: 'cust-1',
254
- firstName: '',
255
- jwt: 'token-123',
256
- },
257
- headers: {},
258
- });
259
- expect(result.status).toBe('failed');
260
- }));
261
- it('should reject update without authentication', () => __awaiter(void 0, void 0, void 0, function* () {
262
- const { client } = setupProfileService();
263
- const error = (0, test_utils_1.createMockConnectError)(16, 'UNAUTHENTICATED', 'Invalid JWT');
264
- client.updateProfile.mockRejectedValue(error);
265
- const result = yield (0, profile_1.updateProfile)({
266
- body: {
267
- customerId: 'cust-1',
268
- firstName: 'John',
269
- jwt: 'invalid-token',
270
- },
271
- headers: {},
272
- });
273
- expect(result.status).toBe('failed');
274
- }));
275
- it('should handle permission denied error', () => __awaiter(void 0, void 0, void 0, function* () {
276
- const { client } = setupProfileService();
277
- const error = (0, test_utils_1.createMockConnectError)(7, 'PERMISSION_DENIED', 'Cannot update profile for another customer');
278
- client.updateProfile.mockRejectedValue(error);
279
- const result = yield (0, profile_1.updateProfile)({
280
- body: {
281
- customerId: 'other-cust',
282
- firstName: 'Jane',
283
- jwt: 'user-jwt',
284
- },
285
- headers: {},
286
- });
287
- expect(result.status).toBe('failed');
288
- }));
289
- it('should not include JWT in service request body', () => __awaiter(void 0, void 0, void 0, function* () {
290
- const { client } = setupProfileService();
291
- client.updateProfile.mockResolvedValue({
292
- customerId: 'cust-1',
293
- firstName: 'Jane',
294
- });
295
- const jwt = 'user-jwt-token';
296
- const updateData = {
297
- body: {
298
- customerId: 'cust-1',
299
- firstName: 'Jane',
300
- lastName: 'Doe',
301
- email: 'jane@example.com',
302
- otherNames: 'Jane Marie',
303
- dateOfBirth: '1990-01-01',
304
- gender: 'female',
305
- phone: '555-1234',
306
- jwt,
307
- },
308
- headers: {},
309
- };
310
- yield (0, profile_1.updateProfile)(updateData);
311
- const callArgs = client.updateProfile.mock.calls[0][0];
312
- expect(callArgs).not.toHaveProperty('jwt');
313
- }));
314
- it('should apply three interceptors in correct order', () => __awaiter(void 0, void 0, void 0, function* () {
315
- const { client } = setupProfileService();
316
- client.updateProfile.mockResolvedValue({
317
- customerId: 'cust-1',
318
- firstName: 'Jane',
319
- });
320
- const headers = {
321
- 'x-shop-id': '123',
322
- };
323
- const jwt = 'user-jwt-token';
324
- yield (0, profile_1.updateProfile)({
325
- body: {
326
- customerId: 'cust-1',
327
- firstName: 'Jane',
328
- lastName: 'Doe',
329
- email: 'jane@example.com',
330
- otherNames: 'Jane Marie',
331
- dateOfBirth: '1990-01-01',
332
- gender: 'female',
333
- phone: '555-1234',
334
- jwt,
335
- },
336
- headers,
337
- });
338
- expect(mockCreateHeadersInterceptor).toHaveBeenCalledWith(headers);
339
- expect(mockCreateAuthenticationInterceptor).toHaveBeenCalled();
340
- expect(mockCreateCustomerAuthenticationInterceptor).toHaveBeenCalledWith(jwt);
341
- }));
342
- it('should handle database errors gracefully', () => __awaiter(void 0, void 0, void 0, function* () {
343
- const { client } = setupProfileService();
344
- const error = (0, test_utils_1.createMockConnectError)(13, 'INTERNAL', 'Database error');
345
- client.updateProfile.mockRejectedValue(error);
346
- const result = yield (0, profile_1.updateProfile)({
347
- body: {
348
- customerId: 'cust-1',
349
- firstName: 'Jane',
350
- jwt: 'token-123',
351
- },
352
- headers: {},
353
- });
354
- expect(result.status).toBe('failed');
355
- expect(result.code).toBe(connect_1.Code.Internal);
356
- }));
357
- });
358
- describe('Profile Service - Common Behavior', () => {
359
- it('should load configuration for each request', () => __awaiter(void 0, void 0, void 0, function* () {
360
- const { client } = setupProfileService();
361
- client.basicProfile.mockResolvedValue({
362
- customerId: 'cust-1',
363
- email: 'user@example.com',
364
- });
365
- yield (0, profile_1.getBasicProfile)({
366
- body: {
367
- customerId: 'cust-1',
368
- firstName: 'John',
369
- lastName: 'Doe',
370
- email: 'john@example.com',
371
- otherNames: 'John Michael',
372
- dateOfBirth: '1985-05-15',
373
- gender: 'male',
374
- phone: '555-5678',
375
- jwt: 'token-123',
376
- },
377
- headers: {},
378
- });
379
- expect(mockGetCheckoutConfig).toHaveBeenCalled();
380
- }));
381
- it('should enable compression for all operations', () => __awaiter(void 0, void 0, void 0, function* () {
382
- const { client } = setupProfileService();
383
- client.basicProfile.mockResolvedValue({
384
- customerId: 'cust-1',
385
- email: 'user@example.com',
386
- });
387
- yield (0, profile_1.getBasicProfile)({
388
- body: {
389
- customerId: 'cust-1',
390
- firstName: 'John',
391
- lastName: 'Doe',
392
- email: 'john@example.com',
393
- otherNames: 'John Michael',
394
- dateOfBirth: '1985-05-15',
395
- gender: 'male',
396
- phone: '555-5678',
397
- jwt: 'token-123',
398
- },
399
- headers: {},
400
- });
401
- const transportConfig = mockCreateGrpcTransport.mock.calls[0][0];
402
- expect(transportConfig).toHaveProperty('acceptCompression');
403
- expect(transportConfig).toHaveProperty('sendCompression');
404
- }));
405
- it('should handle concurrent profile operations', () => __awaiter(void 0, void 0, void 0, function* () {
406
- const { client } = setupProfileService();
407
- const mockProfile1 = {
408
- customerId: 'cust-1',
409
- email: 'user1@example.com',
410
- firstName: 'John',
411
- };
412
- const mockProfile2 = {
413
- customerId: 'cust-2',
414
- email: 'user2@example.com',
415
- firstName: 'Jane',
416
- };
417
- client.basicProfile.mockResolvedValueOnce(mockProfile1);
418
- client.basicProfile.mockResolvedValueOnce(mockProfile2);
419
- const results = yield Promise.all([
420
- (0, profile_1.getBasicProfile)({
421
- body: {
422
- customerId: 'cust-1',
423
- jwt: 'token-1',
424
- },
425
- headers: {},
426
- }),
427
- (0, profile_1.getBasicProfile)({
428
- body: {
429
- customerId: 'cust-2',
430
- jwt: 'token-2',
431
- },
432
- headers: {},
433
- }),
434
- ]);
435
- expect(results).toHaveLength(2);
436
- expect(results.every(r => r.status === 'success')).toBe(true);
437
- }));
438
- it('should handle edge cases with special characters in data', () => __awaiter(void 0, void 0, void 0, function* () {
439
- const { client } = setupProfileService();
440
- const mockProfile = {
441
- customerId: 'cust-1',
442
- email: 'user+tag@example.com',
443
- firstName: "O'Connor",
444
- lastName: 'François',
445
- };
446
- client.basicProfile.mockResolvedValue(mockProfile);
447
- const result = yield (0, profile_1.getBasicProfile)({
448
- body: {
449
- customerId: 'cust-1',
450
- jwt: 'token-123',
451
- },
452
- headers: {},
453
- });
454
- expect(result.status).toBe('success');
455
- expect(result.value).toEqual(mockProfile);
456
- }));
457
- it('should handle null or undefined headers gracefully', () => __awaiter(void 0, void 0, void 0, function* () {
458
- const { client } = setupProfileService();
459
- client.basicProfile.mockResolvedValue({
460
- customerId: 'cust-1',
461
- email: 'user@example.com',
462
- });
463
- const result = yield (0, profile_1.getBasicProfile)({
464
- body: {
465
- customerId: 'cust-1',
466
- jwt: 'token-123',
467
- },
468
- headers: {
469
- 'x-header': null,
470
- },
471
- });
472
- expect(result.status).toBe('success');
473
- }));
474
- });
475
- });