@vulog/aima-user 1.2.37 → 1.2.38
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/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -2
- package/package.json +5 -5
- package/src/createBusinessProfile.test.ts +258 -0
- package/src/createBusinessProfile.ts +3 -3
package/dist/index.cjs
CHANGED
|
@@ -60,8 +60,8 @@ const createBusinessProfile = async (client, userId, businessId, data) => {
|
|
|
60
60
|
businessId,
|
|
61
61
|
data
|
|
62
62
|
});
|
|
63
|
-
if (!result.success) throw new TypeError("Invalid
|
|
64
|
-
return client.post(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${businessId}/user/${userId}`, result.data).then(({ data: p }) => p);
|
|
63
|
+
if (!result.success) throw new TypeError("Invalid arguments", { cause: result.error.issues });
|
|
64
|
+
return client.post(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${businessId}/user/${userId}`, result.data.data).then(({ data: p }) => p);
|
|
65
65
|
};
|
|
66
66
|
//#endregion
|
|
67
67
|
//#region src/createUser.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -195,7 +195,7 @@ type CreateBusinessProfile = {
|
|
|
195
195
|
emailConsent: boolean;
|
|
196
196
|
email: string;
|
|
197
197
|
requestId: string;
|
|
198
|
-
costCenterId
|
|
198
|
+
costCenterId?: string | null;
|
|
199
199
|
};
|
|
200
200
|
declare const createBusinessProfile: (client: Client, userId: string, businessId: string, data: CreateBusinessProfile) => Promise<UserProfile>;
|
|
201
201
|
//#endregion
|
package/dist/index.d.mts
CHANGED
|
@@ -195,7 +195,7 @@ type CreateBusinessProfile = {
|
|
|
195
195
|
emailConsent: boolean;
|
|
196
196
|
email: string;
|
|
197
197
|
requestId: string;
|
|
198
|
-
costCenterId
|
|
198
|
+
costCenterId?: string | null;
|
|
199
199
|
};
|
|
200
200
|
declare const createBusinessProfile: (client: Client, userId: string, businessId: string, data: CreateBusinessProfile) => Promise<UserProfile>;
|
|
201
201
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -59,8 +59,8 @@ const createBusinessProfile = async (client, userId, businessId, data) => {
|
|
|
59
59
|
businessId,
|
|
60
60
|
data
|
|
61
61
|
});
|
|
62
|
-
if (!result.success) throw new TypeError("Invalid
|
|
63
|
-
return client.post(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${businessId}/user/${userId}`, result.data).then(({ data: p }) => p);
|
|
62
|
+
if (!result.success) throw new TypeError("Invalid arguments", { cause: result.error.issues });
|
|
63
|
+
return client.post(`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${businessId}/user/${userId}`, result.data.data).then(({ data: p }) => p);
|
|
64
64
|
};
|
|
65
65
|
//#endregion
|
|
66
66
|
//#region src/createUser.ts
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-user",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.38",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.cts",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"author": "Vulog",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@vulog/aima-client": "1.2.
|
|
36
|
-
"@vulog/aima-config": "1.2.
|
|
37
|
-
"@vulog/aima-core": "1.2.
|
|
35
|
+
"@vulog/aima-client": "1.2.38",
|
|
36
|
+
"@vulog/aima-config": "1.2.38",
|
|
37
|
+
"@vulog/aima-core": "1.2.38"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"zod": "^3.25.76"
|
|
41
41
|
},
|
|
42
42
|
"description": ""
|
|
43
|
-
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { describe, test, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { Client } from '@vulog/aima-client';
|
|
3
|
+
import { createBusinessProfile } from './createBusinessProfile';
|
|
4
|
+
|
|
5
|
+
describe('createBusinessProfile', () => {
|
|
6
|
+
const FLEET_ID = 'HOURCAR-USMSP';
|
|
7
|
+
const USER_ID = '8a274a9c-f5ac-4258-abe1-6c892b6c0b4b';
|
|
8
|
+
const BUSINESS_ID = '051323b4-0f23-4b8d-88b5-d653d20df8ca';
|
|
9
|
+
const REQUEST_ID = '8ee558c1-863e-48cb-9338-e5612ed08d51';
|
|
10
|
+
|
|
11
|
+
const postMock = vi.fn();
|
|
12
|
+
const client = {
|
|
13
|
+
post: postMock,
|
|
14
|
+
clientOptions: {
|
|
15
|
+
fleetId: FLEET_ID,
|
|
16
|
+
},
|
|
17
|
+
} as unknown as Client;
|
|
18
|
+
|
|
19
|
+
const mockUserProfile = {
|
|
20
|
+
id: '4e0bcb24-8f1a-45b0-9a6b-0817886fa195',
|
|
21
|
+
creationDate: '2026-03-18T13:17:14.208+00:00',
|
|
22
|
+
entityId: 'entity-id',
|
|
23
|
+
entityName: 'default',
|
|
24
|
+
status: 'APPROVED' as const,
|
|
25
|
+
type: 'Business' as const,
|
|
26
|
+
emailConsent: true,
|
|
27
|
+
services: [],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
postMock.mockReset();
|
|
32
|
+
postMock.mockResolvedValue({ data: mockUserProfile });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('calls POST with correct URL', async () => {
|
|
36
|
+
const data = {
|
|
37
|
+
emailConsent: true,
|
|
38
|
+
email: 'contact@company.com',
|
|
39
|
+
requestId: REQUEST_ID,
|
|
40
|
+
costCenterId: undefined,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
await createBusinessProfile(client, USER_ID, BUSINESS_ID, data);
|
|
44
|
+
|
|
45
|
+
expect(postMock).toHaveBeenCalledTimes(1);
|
|
46
|
+
const [url] = postMock.mock.calls[0];
|
|
47
|
+
expect(url).toBe(
|
|
48
|
+
`/boapi/proxy/business/fleets/${FLEET_ID}/business/${BUSINESS_ID}/user/${USER_ID}`
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('sends flat profile body (email, emailConsent, requestId) - no userId/businessId in body', async () => {
|
|
53
|
+
const email = 'business.contact@example.com';
|
|
54
|
+
const data = {
|
|
55
|
+
emailConsent: true,
|
|
56
|
+
email,
|
|
57
|
+
requestId: REQUEST_ID,
|
|
58
|
+
costCenterId: undefined,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
await createBusinessProfile(client, USER_ID, BUSINESS_ID, data);
|
|
62
|
+
|
|
63
|
+
const [, body] = postMock.mock.calls[0];
|
|
64
|
+
expect(body).not.toHaveProperty('userId');
|
|
65
|
+
expect(body).not.toHaveProperty('businessId');
|
|
66
|
+
expect(body).not.toHaveProperty('data');
|
|
67
|
+
expect(body).toHaveProperty('email', email);
|
|
68
|
+
expect(body).toHaveProperty('emailConsent', true);
|
|
69
|
+
expect(body).toHaveProperty('requestId', REQUEST_ID);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('sends costCenterId when provided', async () => {
|
|
73
|
+
const costCenterId = '018ab2b6-71b2-4c76-90bd-6e8d3f26861c';
|
|
74
|
+
const data = {
|
|
75
|
+
emailConsent: false,
|
|
76
|
+
email: 'biz@example.com',
|
|
77
|
+
requestId: REQUEST_ID,
|
|
78
|
+
costCenterId,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
await createBusinessProfile(client, USER_ID, BUSINESS_ID, data);
|
|
82
|
+
|
|
83
|
+
const [, body] = postMock.mock.calls[0];
|
|
84
|
+
expect(body).toEqual({
|
|
85
|
+
emailConsent: false,
|
|
86
|
+
email: 'biz@example.com',
|
|
87
|
+
requestId: REQUEST_ID,
|
|
88
|
+
costCenterId,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('omits costCenterId from body when undefined', async () => {
|
|
93
|
+
const data = {
|
|
94
|
+
emailConsent: true,
|
|
95
|
+
email: 'minimal@test.org',
|
|
96
|
+
requestId: REQUEST_ID,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
await createBusinessProfile(client, USER_ID, BUSINESS_ID, data);
|
|
100
|
+
|
|
101
|
+
const [, body] = postMock.mock.calls[0];
|
|
102
|
+
expect(body).toHaveProperty('email', 'minimal@test.org');
|
|
103
|
+
expect(body).toHaveProperty('requestId', REQUEST_ID);
|
|
104
|
+
expect(body).toHaveProperty('emailConsent', true);
|
|
105
|
+
expect(body).not.toHaveProperty('costCenterId');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('returns response data as UserProfile', async () => {
|
|
109
|
+
const data = {
|
|
110
|
+
emailConsent: true,
|
|
111
|
+
email: 'return@test.com',
|
|
112
|
+
requestId: REQUEST_ID,
|
|
113
|
+
costCenterId: undefined,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const result = await createBusinessProfile(
|
|
117
|
+
client,
|
|
118
|
+
USER_ID,
|
|
119
|
+
BUSINESS_ID,
|
|
120
|
+
data
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
expect(result).toEqual(mockUserProfile);
|
|
124
|
+
expect(result.id).toBe(mockUserProfile.id);
|
|
125
|
+
expect(result.status).toBe('APPROVED');
|
|
126
|
+
expect(result.type).toBe('Business');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('throws TypeError when email is invalid', async () => {
|
|
130
|
+
const data = {
|
|
131
|
+
emailConsent: true,
|
|
132
|
+
email: 'not-an-email',
|
|
133
|
+
requestId: REQUEST_ID,
|
|
134
|
+
costCenterId: undefined,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
await expect(
|
|
138
|
+
createBusinessProfile(client, USER_ID, BUSINESS_ID, data)
|
|
139
|
+
).rejects.toThrow(TypeError);
|
|
140
|
+
|
|
141
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('throws TypeError when email is empty', async () => {
|
|
145
|
+
const data = {
|
|
146
|
+
emailConsent: true,
|
|
147
|
+
email: '',
|
|
148
|
+
requestId: REQUEST_ID,
|
|
149
|
+
costCenterId: undefined,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
await expect(
|
|
153
|
+
createBusinessProfile(client, USER_ID, BUSINESS_ID, data)
|
|
154
|
+
).rejects.toThrow(TypeError);
|
|
155
|
+
|
|
156
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('throws TypeError when userId is not a valid UUID', async () => {
|
|
160
|
+
const data = {
|
|
161
|
+
emailConsent: true,
|
|
162
|
+
email: 'valid@example.com',
|
|
163
|
+
requestId: REQUEST_ID,
|
|
164
|
+
costCenterId: undefined,
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
await expect(
|
|
168
|
+
createBusinessProfile(client, 'not-a-uuid', BUSINESS_ID, data)
|
|
169
|
+
).rejects.toThrow(TypeError);
|
|
170
|
+
|
|
171
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test('throws TypeError when businessId is not a valid UUID', async () => {
|
|
175
|
+
const data = {
|
|
176
|
+
emailConsent: true,
|
|
177
|
+
email: 'valid@example.com',
|
|
178
|
+
requestId: REQUEST_ID,
|
|
179
|
+
costCenterId: undefined,
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
await expect(
|
|
183
|
+
createBusinessProfile(client, USER_ID, 'invalid-business', data)
|
|
184
|
+
).rejects.toThrow(TypeError);
|
|
185
|
+
|
|
186
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('throws TypeError when requestId is not a valid UUID', async () => {
|
|
190
|
+
const data = {
|
|
191
|
+
emailConsent: true,
|
|
192
|
+
email: 'valid@example.com',
|
|
193
|
+
requestId: 'not-a-uuid',
|
|
194
|
+
costCenterId: undefined,
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
await expect(
|
|
198
|
+
createBusinessProfile(client, USER_ID, BUSINESS_ID, data)
|
|
199
|
+
).rejects.toThrow(TypeError);
|
|
200
|
+
|
|
201
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test('throws TypeError when costCenterId is not a valid UUID when provided', async () => {
|
|
205
|
+
const data = {
|
|
206
|
+
emailConsent: true,
|
|
207
|
+
email: 'valid@example.com',
|
|
208
|
+
requestId: REQUEST_ID,
|
|
209
|
+
costCenterId: 'not-a-uuid',
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
await expect(
|
|
213
|
+
createBusinessProfile(client, USER_ID, BUSINESS_ID, data)
|
|
214
|
+
).rejects.toThrow(TypeError);
|
|
215
|
+
|
|
216
|
+
expect(postMock).not.toHaveBeenCalled();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('error cause includes Zod issues for invalid input', async () => {
|
|
220
|
+
const data = {
|
|
221
|
+
emailConsent: true,
|
|
222
|
+
email: 'bad-email',
|
|
223
|
+
requestId: REQUEST_ID,
|
|
224
|
+
costCenterId: undefined,
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
await createBusinessProfile(client, USER_ID, BUSINESS_ID, data);
|
|
229
|
+
} catch (err) {
|
|
230
|
+
expect(err).toBeInstanceOf(TypeError);
|
|
231
|
+
expect((err as Error).cause).toBeDefined();
|
|
232
|
+
expect(Array.isArray((err as Error).cause)).toBe(true);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test('sends various valid email formats in body', async () => {
|
|
237
|
+
const emails = [
|
|
238
|
+
'user@example.com',
|
|
239
|
+
'user+tag@sub.domain.co.uk',
|
|
240
|
+
'tneels+biz04@vulog.com',
|
|
241
|
+
];
|
|
242
|
+
|
|
243
|
+
for (const email of emails) {
|
|
244
|
+
postMock.mockClear();
|
|
245
|
+
const data = {
|
|
246
|
+
emailConsent: true,
|
|
247
|
+
email,
|
|
248
|
+
requestId: REQUEST_ID,
|
|
249
|
+
costCenterId: undefined,
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
await createBusinessProfile(client, USER_ID, BUSINESS_ID, data);
|
|
253
|
+
|
|
254
|
+
const [, body] = postMock.mock.calls[0];
|
|
255
|
+
expect(body.email).toBe(email);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
});
|
|
@@ -7,7 +7,7 @@ export type CreateBusinessProfile = {
|
|
|
7
7
|
emailConsent: boolean;
|
|
8
8
|
email: string;
|
|
9
9
|
requestId: string;
|
|
10
|
-
costCenterId
|
|
10
|
+
costCenterId?: string | null;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
const createBusinessProfileSchema = z.object({
|
|
@@ -33,7 +33,7 @@ export const createBusinessProfile = async (
|
|
|
33
33
|
data,
|
|
34
34
|
});
|
|
35
35
|
if (!result.success) {
|
|
36
|
-
throw new TypeError('Invalid
|
|
36
|
+
throw new TypeError('Invalid arguments', {
|
|
37
37
|
cause: result.error.issues,
|
|
38
38
|
});
|
|
39
39
|
}
|
|
@@ -41,7 +41,7 @@ export const createBusinessProfile = async (
|
|
|
41
41
|
return client
|
|
42
42
|
.post(
|
|
43
43
|
`/boapi/proxy/business/fleets/${client.clientOptions.fleetId}/business/${businessId}/user/${userId}`,
|
|
44
|
-
result.data
|
|
44
|
+
result.data.data
|
|
45
45
|
)
|
|
46
46
|
.then(({ data: p }) => p);
|
|
47
47
|
};
|