@smess/networking 1.0.3 → 1.0.4
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/scripts/real-test.js +177 -11
- package/dist/src/services/auth.service.d.ts +8 -6
- package/dist/src/services/auth.service.js +26 -25
- package/dist/src/services/auth.service.test.js +3 -1
- package/dist/src/services/customer.service.d.ts +43 -0
- package/dist/src/services/customer.service.js +75 -0
- package/dist/src/services/customer.service.test.d.ts +1 -0
- package/dist/src/services/customer.service.test.js +98 -0
- package/dist/src/services/order.service.d.ts +60 -0
- package/dist/src/services/order.service.js +94 -0
- package/dist/src/services/order.service.test.d.ts +1 -0
- package/dist/src/services/order.service.test.js +137 -0
- package/dist/src/services/smess.service.d.ts +1 -0
- package/dist/src/services/smess.service.js +4 -5
- package/dist/src/services/smess.service.test.js +22 -26
- package/dist/src/services/store.service.d.ts +39 -0
- package/dist/src/services/store.service.js +78 -0
- package/dist/src/services/store.service.test.d.ts +1 -0
- package/dist/src/services/store.service.test.js +106 -0
- package/dist/src/types/types.d.ts +1 -3
- package/package.json +1 -1
|
@@ -6,6 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const user_service_1 = require("../src/services/user.service");
|
|
7
7
|
const rxjs_1 = require("rxjs");
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const auth_service_1 = require("../src/services/auth.service");
|
|
10
|
+
const customer_service_1 = require("../src/services/customer.service");
|
|
11
|
+
const store_service_1 = require("../src/services/store.service");
|
|
12
|
+
const logger_service_1 = require("../src/services/logger.service");
|
|
9
13
|
function isNetworkingUIEventWrapped(val) {
|
|
10
14
|
return (typeof val === 'object' &&
|
|
11
15
|
val !== null &&
|
|
@@ -13,6 +17,53 @@ function isNetworkingUIEventWrapped(val) {
|
|
|
13
17
|
'hasFailed' in val &&
|
|
14
18
|
'response' in val);
|
|
15
19
|
}
|
|
20
|
+
async function testAuthService() {
|
|
21
|
+
const config = {
|
|
22
|
+
baseUrl: 'https://api.smeservices.cloud',
|
|
23
|
+
version: 'api/v1',
|
|
24
|
+
isProd: true,
|
|
25
|
+
clientId: '665e188a-cdb0-11ef-b5bd-470a5caf5cbc',
|
|
26
|
+
};
|
|
27
|
+
const $authToken = new rxjs_1.BehaviorSubject(null);
|
|
28
|
+
const authService = new auth_service_1.AuthService(config, $authToken);
|
|
29
|
+
let emitted = false;
|
|
30
|
+
try {
|
|
31
|
+
const obs$ = authService.login({ identifier: 'test@email.org', password: 'PassWord123' }).pipe((0, rxjs_1.timeout)({ first: 10000 }), (0, rxjs_1.catchError)(err => {
|
|
32
|
+
logger_service_1.$logger.error('❌ AuthService observable error', err, 'real-test');
|
|
33
|
+
return (0, rxjs_1.of)(undefined);
|
|
34
|
+
}));
|
|
35
|
+
await new Promise((resolve, reject) => {
|
|
36
|
+
obs$.subscribe({
|
|
37
|
+
next: (val) => {
|
|
38
|
+
emitted = true;
|
|
39
|
+
logger_service_1.$logger.info('AuthService emission', val, 'real-test');
|
|
40
|
+
if (isNetworkingUIEventWrapped(val) && val.hasSuccess && val.response) {
|
|
41
|
+
logger_service_1.$logger.info('✅ AuthService real API test succeeded', val.response, 'real-test');
|
|
42
|
+
resolve(undefined);
|
|
43
|
+
}
|
|
44
|
+
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
45
|
+
logger_service_1.$logger.error('❌ AuthService real API test failed', val.alertModel || val, 'real-test');
|
|
46
|
+
reject(new Error('AuthService failed'));
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
error: (err) => {
|
|
50
|
+
logger_service_1.$logger.error('❌ AuthService observable error', err, 'real-test');
|
|
51
|
+
reject(err);
|
|
52
|
+
},
|
|
53
|
+
complete: () => {
|
|
54
|
+
if (!emitted) {
|
|
55
|
+
logger_service_1.$logger.error('❌ AuthService observable completed without emission', undefined, 'real-test');
|
|
56
|
+
reject(new Error('No emission'));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
logger_service_1.$logger.error('❌ AuthService test error', err, 'real-test');
|
|
64
|
+
process.exit(2);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
16
67
|
async function testUserService() {
|
|
17
68
|
const config = {
|
|
18
69
|
baseUrl: 'https://jsonplaceholder.typicode.com',
|
|
@@ -22,30 +73,137 @@ async function testUserService() {
|
|
|
22
73
|
let emitted = false;
|
|
23
74
|
try {
|
|
24
75
|
const obs$ = userService.fetchUserById(1).pipe((0, rxjs_1.timeout)({ first: 10000 }), (0, rxjs_1.catchError)(err => {
|
|
25
|
-
|
|
76
|
+
logger_service_1.$logger.error('❌ UserService observable error', err, 'real-test');
|
|
26
77
|
return (0, rxjs_1.of)(undefined);
|
|
27
78
|
}));
|
|
28
79
|
await new Promise((resolve, reject) => {
|
|
29
80
|
obs$.subscribe({
|
|
30
81
|
next: (val) => {
|
|
31
82
|
emitted = true;
|
|
32
|
-
|
|
83
|
+
logger_service_1.$logger.info('UserService emission', val, 'real-test');
|
|
33
84
|
if (isNetworkingUIEventWrapped(val) && val.hasSuccess && val.response) {
|
|
34
|
-
|
|
85
|
+
logger_service_1.$logger.info('✅ UserService real API test succeeded', val.response, 'real-test');
|
|
35
86
|
resolve(undefined);
|
|
36
87
|
}
|
|
37
88
|
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
38
|
-
|
|
89
|
+
logger_service_1.$logger.error('❌ UserService real API test failed', val.alertModel || val, 'real-test');
|
|
39
90
|
reject(new Error('UserService failed'));
|
|
40
91
|
}
|
|
41
92
|
},
|
|
42
93
|
error: (err) => {
|
|
43
|
-
|
|
94
|
+
logger_service_1.$logger.error('❌ UserService observable error', err, 'real-test');
|
|
95
|
+
reject(err);
|
|
96
|
+
},
|
|
97
|
+
complete: () => {
|
|
98
|
+
if (!emitted) {
|
|
99
|
+
logger_service_1.$logger.error('❌ UserService observable completed without emission', undefined, 'real-test');
|
|
100
|
+
reject(new Error('No emission'));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
logger_service_1.$logger.error('❌ UserService test error', err, 'real-test');
|
|
108
|
+
process.exit(2);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function testCustomerRegister() {
|
|
112
|
+
const config = {
|
|
113
|
+
baseUrl: 'https://api.smeservices.cloud',
|
|
114
|
+
version: 'api/v1',
|
|
115
|
+
isProd: true,
|
|
116
|
+
clientId: '665e188a-cdb0-11ef-b5bd-470a5caf5cbc',
|
|
117
|
+
};
|
|
118
|
+
const $authToken = new rxjs_1.BehaviorSubject(null);
|
|
119
|
+
const customerService = new customer_service_1.CustomerService(config, $authToken);
|
|
120
|
+
const random = Math.floor(Math.random() * 1000000);
|
|
121
|
+
const payload = {
|
|
122
|
+
email: `realtest+${random}@email.org`,
|
|
123
|
+
password: `PassWord${random}`,
|
|
124
|
+
phone_number: `+83${random}`,
|
|
125
|
+
client_id: config.clientId,
|
|
126
|
+
};
|
|
127
|
+
let emitted = false;
|
|
128
|
+
try {
|
|
129
|
+
const obs$ = customerService.register(payload).pipe((0, rxjs_1.timeout)({ first: 10000 }), (0, rxjs_1.catchError)(err => {
|
|
130
|
+
logger_service_1.$logger.error('❌ CustomerService observable error', err, 'real-test');
|
|
131
|
+
return (0, rxjs_1.of)(undefined);
|
|
132
|
+
}));
|
|
133
|
+
await new Promise((resolve, reject) => {
|
|
134
|
+
obs$.subscribe({
|
|
135
|
+
next: (val) => {
|
|
136
|
+
emitted = true;
|
|
137
|
+
logger_service_1.$logger.info('CustomerService emission', val, 'real-test');
|
|
138
|
+
if (isNetworkingUIEventWrapped(val) && val.hasSuccess && val.response) {
|
|
139
|
+
logger_service_1.$logger.info('✅ CustomerService real API test succeeded', val.response, 'real-test');
|
|
140
|
+
resolve(undefined);
|
|
141
|
+
}
|
|
142
|
+
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
143
|
+
logger_service_1.$logger.error('❌ CustomerService real API test failed', val.alertModel || val, 'real-test');
|
|
144
|
+
reject(new Error('CustomerService failed'));
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
error: (err) => {
|
|
148
|
+
logger_service_1.$logger.error('❌ CustomerService observable error', err, 'real-test');
|
|
149
|
+
reject(err);
|
|
150
|
+
},
|
|
151
|
+
complete: () => {
|
|
152
|
+
if (!emitted) {
|
|
153
|
+
logger_service_1.$logger.error('❌ CustomerService observable completed without emission', undefined, 'real-test');
|
|
154
|
+
reject(new Error('No emission'));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
logger_service_1.$logger.error('❌ CustomerService test error', err, 'real-test');
|
|
162
|
+
process.exit(2);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async function testStoreProductCollection() {
|
|
166
|
+
const config = {
|
|
167
|
+
baseUrl: 'https://api.smeservices.cloud',
|
|
168
|
+
version: 'api/v1',
|
|
169
|
+
isProd: true,
|
|
170
|
+
clientId: '665e188a-cdb0-11ef-b5bd-470a5caf5cbc',
|
|
171
|
+
};
|
|
172
|
+
const $authToken = new rxjs_1.BehaviorSubject(null);
|
|
173
|
+
const storeService = new store_service_1.StoreService(config, $authToken);
|
|
174
|
+
const storeId = 'f1df6e9a-0160-11f0-82c2-6cac1a7e2953'; // Use a real or test store id as appropriate
|
|
175
|
+
const payload = {
|
|
176
|
+
page: 1,
|
|
177
|
+
per_page: 10,
|
|
178
|
+
search: 'bia',
|
|
179
|
+
};
|
|
180
|
+
let emitted = false;
|
|
181
|
+
try {
|
|
182
|
+
const obs$ = storeService.productCollection(storeId, payload).pipe((0, rxjs_1.timeout)({ first: 10000 }), (0, rxjs_1.catchError)(err => {
|
|
183
|
+
logger_service_1.$logger.error('❌ StoreService.productCollection observable error', err, 'real-test');
|
|
184
|
+
return (0, rxjs_1.of)(undefined);
|
|
185
|
+
}));
|
|
186
|
+
await new Promise((resolve, reject) => {
|
|
187
|
+
obs$.subscribe({
|
|
188
|
+
next: (val) => {
|
|
189
|
+
emitted = true;
|
|
190
|
+
logger_service_1.$logger.info('StoreService.productCollection emission', val, 'real-test');
|
|
191
|
+
if (isNetworkingUIEventWrapped(val) && val.hasSuccess && val.response) {
|
|
192
|
+
logger_service_1.$logger.info('✅ StoreService.productCollection real API test succeeded', val.response, 'real-test');
|
|
193
|
+
resolve(undefined);
|
|
194
|
+
}
|
|
195
|
+
else if (isNetworkingUIEventWrapped(val) && val.hasFailed) {
|
|
196
|
+
logger_service_1.$logger.error('❌ StoreService.productCollection real API test failed', val.alertModel || val, 'real-test');
|
|
197
|
+
reject(new Error('StoreService.productCollection failed'));
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
error: (err) => {
|
|
201
|
+
logger_service_1.$logger.error('❌ StoreService.productCollection observable error', err, 'real-test');
|
|
44
202
|
reject(err);
|
|
45
203
|
},
|
|
46
204
|
complete: () => {
|
|
47
205
|
if (!emitted) {
|
|
48
|
-
|
|
206
|
+
logger_service_1.$logger.error('❌ StoreService.productCollection observable completed without emission', undefined, 'real-test');
|
|
49
207
|
reject(new Error('No emission'));
|
|
50
208
|
}
|
|
51
209
|
}
|
|
@@ -53,7 +211,7 @@ async function testUserService() {
|
|
|
53
211
|
});
|
|
54
212
|
}
|
|
55
213
|
catch (err) {
|
|
56
|
-
|
|
214
|
+
logger_service_1.$logger.error('❌ StoreService.productCollection test error', err, 'real-test');
|
|
57
215
|
process.exit(2);
|
|
58
216
|
}
|
|
59
217
|
}
|
|
@@ -61,21 +219,29 @@ async function testAxiosDirect() {
|
|
|
61
219
|
try {
|
|
62
220
|
const response = await axios_1.default.get('https://jsonplaceholder.typicode.com/users/1');
|
|
63
221
|
if (response && response.data && response.data.id === 1) {
|
|
64
|
-
|
|
222
|
+
logger_service_1.$logger.info('✅ Direct axios test succeeded', response.data, 'real-test');
|
|
65
223
|
}
|
|
66
224
|
else {
|
|
67
|
-
|
|
225
|
+
logger_service_1.$logger.error('❌ Direct axios test failed', response.data, 'real-test');
|
|
68
226
|
process.exit(3);
|
|
69
227
|
}
|
|
70
228
|
}
|
|
71
229
|
catch (err) {
|
|
72
|
-
|
|
230
|
+
logger_service_1.$logger.error('❌ Direct axios test error', err, 'real-test');
|
|
73
231
|
process.exit(4);
|
|
74
232
|
}
|
|
75
233
|
}
|
|
76
234
|
(async () => {
|
|
77
235
|
await testAxiosDirect();
|
|
236
|
+
logger_service_1.$logger.info('✅ Direct axios test passed!', undefined, 'real-test');
|
|
237
|
+
await testAuthService();
|
|
238
|
+
logger_service_1.$logger.info('✅ AuthService real API tests passed!', undefined, 'real-test');
|
|
78
239
|
await testUserService();
|
|
79
|
-
|
|
240
|
+
logger_service_1.$logger.info('✅ UserService real API tests passed!', undefined, 'real-test');
|
|
241
|
+
await testCustomerRegister();
|
|
242
|
+
logger_service_1.$logger.info('✅ CustomerService real API register test passed!', undefined, 'real-test');
|
|
243
|
+
await testStoreProductCollection();
|
|
244
|
+
logger_service_1.$logger.info('✅ StoreService.productCollection real API test passed!', undefined, 'real-test');
|
|
245
|
+
logger_service_1.$logger.info('🎉 All real API tests passed!', undefined, 'real-test');
|
|
80
246
|
process.exit(0);
|
|
81
247
|
})();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types';
|
|
2
2
|
import { SmessService } from './smess.service';
|
|
3
|
-
import { Observable } from "rxjs";
|
|
3
|
+
import { BehaviorSubject, Observable } from "rxjs";
|
|
4
4
|
export interface AuthLoginRequest {
|
|
5
5
|
identifier: string;
|
|
6
6
|
password: string;
|
|
@@ -22,15 +22,16 @@ export type AuthLoginResponse = {
|
|
|
22
22
|
token: unknown;
|
|
23
23
|
refresh_token: unknown;
|
|
24
24
|
};
|
|
25
|
-
export type AuthTarget = '
|
|
25
|
+
export type AuthTarget = 'login' | 'logout' | 'change-password' | 'password-forgot' | 'reset-password' | 'verify-reset-password-token';
|
|
26
26
|
export declare class AuthProvider implements ProviderType {
|
|
27
27
|
private readonly config;
|
|
28
28
|
private readonly target;
|
|
29
|
-
|
|
29
|
+
private readonly $authToken;
|
|
30
|
+
constructor(config: NetworkingConfig, target: AuthTarget, $authToken: BehaviorSubject<string | null>);
|
|
30
31
|
get baseURL(): string;
|
|
31
32
|
get path(): string;
|
|
32
33
|
get method(): string;
|
|
33
|
-
get headers(): Record<string, string
|
|
34
|
+
get headers(): Record<string, string>;
|
|
34
35
|
getPath(...queryParams: unknown[]): string;
|
|
35
36
|
}
|
|
36
37
|
export interface AuthServiceType {
|
|
@@ -43,8 +44,9 @@ export interface AuthServiceType {
|
|
|
43
44
|
verifyResetPasswordToken(token: string): Observable<NetworkingUIEventWrapped<AuthLoginResponse>>;
|
|
44
45
|
}
|
|
45
46
|
export declare class AuthService implements AuthServiceType {
|
|
46
|
-
private config;
|
|
47
|
-
|
|
47
|
+
private readonly config;
|
|
48
|
+
private readonly $authToken;
|
|
49
|
+
constructor(config: NetworkingConfig, $authToken: BehaviorSubject<string | null>);
|
|
48
50
|
provider(target: AuthTarget): SmessService<AuthProvider>;
|
|
49
51
|
login(payload: AuthLoginRequest): Observable<NetworkingUIEventWrapped<AuthLoginResponse>>;
|
|
50
52
|
logout(): Observable<NetworkingUIEventWrapped<void>>;
|
|
@@ -3,57 +3,57 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AuthService = exports.AuthProvider = void 0;
|
|
4
4
|
const smess_service_1 = require("./smess.service");
|
|
5
5
|
class AuthProvider {
|
|
6
|
-
constructor(config, target) {
|
|
6
|
+
constructor(config, target, $authToken) {
|
|
7
7
|
this.config = config;
|
|
8
8
|
this.target = target;
|
|
9
|
+
this.$authToken = $authToken;
|
|
9
10
|
}
|
|
10
11
|
get baseURL() {
|
|
11
|
-
return `${this.config.baseUrl}
|
|
12
|
+
return this.config.version ? `${this.config.baseUrl}/${this.config.version}` : this.config.baseUrl;
|
|
12
13
|
}
|
|
13
14
|
get path() {
|
|
14
15
|
switch (this.target) {
|
|
15
16
|
case 'login':
|
|
16
17
|
return '/authentication/login_check';
|
|
17
|
-
case 'logout':
|
|
18
|
-
return '/authentication/logout';
|
|
19
|
-
case 'register':
|
|
20
|
-
return '/authentication/customer/register';
|
|
21
|
-
case 'get-profile':
|
|
22
|
-
return '/authentication/customer/get-profile';
|
|
23
|
-
case 'update-profile':
|
|
24
|
-
return '/authentication/customer/update';
|
|
25
18
|
case 'password-forgot':
|
|
26
19
|
return '/authentication/forgot-password';
|
|
27
|
-
case 'change-password':
|
|
28
|
-
return '/authentication/change-password';
|
|
29
20
|
case 'reset-password':
|
|
30
21
|
return '/authentication/reset-password';
|
|
22
|
+
case 'verify-reset-password-token':
|
|
23
|
+
return '/authentication/verify-reset-password-token';
|
|
24
|
+
case 'logout':
|
|
25
|
+
return '/authentication/logout';
|
|
26
|
+
case 'change-password':
|
|
27
|
+
return '/authentication/change-password';
|
|
31
28
|
default:
|
|
32
29
|
return '/authentication';
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
32
|
get method() {
|
|
36
33
|
switch (this.target) {
|
|
37
|
-
case 'get-profile':
|
|
38
|
-
return 'GET';
|
|
39
|
-
case 'update-profile':
|
|
40
|
-
return 'PUT';
|
|
41
34
|
default:
|
|
42
35
|
return 'POST';
|
|
43
36
|
}
|
|
44
37
|
}
|
|
45
38
|
get headers() {
|
|
39
|
+
let authHeaders = {};
|
|
46
40
|
switch (this.target) {
|
|
47
41
|
case 'login':
|
|
48
|
-
|
|
49
|
-
case '
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
case 'password-forgot':
|
|
43
|
+
case 'reset-password':
|
|
44
|
+
case 'verify-reset-password-token':
|
|
45
|
+
authHeaders = smess_service_1.SmessService.getHeaders(smess_service_1.Accept.V1);
|
|
46
|
+
break;
|
|
53
47
|
default:
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
authHeaders = smess_service_1.SmessService.getHeaders(smess_service_1.Accept.V1, this.$authToken.value);
|
|
49
|
+
}
|
|
50
|
+
if (this.config.clientId) {
|
|
51
|
+
authHeaders[smess_service_1.SMESSHeader.ClientId] = this.config.clientId;
|
|
52
|
+
}
|
|
53
|
+
if (this.config.apiKey) {
|
|
54
|
+
authHeaders[smess_service_1.SMESSHeader.ApiKey] = this.config.apiKey;
|
|
56
55
|
}
|
|
56
|
+
return smess_service_1.SmessService.filterHeaders(authHeaders);
|
|
57
57
|
}
|
|
58
58
|
getPath(...queryParams) {
|
|
59
59
|
let definedPath = this.path;
|
|
@@ -66,11 +66,12 @@ class AuthProvider {
|
|
|
66
66
|
}
|
|
67
67
|
exports.AuthProvider = AuthProvider;
|
|
68
68
|
class AuthService {
|
|
69
|
-
constructor(config) {
|
|
69
|
+
constructor(config, $authToken) {
|
|
70
70
|
this.config = config;
|
|
71
|
+
this.$authToken = $authToken;
|
|
71
72
|
}
|
|
72
73
|
provider(target) {
|
|
73
|
-
const targetWrapper = new AuthProvider(this.config, target);
|
|
74
|
+
const targetWrapper = new AuthProvider(this.config, target, this.$authToken);
|
|
74
75
|
return new smess_service_1.SmessService(targetWrapper);
|
|
75
76
|
}
|
|
76
77
|
login(payload) {
|
|
@@ -11,8 +11,10 @@ describe('AuthService', () => {
|
|
|
11
11
|
apiKey: 'test-api-key',
|
|
12
12
|
};
|
|
13
13
|
let service;
|
|
14
|
+
let $authToken;
|
|
14
15
|
beforeEach(() => {
|
|
15
|
-
|
|
16
|
+
$authToken = new rxjs_1.BehaviorSubject(null);
|
|
17
|
+
service = new auth_service_1.AuthService(config, $authToken);
|
|
16
18
|
});
|
|
17
19
|
it('login success', async () => {
|
|
18
20
|
const payload = { identifier: 'user', password: 'pass' };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types';
|
|
2
|
+
import { SmessService } from './smess.service';
|
|
3
|
+
import { BehaviorSubject, Observable } from 'rxjs';
|
|
4
|
+
export type CustomerTarget = 'register' | 'get-profile' | 'update-profile';
|
|
5
|
+
export interface CustomerRegisterRequest {
|
|
6
|
+
client_id?: string;
|
|
7
|
+
email: string;
|
|
8
|
+
password: string;
|
|
9
|
+
phone_number?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
address?: string;
|
|
12
|
+
tax_identification_number?: string | null;
|
|
13
|
+
}
|
|
14
|
+
export interface CustomerUpdateRequest {
|
|
15
|
+
name: string;
|
|
16
|
+
address: string;
|
|
17
|
+
postal_code: string;
|
|
18
|
+
city: string;
|
|
19
|
+
state: string | null;
|
|
20
|
+
country: string | null;
|
|
21
|
+
contact_email: string | null;
|
|
22
|
+
phone_number: string | null;
|
|
23
|
+
}
|
|
24
|
+
export declare class CustomerProvider implements ProviderType {
|
|
25
|
+
private readonly config;
|
|
26
|
+
private readonly target;
|
|
27
|
+
private readonly $authToken;
|
|
28
|
+
constructor(config: NetworkingConfig, target: CustomerTarget, $authToken: BehaviorSubject<string | null>);
|
|
29
|
+
get baseURL(): string;
|
|
30
|
+
get path(): string;
|
|
31
|
+
get method(): string;
|
|
32
|
+
get headers(): Record<string, string>;
|
|
33
|
+
getPath(...queryParams: unknown[]): string;
|
|
34
|
+
}
|
|
35
|
+
export declare class CustomerService {
|
|
36
|
+
private readonly config;
|
|
37
|
+
private readonly $authToken;
|
|
38
|
+
constructor(config: NetworkingConfig, $authToken: BehaviorSubject<string | null>);
|
|
39
|
+
provider(target: CustomerTarget): SmessService<CustomerProvider>;
|
|
40
|
+
register(payload: CustomerRegisterRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
41
|
+
getProfile(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
42
|
+
updateProfile(payload: CustomerUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomerService = exports.CustomerProvider = void 0;
|
|
4
|
+
const smess_service_1 = require("./smess.service");
|
|
5
|
+
class CustomerProvider {
|
|
6
|
+
constructor(config, target, $authToken) {
|
|
7
|
+
this.config = config;
|
|
8
|
+
this.target = target;
|
|
9
|
+
this.$authToken = $authToken;
|
|
10
|
+
}
|
|
11
|
+
get baseURL() {
|
|
12
|
+
return this.config.version ? `${this.config.baseUrl}/${this.config.version}` : this.config.baseUrl;
|
|
13
|
+
}
|
|
14
|
+
get path() {
|
|
15
|
+
switch (this.target) {
|
|
16
|
+
case 'register':
|
|
17
|
+
return '/authentication/customer/register';
|
|
18
|
+
case 'get-profile':
|
|
19
|
+
return '/authentication/customer/get-profile';
|
|
20
|
+
case 'update-profile':
|
|
21
|
+
return '/authentication/customer/update';
|
|
22
|
+
default:
|
|
23
|
+
return '/authentication/customer';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
get method() {
|
|
27
|
+
switch (this.target) {
|
|
28
|
+
case 'get-profile':
|
|
29
|
+
return 'GET';
|
|
30
|
+
case 'update-profile':
|
|
31
|
+
return 'PUT';
|
|
32
|
+
default:
|
|
33
|
+
return 'POST';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
get headers() {
|
|
37
|
+
let headers = smess_service_1.SmessService.getHeaders(smess_service_1.Accept.V1, this.$authToken.value);
|
|
38
|
+
if (this.config.clientId) {
|
|
39
|
+
headers[smess_service_1.SMESSHeader.ClientId] = this.config.clientId;
|
|
40
|
+
}
|
|
41
|
+
if (this.config.apiKey) {
|
|
42
|
+
headers[smess_service_1.SMESSHeader.ApiKey] = this.config.apiKey;
|
|
43
|
+
}
|
|
44
|
+
return smess_service_1.SmessService.filterHeaders(headers);
|
|
45
|
+
}
|
|
46
|
+
getPath(...queryParams) {
|
|
47
|
+
let definedPath = this.path;
|
|
48
|
+
const params = definedPath.match(/\$\{(.+?)\}/g);
|
|
49
|
+
params === null || params === void 0 ? void 0 : params.forEach((value, index) => {
|
|
50
|
+
definedPath = definedPath.replace(value, String(queryParams[index]));
|
|
51
|
+
});
|
|
52
|
+
return definedPath;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.CustomerProvider = CustomerProvider;
|
|
56
|
+
class CustomerService {
|
|
57
|
+
constructor(config, $authToken) {
|
|
58
|
+
this.config = config;
|
|
59
|
+
this.$authToken = $authToken;
|
|
60
|
+
}
|
|
61
|
+
provider(target) {
|
|
62
|
+
const targetWrapper = new CustomerProvider(this.config, target, this.$authToken);
|
|
63
|
+
return new smess_service_1.SmessService(targetWrapper);
|
|
64
|
+
}
|
|
65
|
+
register(payload) {
|
|
66
|
+
return this.provider('register').request(payload);
|
|
67
|
+
}
|
|
68
|
+
getProfile() {
|
|
69
|
+
return this.provider('get-profile').request();
|
|
70
|
+
}
|
|
71
|
+
updateProfile(payload) {
|
|
72
|
+
return this.provider('update-profile').request(payload);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.CustomerService = CustomerService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const customer_service_1 = require("./customer.service");
|
|
4
|
+
const types_1 = require("../types/types");
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
describe('CustomerService', () => {
|
|
7
|
+
const config = {
|
|
8
|
+
baseUrl: 'https://api.example.com',
|
|
9
|
+
isProd: false,
|
|
10
|
+
clientId: 'test-client-id',
|
|
11
|
+
apiKey: 'test-api-key',
|
|
12
|
+
};
|
|
13
|
+
let service;
|
|
14
|
+
let $authToken;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
$authToken = new rxjs_1.BehaviorSubject(null);
|
|
17
|
+
service = new customer_service_1.CustomerService(config, $authToken);
|
|
18
|
+
});
|
|
19
|
+
it('register success', async () => {
|
|
20
|
+
const payload = {
|
|
21
|
+
email: 'test@example.com',
|
|
22
|
+
password: 'pass',
|
|
23
|
+
};
|
|
24
|
+
const response = { data: { id: 1, email: 'test@example.com' } };
|
|
25
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
26
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response)),
|
|
27
|
+
});
|
|
28
|
+
const result = await service.register(payload).toPromise();
|
|
29
|
+
expect(result === null || result === void 0 ? void 0 : result.hasSuccess).toBe(true);
|
|
30
|
+
expect(result === null || result === void 0 ? void 0 : result.response).toEqual(response);
|
|
31
|
+
});
|
|
32
|
+
it('register error', async () => {
|
|
33
|
+
const payload = {
|
|
34
|
+
email: 'test@example.com',
|
|
35
|
+
password: 'pass',
|
|
36
|
+
};
|
|
37
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
38
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.failed(types_1.AlertModel.default())),
|
|
39
|
+
});
|
|
40
|
+
const result = await service.register(payload).toPromise();
|
|
41
|
+
expect(result === null || result === void 0 ? void 0 : result.hasFailed).toBe(true);
|
|
42
|
+
expect(result === null || result === void 0 ? void 0 : result.alertModel).toBeInstanceOf(types_1.AlertModel);
|
|
43
|
+
});
|
|
44
|
+
it('getProfile success', async () => {
|
|
45
|
+
const response = { data: { id: 1, email: 'test@example.com' } };
|
|
46
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
47
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response)),
|
|
48
|
+
});
|
|
49
|
+
const result = await service.getProfile().toPromise();
|
|
50
|
+
expect(result === null || result === void 0 ? void 0 : result.hasSuccess).toBe(true);
|
|
51
|
+
expect(result === null || result === void 0 ? void 0 : result.response).toEqual(response);
|
|
52
|
+
});
|
|
53
|
+
it('getProfile error', async () => {
|
|
54
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
55
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.failed(types_1.AlertModel.default())),
|
|
56
|
+
});
|
|
57
|
+
const result = await service.getProfile().toPromise();
|
|
58
|
+
expect(result === null || result === void 0 ? void 0 : result.hasFailed).toBe(true);
|
|
59
|
+
expect(result === null || result === void 0 ? void 0 : result.alertModel).toBeInstanceOf(types_1.AlertModel);
|
|
60
|
+
});
|
|
61
|
+
it('updateProfile success', async () => {
|
|
62
|
+
const payload = {
|
|
63
|
+
name: 'Test',
|
|
64
|
+
address: '123 Main St',
|
|
65
|
+
postal_code: '12345',
|
|
66
|
+
city: 'City',
|
|
67
|
+
state: null,
|
|
68
|
+
country: null,
|
|
69
|
+
contact_email: null,
|
|
70
|
+
phone_number: null,
|
|
71
|
+
};
|
|
72
|
+
const response = { data: { id: 1, name: 'Test' } };
|
|
73
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
74
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response)),
|
|
75
|
+
});
|
|
76
|
+
const result = await service.updateProfile(payload).toPromise();
|
|
77
|
+
expect(result === null || result === void 0 ? void 0 : result.hasSuccess).toBe(true);
|
|
78
|
+
expect(result === null || result === void 0 ? void 0 : result.response).toEqual(response);
|
|
79
|
+
});
|
|
80
|
+
it('updateProfile error', async () => {
|
|
81
|
+
const payload = {
|
|
82
|
+
name: 'Test',
|
|
83
|
+
address: '123 Main St',
|
|
84
|
+
postal_code: '12345',
|
|
85
|
+
city: 'City',
|
|
86
|
+
state: null,
|
|
87
|
+
country: null,
|
|
88
|
+
contact_email: null,
|
|
89
|
+
phone_number: null,
|
|
90
|
+
};
|
|
91
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
92
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.failed(types_1.AlertModel.default())),
|
|
93
|
+
});
|
|
94
|
+
const result = await service.updateProfile(payload).toPromise();
|
|
95
|
+
expect(result === null || result === void 0 ? void 0 : result.hasFailed).toBe(true);
|
|
96
|
+
expect(result === null || result === void 0 ? void 0 : result.alertModel).toBeInstanceOf(types_1.AlertModel);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types';
|
|
2
|
+
import { SmessService } from './smess.service';
|
|
3
|
+
import { BehaviorSubject, Observable } from 'rxjs';
|
|
4
|
+
export type OrderTarget = 'order-list' | 'order-create' | 'order-delete' | 'order-get-draft' | 'order-update' | 'order-get';
|
|
5
|
+
export interface CreateOrderRequest extends UpdateOrderRequest {
|
|
6
|
+
}
|
|
7
|
+
export interface UpdateOrderRequest {
|
|
8
|
+
external_id?: string;
|
|
9
|
+
order_date: string;
|
|
10
|
+
type?: string;
|
|
11
|
+
status?: string;
|
|
12
|
+
payment_status?: string;
|
|
13
|
+
delivery_note?: string;
|
|
14
|
+
delivery_fee?: number;
|
|
15
|
+
payment_method?: string;
|
|
16
|
+
payment_period?: string;
|
|
17
|
+
discount_in_percent?: number;
|
|
18
|
+
due_payment_amount?: number;
|
|
19
|
+
total_gst?: number;
|
|
20
|
+
total_exclude_gst?: number;
|
|
21
|
+
total_include_gst?: number;
|
|
22
|
+
order_items: OrderItemRequest[];
|
|
23
|
+
}
|
|
24
|
+
export interface OrderItemRequest {
|
|
25
|
+
product_name: string;
|
|
26
|
+
product_category: string;
|
|
27
|
+
supplier?: string;
|
|
28
|
+
supplier_code?: string;
|
|
29
|
+
supplier_item_name?: string;
|
|
30
|
+
unit: string;
|
|
31
|
+
quantity: number;
|
|
32
|
+
price_include_taxes: number;
|
|
33
|
+
vat_in_percent: number;
|
|
34
|
+
discount_in_percent?: number;
|
|
35
|
+
page_number?: number;
|
|
36
|
+
item_row_in_page?: number;
|
|
37
|
+
}
|
|
38
|
+
export declare class OrderProvider implements ProviderType {
|
|
39
|
+
private readonly config;
|
|
40
|
+
private readonly target;
|
|
41
|
+
private readonly $authToken;
|
|
42
|
+
constructor(config: NetworkingConfig, target: OrderTarget, $authToken: BehaviorSubject<string | null>);
|
|
43
|
+
get baseURL(): string;
|
|
44
|
+
get path(): string;
|
|
45
|
+
get method(): string;
|
|
46
|
+
get headers(): Record<string, string>;
|
|
47
|
+
getPath(...queryParams: unknown[]): string;
|
|
48
|
+
}
|
|
49
|
+
export declare class OrderService {
|
|
50
|
+
private readonly config;
|
|
51
|
+
private readonly $authToken;
|
|
52
|
+
constructor(config: NetworkingConfig, $authToken: BehaviorSubject<string | null>);
|
|
53
|
+
provider(target: OrderTarget): SmessService<OrderProvider>;
|
|
54
|
+
list(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
55
|
+
create(payload: CreateOrderRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
56
|
+
delete(id: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
57
|
+
getDraft(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
58
|
+
update(id: string, payload: UpdateOrderRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
59
|
+
get(id: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OrderService = exports.OrderProvider = void 0;
|
|
4
|
+
const smess_service_1 = require("./smess.service");
|
|
5
|
+
class OrderProvider {
|
|
6
|
+
constructor(config, target, $authToken) {
|
|
7
|
+
this.config = config;
|
|
8
|
+
this.target = target;
|
|
9
|
+
this.$authToken = $authToken;
|
|
10
|
+
}
|
|
11
|
+
get baseURL() {
|
|
12
|
+
return this.config.version ? `${this.config.baseUrl}/${this.config.version}` : this.config.baseUrl;
|
|
13
|
+
}
|
|
14
|
+
get path() {
|
|
15
|
+
switch (this.target) {
|
|
16
|
+
case 'order-list':
|
|
17
|
+
return '/order/list';
|
|
18
|
+
case 'order-create':
|
|
19
|
+
return '/order/create';
|
|
20
|
+
case 'order-delete':
|
|
21
|
+
return '/order/${id}';
|
|
22
|
+
case 'order-get-draft':
|
|
23
|
+
return '/order/get-draft';
|
|
24
|
+
case 'order-update':
|
|
25
|
+
case 'order-get':
|
|
26
|
+
default:
|
|
27
|
+
return '/order/${id}';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
get method() {
|
|
31
|
+
switch (this.target) {
|
|
32
|
+
case 'order-list':
|
|
33
|
+
case 'order-get':
|
|
34
|
+
case 'order-get-draft':
|
|
35
|
+
return 'GET';
|
|
36
|
+
case 'order-create':
|
|
37
|
+
return 'POST';
|
|
38
|
+
case 'order-update':
|
|
39
|
+
return 'PUT';
|
|
40
|
+
case 'order-delete':
|
|
41
|
+
return 'DELETE';
|
|
42
|
+
default:
|
|
43
|
+
return 'GET';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
get headers() {
|
|
47
|
+
let headers = smess_service_1.SmessService.getHeaders(smess_service_1.Accept.V1, this.$authToken.value);
|
|
48
|
+
if (this.config.clientId) {
|
|
49
|
+
headers[smess_service_1.SMESSHeader.ClientId] = this.config.clientId;
|
|
50
|
+
}
|
|
51
|
+
if (this.config.apiKey) {
|
|
52
|
+
headers[smess_service_1.SMESSHeader.ApiKey] = this.config.apiKey;
|
|
53
|
+
}
|
|
54
|
+
return smess_service_1.SmessService.filterHeaders(headers);
|
|
55
|
+
}
|
|
56
|
+
getPath(...queryParams) {
|
|
57
|
+
let definedPath = this.path;
|
|
58
|
+
const params = definedPath.match(/\$\{(.+?)\}/g);
|
|
59
|
+
params === null || params === void 0 ? void 0 : params.forEach((value, index) => {
|
|
60
|
+
definedPath = definedPath.replace(value, String(queryParams[index]));
|
|
61
|
+
});
|
|
62
|
+
return definedPath;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.OrderProvider = OrderProvider;
|
|
66
|
+
class OrderService {
|
|
67
|
+
constructor(config, $authToken) {
|
|
68
|
+
this.config = config;
|
|
69
|
+
this.$authToken = $authToken;
|
|
70
|
+
}
|
|
71
|
+
provider(target) {
|
|
72
|
+
const targetWrapper = new OrderProvider(this.config, target, this.$authToken);
|
|
73
|
+
return new smess_service_1.SmessService(targetWrapper);
|
|
74
|
+
}
|
|
75
|
+
list() {
|
|
76
|
+
return this.provider('order-list').request();
|
|
77
|
+
}
|
|
78
|
+
create(payload) {
|
|
79
|
+
return this.provider('order-create').request(payload);
|
|
80
|
+
}
|
|
81
|
+
delete(id) {
|
|
82
|
+
return this.provider('order-delete').request(null, undefined, id);
|
|
83
|
+
}
|
|
84
|
+
getDraft() {
|
|
85
|
+
return this.provider('order-get-draft').request();
|
|
86
|
+
}
|
|
87
|
+
update(id, payload) {
|
|
88
|
+
return this.provider('order-update').request(payload, undefined, id);
|
|
89
|
+
}
|
|
90
|
+
get(id) {
|
|
91
|
+
return this.provider('order-get').request(null, undefined, id);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.OrderService = OrderService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const order_service_1 = require("./order.service");
|
|
4
|
+
const types_1 = require("../types/types");
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
describe('OrderService', () => {
|
|
7
|
+
const config = {
|
|
8
|
+
baseUrl: 'https://api.example.com',
|
|
9
|
+
isProd: false,
|
|
10
|
+
clientId: 'test-client-id',
|
|
11
|
+
apiKey: 'test-api-key',
|
|
12
|
+
};
|
|
13
|
+
let service;
|
|
14
|
+
let $authToken;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
$authToken = new rxjs_1.BehaviorSubject(null);
|
|
17
|
+
service = new order_service_1.OrderService(config, $authToken);
|
|
18
|
+
});
|
|
19
|
+
it('list success', async () => {
|
|
20
|
+
const response = { data: [{ id: '1', status: 'draft' }] };
|
|
21
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
22
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response)),
|
|
23
|
+
});
|
|
24
|
+
const result = await service.list().toPromise();
|
|
25
|
+
expect(result === null || result === void 0 ? void 0 : result.hasSuccess).toBe(true);
|
|
26
|
+
expect(result === null || result === void 0 ? void 0 : result.response).toEqual(response);
|
|
27
|
+
});
|
|
28
|
+
it('list error', async () => {
|
|
29
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
30
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.failed(types_1.AlertModel.default())),
|
|
31
|
+
});
|
|
32
|
+
const result = await service.list().toPromise();
|
|
33
|
+
expect(result === null || result === void 0 ? void 0 : result.hasFailed).toBe(true);
|
|
34
|
+
expect(result === null || result === void 0 ? void 0 : result.alertModel).toBeInstanceOf(types_1.AlertModel);
|
|
35
|
+
});
|
|
36
|
+
it('create success', async () => {
|
|
37
|
+
const payload = {
|
|
38
|
+
order_date: '2024-01-01',
|
|
39
|
+
order_items: [],
|
|
40
|
+
};
|
|
41
|
+
const response = { data: { id: '1', status: 'created' } };
|
|
42
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
43
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response)),
|
|
44
|
+
});
|
|
45
|
+
const result = await service.create(payload).toPromise();
|
|
46
|
+
expect(result === null || result === void 0 ? void 0 : result.hasSuccess).toBe(true);
|
|
47
|
+
expect(result === null || result === void 0 ? void 0 : result.response).toEqual(response);
|
|
48
|
+
});
|
|
49
|
+
it('create error', async () => {
|
|
50
|
+
const payload = {
|
|
51
|
+
order_date: '2024-01-01',
|
|
52
|
+
order_items: [],
|
|
53
|
+
};
|
|
54
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
55
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.failed(types_1.AlertModel.default())),
|
|
56
|
+
});
|
|
57
|
+
const result = await service.create(payload).toPromise();
|
|
58
|
+
expect(result === null || result === void 0 ? void 0 : result.hasFailed).toBe(true);
|
|
59
|
+
expect(result === null || result === void 0 ? void 0 : result.alertModel).toBeInstanceOf(types_1.AlertModel);
|
|
60
|
+
});
|
|
61
|
+
it('delete success', async () => {
|
|
62
|
+
const response = { data: { id: '1', status: 'deleted' } };
|
|
63
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
64
|
+
request: (_payload, _mockResponse, id) => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response)),
|
|
65
|
+
});
|
|
66
|
+
const result = await service.delete('1').toPromise();
|
|
67
|
+
expect(result === null || result === void 0 ? void 0 : result.hasSuccess).toBe(true);
|
|
68
|
+
expect(result === null || result === void 0 ? void 0 : result.response).toEqual(response);
|
|
69
|
+
});
|
|
70
|
+
it('delete error', async () => {
|
|
71
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
72
|
+
request: (_payload, _mockResponse, id) => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.failed(types_1.AlertModel.default())),
|
|
73
|
+
});
|
|
74
|
+
const result = await service.delete('1').toPromise();
|
|
75
|
+
expect(result === null || result === void 0 ? void 0 : result.hasFailed).toBe(true);
|
|
76
|
+
expect(result === null || result === void 0 ? void 0 : result.alertModel).toBeInstanceOf(types_1.AlertModel);
|
|
77
|
+
});
|
|
78
|
+
it('getDraft success', async () => {
|
|
79
|
+
const response = { data: { id: 'draft', status: 'draft' } };
|
|
80
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
81
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response)),
|
|
82
|
+
});
|
|
83
|
+
const result = await service.getDraft().toPromise();
|
|
84
|
+
expect(result === null || result === void 0 ? void 0 : result.hasSuccess).toBe(true);
|
|
85
|
+
expect(result === null || result === void 0 ? void 0 : result.response).toEqual(response);
|
|
86
|
+
});
|
|
87
|
+
it('getDraft error', async () => {
|
|
88
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
89
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.failed(types_1.AlertModel.default())),
|
|
90
|
+
});
|
|
91
|
+
const result = await service.getDraft().toPromise();
|
|
92
|
+
expect(result === null || result === void 0 ? void 0 : result.hasFailed).toBe(true);
|
|
93
|
+
expect(result === null || result === void 0 ? void 0 : result.alertModel).toBeInstanceOf(types_1.AlertModel);
|
|
94
|
+
});
|
|
95
|
+
it('update success', async () => {
|
|
96
|
+
const payload = {
|
|
97
|
+
order_date: '2024-01-01',
|
|
98
|
+
order_items: [],
|
|
99
|
+
};
|
|
100
|
+
const response = { data: { id: '1', status: 'updated' } };
|
|
101
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
102
|
+
request: (_payload, _mockResponse, id) => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response)),
|
|
103
|
+
});
|
|
104
|
+
const result = await service.update('1', payload).toPromise();
|
|
105
|
+
expect(result === null || result === void 0 ? void 0 : result.hasSuccess).toBe(true);
|
|
106
|
+
expect(result === null || result === void 0 ? void 0 : result.response).toEqual(response);
|
|
107
|
+
});
|
|
108
|
+
it('update error', async () => {
|
|
109
|
+
const payload = {
|
|
110
|
+
order_date: '2024-01-01',
|
|
111
|
+
order_items: [],
|
|
112
|
+
};
|
|
113
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
114
|
+
request: (_payload, _mockResponse, id) => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.failed(types_1.AlertModel.default())),
|
|
115
|
+
});
|
|
116
|
+
const result = await service.update('1', payload).toPromise();
|
|
117
|
+
expect(result === null || result === void 0 ? void 0 : result.hasFailed).toBe(true);
|
|
118
|
+
expect(result === null || result === void 0 ? void 0 : result.alertModel).toBeInstanceOf(types_1.AlertModel);
|
|
119
|
+
});
|
|
120
|
+
it('get success', async () => {
|
|
121
|
+
const response = { data: { id: '1', status: 'fetched' } };
|
|
122
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
123
|
+
request: (_payload, _mockResponse, id) => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response)),
|
|
124
|
+
});
|
|
125
|
+
const result = await service.get('1').toPromise();
|
|
126
|
+
expect(result === null || result === void 0 ? void 0 : result.hasSuccess).toBe(true);
|
|
127
|
+
expect(result === null || result === void 0 ? void 0 : result.response).toEqual(response);
|
|
128
|
+
});
|
|
129
|
+
it('get error', async () => {
|
|
130
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
131
|
+
request: (_payload, _mockResponse, id) => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.failed(types_1.AlertModel.default())),
|
|
132
|
+
});
|
|
133
|
+
const result = await service.get('1').toPromise();
|
|
134
|
+
expect(result === null || result === void 0 ? void 0 : result.hasFailed).toBe(true);
|
|
135
|
+
expect(result === null || result === void 0 ? void 0 : result.alertModel).toBeInstanceOf(types_1.AlertModel);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -28,6 +28,7 @@ export declare class SmessService<T extends ProviderType> {
|
|
|
28
28
|
private target;
|
|
29
29
|
constructor(target: T);
|
|
30
30
|
static getHeaders(version: Accept, authorization?: string | null, options?: HeaderType): Partial<Record<SMESSHeader, string | undefined>>;
|
|
31
|
+
static filterHeaders(headers: Partial<Record<SMESSHeader, string | undefined>>): Record<string, string>;
|
|
31
32
|
private static commonHeaders;
|
|
32
33
|
request<R = unknown>(request?: unknown, mockResponse?: R, ...queryParams: unknown[]): Observable<NetworkingUIEventWrapped<R>>;
|
|
33
34
|
private transformAxiosError;
|
|
@@ -69,6 +69,10 @@ class SmessService {
|
|
|
69
69
|
}
|
|
70
70
|
return headers;
|
|
71
71
|
}
|
|
72
|
+
static filterHeaders(headers) {
|
|
73
|
+
const filteredHeaders = Object.fromEntries(Object.entries(headers).filter(([_, value]) => value !== undefined && value !== null && value !== ''));
|
|
74
|
+
return filteredHeaders;
|
|
75
|
+
}
|
|
72
76
|
static commonHeaders(version, options) {
|
|
73
77
|
const { shouldAddClientIdHeader = true, } = options !== null && options !== void 0 ? options : {};
|
|
74
78
|
const headers = {
|
|
@@ -81,9 +85,6 @@ class SmessService {
|
|
|
81
85
|
}
|
|
82
86
|
// MARK: - Public
|
|
83
87
|
request(request, mockResponse, ...queryParams) {
|
|
84
|
-
if (mockResponse !== undefined) {
|
|
85
|
-
return (0, rxjs_import_1.of)(types_1.NetworkingUIEventWrapped.succeeded(mockResponse));
|
|
86
|
-
}
|
|
87
88
|
const url = queryParams.length
|
|
88
89
|
? this.target.getPath(...queryParams)
|
|
89
90
|
: this.target.path;
|
|
@@ -94,11 +95,9 @@ class SmessService {
|
|
|
94
95
|
config.data = request;
|
|
95
96
|
config.params = request;
|
|
96
97
|
}
|
|
97
|
-
// Note: HttpService.get expects (url, config)
|
|
98
98
|
observable = this.httpService.get(url, config);
|
|
99
99
|
}
|
|
100
100
|
else if (this.target.method === 'POST') {
|
|
101
|
-
// HttpService.post expects (url, data, config)
|
|
102
101
|
observable = this.httpService.post(url, request, config);
|
|
103
102
|
}
|
|
104
103
|
else if (this.target.method === 'PATCH') {
|
|
@@ -25,19 +25,14 @@ describe('SmessService', () => {
|
|
|
25
25
|
post: jest.fn(),
|
|
26
26
|
patch: jest.fn(),
|
|
27
27
|
put: jest.fn(),
|
|
28
|
-
|
|
29
|
-
request: jest.fn((payload) => {
|
|
30
|
-
if (payload === 'error') {
|
|
31
|
-
return (0, rxjs_1.throwError)(() => new Error('Test error'));
|
|
32
|
-
}
|
|
33
|
-
return (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded({ foo: 'bar' }));
|
|
34
|
-
}),
|
|
28
|
+
request: jest.fn(),
|
|
35
29
|
interceptors: { response: { use: jest.fn() } },
|
|
36
30
|
};
|
|
37
31
|
service.request().subscribe(result => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
if (result.hasSuccess) {
|
|
33
|
+
expect(result.response).toEqual({ foo: 'bar' });
|
|
34
|
+
done();
|
|
35
|
+
}
|
|
41
36
|
});
|
|
42
37
|
});
|
|
43
38
|
it('should return succeeded for POST', done => {
|
|
@@ -45,20 +40,17 @@ describe('SmessService', () => {
|
|
|
45
40
|
const service = new smess_service_1.SmessService(postProvider);
|
|
46
41
|
service['httpService'] = {
|
|
47
42
|
get: jest.fn(),
|
|
48
|
-
post: jest.fn((
|
|
49
|
-
if (payload === 'error') {
|
|
50
|
-
return (0, rxjs_1.throwError)(() => new Error('Test error'));
|
|
51
|
-
}
|
|
52
|
-
return (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded({ foo: 'baz' }));
|
|
53
|
-
}),
|
|
43
|
+
post: jest.fn(() => (0, rxjs_1.of)({ data: { foo: 'baz' } })),
|
|
54
44
|
patch: jest.fn(),
|
|
55
45
|
put: jest.fn(),
|
|
56
46
|
request: jest.fn(),
|
|
57
47
|
interceptors: { response: { use: jest.fn() } },
|
|
58
48
|
};
|
|
59
49
|
service.request({ some: 'data' }).subscribe(result => {
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
if (result.hasSuccess) {
|
|
51
|
+
expect(result.response).toEqual({ foo: 'baz' });
|
|
52
|
+
done();
|
|
53
|
+
}
|
|
62
54
|
});
|
|
63
55
|
});
|
|
64
56
|
it('should handle error', done => {
|
|
@@ -73,11 +65,13 @@ describe('SmessService', () => {
|
|
|
73
65
|
};
|
|
74
66
|
service.request().subscribe(result => {
|
|
75
67
|
var _a;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
if (result.hasFailed) {
|
|
69
|
+
expect(result).toBeInstanceOf(types_1.NetworkingUIEventWrapped);
|
|
70
|
+
expect(result.hasFailed).toBe(true);
|
|
71
|
+
expect(result.alertModel).toBeTruthy();
|
|
72
|
+
expect((_a = result.alertModel) === null || _a === void 0 ? void 0 : _a.message).toBe('Test error');
|
|
73
|
+
done();
|
|
74
|
+
}
|
|
81
75
|
});
|
|
82
76
|
});
|
|
83
77
|
it('should return mock response if provided', done => {
|
|
@@ -94,13 +88,15 @@ describe('SmessService', () => {
|
|
|
94
88
|
if (mockResponse !== undefined) {
|
|
95
89
|
return (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(mockResponse));
|
|
96
90
|
}
|
|
97
|
-
return (0, rxjs_1.of)(
|
|
91
|
+
return (0, rxjs_1.of)({ data: { foo: 'mock' } });
|
|
98
92
|
}),
|
|
99
93
|
interceptors: { response: { use: jest.fn() } },
|
|
100
94
|
};
|
|
101
95
|
service.request(undefined, { foo: 'mock' }).subscribe(result => {
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
if (result.hasSuccess) {
|
|
97
|
+
expect(result.response).toEqual({ foo: 'mock' });
|
|
98
|
+
done();
|
|
99
|
+
}
|
|
104
100
|
});
|
|
105
101
|
});
|
|
106
102
|
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from '../types/types';
|
|
2
|
+
import { SmessService } from './smess.service';
|
|
3
|
+
import { BehaviorSubject, Observable } from 'rxjs';
|
|
4
|
+
export type StoreTarget = 'store-get' | 'store-list' | 'store-product-category-list' | 'store-product-collection' | 'store-featured-product-list';
|
|
5
|
+
export interface ProductCollectionRequest {
|
|
6
|
+
page?: number;
|
|
7
|
+
per_page?: number;
|
|
8
|
+
search?: string;
|
|
9
|
+
sort_by?: string;
|
|
10
|
+
category?: string;
|
|
11
|
+
min_price?: number;
|
|
12
|
+
max_price?: number;
|
|
13
|
+
only_discounted?: boolean;
|
|
14
|
+
unit?: string;
|
|
15
|
+
supplier?: string;
|
|
16
|
+
has_offer?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare class StoreProvider implements ProviderType {
|
|
19
|
+
private readonly config;
|
|
20
|
+
private readonly target;
|
|
21
|
+
private readonly $authToken;
|
|
22
|
+
constructor(config: NetworkingConfig, target: StoreTarget, $authToken: BehaviorSubject<string | null>);
|
|
23
|
+
get baseURL(): string;
|
|
24
|
+
get path(): string;
|
|
25
|
+
get method(): string;
|
|
26
|
+
get headers(): Record<string, string>;
|
|
27
|
+
getPath(...queryParams: unknown[]): string;
|
|
28
|
+
}
|
|
29
|
+
export declare class StoreService {
|
|
30
|
+
private readonly config;
|
|
31
|
+
private readonly $authToken;
|
|
32
|
+
constructor(config: NetworkingConfig, $authToken: BehaviorSubject<string | null>);
|
|
33
|
+
provider(target: StoreTarget): SmessService<StoreProvider>;
|
|
34
|
+
get(id: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
35
|
+
list(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
36
|
+
productCategoryList(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
37
|
+
productCollection(id: string, payload: ProductCollectionRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
38
|
+
featuredProductList(id: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StoreService = exports.StoreProvider = void 0;
|
|
4
|
+
const smess_service_1 = require("./smess.service");
|
|
5
|
+
class StoreProvider {
|
|
6
|
+
constructor(config, target, $authToken) {
|
|
7
|
+
this.config = config;
|
|
8
|
+
this.target = target;
|
|
9
|
+
this.$authToken = $authToken;
|
|
10
|
+
}
|
|
11
|
+
get baseURL() {
|
|
12
|
+
return this.config.version ? `${this.config.baseUrl}/${this.config.version}` : this.config.baseUrl;
|
|
13
|
+
}
|
|
14
|
+
get path() {
|
|
15
|
+
switch (this.target) {
|
|
16
|
+
case 'store-get':
|
|
17
|
+
return '/store/${id}/information';
|
|
18
|
+
case 'store-list':
|
|
19
|
+
return '/store/list';
|
|
20
|
+
case 'store-product-category-list':
|
|
21
|
+
return '/store/product-category-list';
|
|
22
|
+
case 'store-product-collection':
|
|
23
|
+
return '/store/${id}/product-collection';
|
|
24
|
+
case 'store-featured-product-list':
|
|
25
|
+
return '/store/${id}/featured-product-list';
|
|
26
|
+
default:
|
|
27
|
+
return '/store/${id}';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
get method() {
|
|
31
|
+
return 'GET';
|
|
32
|
+
}
|
|
33
|
+
get headers() {
|
|
34
|
+
let headers = smess_service_1.SmessService.getHeaders(smess_service_1.Accept.V1, this.$authToken.value);
|
|
35
|
+
if (this.config.clientId) {
|
|
36
|
+
headers[smess_service_1.SMESSHeader.ClientId] = this.config.clientId;
|
|
37
|
+
}
|
|
38
|
+
if (this.config.apiKey) {
|
|
39
|
+
headers[smess_service_1.SMESSHeader.ApiKey] = this.config.apiKey;
|
|
40
|
+
}
|
|
41
|
+
return smess_service_1.SmessService.filterHeaders(headers);
|
|
42
|
+
}
|
|
43
|
+
getPath(...queryParams) {
|
|
44
|
+
let definedPath = this.path;
|
|
45
|
+
const params = definedPath.match(/\$\{(.+?)\}/g);
|
|
46
|
+
params === null || params === void 0 ? void 0 : params.forEach((value, index) => {
|
|
47
|
+
definedPath = definedPath.replace(value, String(queryParams[index]));
|
|
48
|
+
});
|
|
49
|
+
return definedPath;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.StoreProvider = StoreProvider;
|
|
53
|
+
class StoreService {
|
|
54
|
+
constructor(config, $authToken) {
|
|
55
|
+
this.config = config;
|
|
56
|
+
this.$authToken = $authToken;
|
|
57
|
+
}
|
|
58
|
+
provider(target) {
|
|
59
|
+
const targetWrapper = new StoreProvider(this.config, target, this.$authToken);
|
|
60
|
+
return new smess_service_1.SmessService(targetWrapper);
|
|
61
|
+
}
|
|
62
|
+
get(id) {
|
|
63
|
+
return this.provider('store-get').request(null, undefined, id);
|
|
64
|
+
}
|
|
65
|
+
list() {
|
|
66
|
+
return this.provider('store-list').request();
|
|
67
|
+
}
|
|
68
|
+
productCategoryList() {
|
|
69
|
+
return this.provider('store-product-category-list').request();
|
|
70
|
+
}
|
|
71
|
+
productCollection(id, payload) {
|
|
72
|
+
return this.provider('store-product-collection').request(payload, undefined, id);
|
|
73
|
+
}
|
|
74
|
+
featuredProductList(id) {
|
|
75
|
+
return this.provider('store-featured-product-list').request(null, undefined, id);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.StoreService = StoreService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const store_service_1 = require("./store.service");
|
|
4
|
+
const types_1 = require("../types/types");
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
describe('StoreService', () => {
|
|
7
|
+
const config = {
|
|
8
|
+
baseUrl: 'https://api.example.com',
|
|
9
|
+
isProd: false,
|
|
10
|
+
clientId: 'test-client-id',
|
|
11
|
+
apiKey: 'test-api-key',
|
|
12
|
+
};
|
|
13
|
+
let service;
|
|
14
|
+
let $authToken;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
$authToken = new rxjs_1.BehaviorSubject(null);
|
|
17
|
+
service = new store_service_1.StoreService(config, $authToken);
|
|
18
|
+
});
|
|
19
|
+
it('get success', async () => {
|
|
20
|
+
const response = { data: { id: '1', name: 'Store' } };
|
|
21
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
22
|
+
request: (_payload, _mockResponse, id) => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response)),
|
|
23
|
+
});
|
|
24
|
+
const result = await service.get('1').toPromise();
|
|
25
|
+
expect(result === null || result === void 0 ? void 0 : result.hasSuccess).toBe(true);
|
|
26
|
+
expect(result === null || result === void 0 ? void 0 : result.response).toEqual(response);
|
|
27
|
+
});
|
|
28
|
+
it('get error', async () => {
|
|
29
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
30
|
+
request: (_payload, _mockResponse, id) => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.failed(types_1.AlertModel.default())),
|
|
31
|
+
});
|
|
32
|
+
const result = await service.get('1').toPromise();
|
|
33
|
+
expect(result === null || result === void 0 ? void 0 : result.hasFailed).toBe(true);
|
|
34
|
+
expect(result === null || result === void 0 ? void 0 : result.alertModel).toBeInstanceOf(types_1.AlertModel);
|
|
35
|
+
});
|
|
36
|
+
it('list success', async () => {
|
|
37
|
+
const response = { data: [{ id: '1', name: 'Store' }] };
|
|
38
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
39
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response)),
|
|
40
|
+
});
|
|
41
|
+
const result = await service.list().toPromise();
|
|
42
|
+
expect(result === null || result === void 0 ? void 0 : result.hasSuccess).toBe(true);
|
|
43
|
+
expect(result === null || result === void 0 ? void 0 : result.response).toEqual(response);
|
|
44
|
+
});
|
|
45
|
+
it('list error', async () => {
|
|
46
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
47
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.failed(types_1.AlertModel.default())),
|
|
48
|
+
});
|
|
49
|
+
const result = await service.list().toPromise();
|
|
50
|
+
expect(result === null || result === void 0 ? void 0 : result.hasFailed).toBe(true);
|
|
51
|
+
expect(result === null || result === void 0 ? void 0 : result.alertModel).toBeInstanceOf(types_1.AlertModel);
|
|
52
|
+
});
|
|
53
|
+
it('productCategoryList success', async () => {
|
|
54
|
+
const response = { data: [{ id: 'cat1', name: 'Category' }] };
|
|
55
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
56
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response)),
|
|
57
|
+
});
|
|
58
|
+
const result = await service.productCategoryList().toPromise();
|
|
59
|
+
expect(result === null || result === void 0 ? void 0 : result.hasSuccess).toBe(true);
|
|
60
|
+
expect(result === null || result === void 0 ? void 0 : result.response).toEqual(response);
|
|
61
|
+
});
|
|
62
|
+
it('productCategoryList error', async () => {
|
|
63
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
64
|
+
request: () => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.failed(types_1.AlertModel.default())),
|
|
65
|
+
});
|
|
66
|
+
const result = await service.productCategoryList().toPromise();
|
|
67
|
+
expect(result === null || result === void 0 ? void 0 : result.hasFailed).toBe(true);
|
|
68
|
+
expect(result === null || result === void 0 ? void 0 : result.alertModel).toBeInstanceOf(types_1.AlertModel);
|
|
69
|
+
});
|
|
70
|
+
it('productCollection success', async () => {
|
|
71
|
+
const response = { data: [{ id: 'prod1', name: 'Product' }] };
|
|
72
|
+
const payload = { page: 1, per_page: 10 };
|
|
73
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
74
|
+
request: (payload, _mockResponse, id) => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response)),
|
|
75
|
+
});
|
|
76
|
+
const result = await service.productCollection('1', payload).toPromise();
|
|
77
|
+
expect(result === null || result === void 0 ? void 0 : result.hasSuccess).toBe(true);
|
|
78
|
+
expect(result === null || result === void 0 ? void 0 : result.response).toEqual(response);
|
|
79
|
+
});
|
|
80
|
+
it('productCollection error', async () => {
|
|
81
|
+
const payload = { page: 1, per_page: 10 };
|
|
82
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
83
|
+
request: (payload, _mockResponse, id) => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.failed(types_1.AlertModel.default())),
|
|
84
|
+
});
|
|
85
|
+
const result = await service.productCollection('1', payload).toPromise();
|
|
86
|
+
expect(result === null || result === void 0 ? void 0 : result.hasFailed).toBe(true);
|
|
87
|
+
expect(result === null || result === void 0 ? void 0 : result.alertModel).toBeInstanceOf(types_1.AlertModel);
|
|
88
|
+
});
|
|
89
|
+
it('featuredProductList success', async () => {
|
|
90
|
+
const response = { data: [{ id: 'feat1', name: 'Featured' }] };
|
|
91
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
92
|
+
request: (_payload, _mockResponse, storeId) => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.succeeded(response)),
|
|
93
|
+
});
|
|
94
|
+
const result = await service.featuredProductList('1').toPromise();
|
|
95
|
+
expect(result === null || result === void 0 ? void 0 : result.hasSuccess).toBe(true);
|
|
96
|
+
expect(result === null || result === void 0 ? void 0 : result.response).toEqual(response);
|
|
97
|
+
});
|
|
98
|
+
it('featuredProductList error', async () => {
|
|
99
|
+
jest.spyOn(service, 'provider').mockReturnValue({
|
|
100
|
+
request: (_payload, _mockResponse, storeId) => (0, rxjs_1.of)(types_1.NetworkingUIEventWrapped.failed(types_1.AlertModel.default())),
|
|
101
|
+
});
|
|
102
|
+
const result = await service.featuredProductList('1').toPromise();
|
|
103
|
+
expect(result === null || result === void 0 ? void 0 : result.hasFailed).toBe(true);
|
|
104
|
+
expect(result === null || result === void 0 ? void 0 : result.alertModel).toBeInstanceOf(types_1.AlertModel);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -63,9 +63,6 @@ export interface ProviderType {
|
|
|
63
63
|
headers: Record<string, string | undefined>;
|
|
64
64
|
getPath(...queryParams: unknown[]): string;
|
|
65
65
|
}
|
|
66
|
-
export interface ProviderTypeMockable {
|
|
67
|
-
shouldUseMockData: boolean;
|
|
68
|
-
}
|
|
69
66
|
export interface HeaderType {
|
|
70
67
|
shouldAddEncryptionHeader?: boolean;
|
|
71
68
|
shouldAddClientIdHeader?: boolean;
|
|
@@ -88,6 +85,7 @@ export interface ServerErrorResponse {
|
|
|
88
85
|
}
|
|
89
86
|
export interface NetworkingConfig {
|
|
90
87
|
baseUrl: string;
|
|
88
|
+
version?: string;
|
|
91
89
|
isProd: boolean;
|
|
92
90
|
clientId?: string;
|
|
93
91
|
apiKey?: string;
|