@smess/networking 1.0.23 → 1.0.24
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/dev-test.d.ts +1 -0
- package/dist/scripts/dev-test.js +803 -0
- package/dist/scripts/real-test.d.ts +1 -0
- package/dist/scripts/real-test.js +341 -0
- package/dist/src/core/axios.d.ts +51 -0
- package/dist/src/core/axios.js +65 -0
- package/dist/src/core/axios.observable.d.ts +11 -0
- package/dist/src/core/axios.observable.js +58 -0
- package/dist/src/core/base.provider.advanced.test.d.ts +1 -0
- package/dist/src/core/base.provider.advanced.test.js +29 -0
- package/dist/src/core/base.provider.d.ts +15 -0
- package/dist/src/core/base.provider.js +13 -0
- package/dist/src/core/base.provider.test.d.ts +1 -0
- package/dist/src/core/base.provider.test.js +36 -0
- package/dist/src/core/base.service.wrapper.advanced.test.d.ts +1 -0
- package/dist/src/core/base.service.wrapper.advanced.test.js +39 -0
- package/dist/src/core/base.service.wrapper.d.ts +7 -0
- package/dist/src/core/base.service.wrapper.js +11 -0
- package/dist/src/core/base.service.wrapper.test.d.ts +1 -0
- package/dist/src/core/base.service.wrapper.test.js +25 -0
- package/dist/src/core/rx.http.service.d.ts +51 -0
- package/dist/src/core/rx.http.service.js +65 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.js +21 -0
- package/dist/src/services/auth.service.d.ts +65 -0
- package/dist/src/services/auth.service.js +197 -0
- package/dist/src/services/auth.service.test.d.ts +1 -0
- package/dist/src/services/auth.service.test.js +334 -0
- package/dist/src/services/cache.service.d.ts +31 -0
- package/dist/src/services/cache.service.js +77 -0
- package/dist/src/services/cache.service.test.d.ts +1 -0
- package/dist/src/services/cache.service.test.js +88 -0
- package/dist/src/services/customer.service.d.ts +71 -0
- package/dist/src/services/customer.service.js +114 -0
- package/dist/src/services/customer.service.test.d.ts +1 -0
- package/dist/src/services/customer.service.test.js +274 -0
- package/dist/src/services/employee.service.d.ts +73 -0
- package/dist/src/services/employee.service.js +73 -0
- package/dist/src/services/employee.service.test.d.ts +1 -0
- package/dist/src/services/employee.service.test.js +120 -0
- package/dist/src/services/logger.service.d.ts +31 -0
- package/dist/src/services/logger.service.js +93 -0
- package/dist/src/services/logger.service.test.d.ts +1 -0
- package/dist/src/services/logger.service.test.js +31 -0
- package/dist/src/services/order.service.d.ts +73 -0
- package/dist/src/services/order.service.js +97 -0
- package/dist/src/services/order.service.test.d.ts +1 -0
- package/dist/src/services/order.service.test.js +163 -0
- package/dist/src/services/product.service.d.ts +21 -0
- package/dist/src/services/product.service.js +42 -0
- package/dist/src/services/product.service.test.d.ts +1 -0
- package/dist/src/services/product.service.test.js +61 -0
- package/dist/src/services/smess.service.d.ts +36 -0
- package/dist/src/services/smess.service.js +128 -0
- package/dist/src/services/smess.service.test.d.ts +1 -0
- package/dist/src/services/smess.service.test.js +103 -0
- package/dist/src/services/store.cart.service.d.ts +158 -0
- package/dist/src/services/store.cart.service.js +177 -0
- package/dist/src/services/store.cart.service.test.d.ts +1 -0
- package/dist/src/services/store.cart.service.test.js +394 -0
- package/dist/src/services/store.product.service.d.ts +123 -0
- package/dist/src/services/store.product.service.js +102 -0
- package/dist/src/services/store.product.service.test.d.ts +1 -0
- package/dist/src/services/store.product.service.test.js +319 -0
- package/dist/src/services/store.service.d.ts +79 -0
- package/dist/src/services/store.service.js +235 -0
- package/dist/src/services/store.service.test.d.ts +1 -0
- package/dist/src/services/store.service.test.js +274 -0
- package/dist/src/services/user.service.d.ts +16 -0
- package/dist/src/services/user.service.js +37 -0
- package/dist/src/services/user.service.test.d.ts +1 -0
- package/dist/src/services/user.service.test.js +52 -0
- package/dist/src/types/types.d.ts +93 -0
- package/dist/src/types/types.js +82 -0
- package/dist/src/types/types.test.d.ts +1 -0
- package/dist/src/types/types.test.js +25 -0
- package/dist/src/utils/cache-import.d.ts +3 -0
- package/dist/src/utils/cache-import.js +2 -0
- package/dist/src/utils/networking-import.d.ts +4 -0
- package/dist/src/utils/networking-import.js +3 -0
- package/dist/src/utils/rxjs-import.d.ts +5 -0
- package/dist/src/utils/rxjs-import.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Accept, SMESSHeader, SmessService } from "./smess.service";
|
|
2
|
+
export class CustomerProvider {
|
|
3
|
+
constructor(config, target, $authToken) {
|
|
4
|
+
this.config = config;
|
|
5
|
+
this.target = target;
|
|
6
|
+
this.$authToken = $authToken;
|
|
7
|
+
}
|
|
8
|
+
get baseURL() {
|
|
9
|
+
return this.config.version
|
|
10
|
+
? `${this.config.baseUrl}/${this.config.version}`
|
|
11
|
+
: this.config.baseUrl;
|
|
12
|
+
}
|
|
13
|
+
get path() {
|
|
14
|
+
switch (this.target) {
|
|
15
|
+
case "register":
|
|
16
|
+
return "/authentication/customer/register";
|
|
17
|
+
case "get-profile":
|
|
18
|
+
return "/authentication/customer/get-profile";
|
|
19
|
+
case "update-profile":
|
|
20
|
+
return "/authentication/customer/update";
|
|
21
|
+
case "cart-collection":
|
|
22
|
+
return "/store/cart/collection";
|
|
23
|
+
case "customer-product-collection":
|
|
24
|
+
return "/store/customer-product/collection";
|
|
25
|
+
case "customer-product-create":
|
|
26
|
+
return "/store/customer-product";
|
|
27
|
+
case "customer-product-remove":
|
|
28
|
+
return "/store/customer-product/remove";
|
|
29
|
+
case "customer-product-update-notes":
|
|
30
|
+
return "/store/customer-product/notes";
|
|
31
|
+
default:
|
|
32
|
+
return "/authentication/customer";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
get method() {
|
|
36
|
+
switch (this.target) {
|
|
37
|
+
case "get-profile":
|
|
38
|
+
return "GET";
|
|
39
|
+
case "cart-collection":
|
|
40
|
+
return "GET";
|
|
41
|
+
case "customer-product-collection":
|
|
42
|
+
return "GET";
|
|
43
|
+
case "customer-product-create":
|
|
44
|
+
return "POST";
|
|
45
|
+
case "customer-product-remove":
|
|
46
|
+
return "DELETE";
|
|
47
|
+
case "customer-product-update-notes":
|
|
48
|
+
return "PATCH";
|
|
49
|
+
case "update-profile":
|
|
50
|
+
return "PUT";
|
|
51
|
+
default:
|
|
52
|
+
return "POST";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
get headers() {
|
|
56
|
+
let headers = SmessService.getHeaders(Accept.V1, this.$authToken.value);
|
|
57
|
+
switch (this.target) {
|
|
58
|
+
case "register":
|
|
59
|
+
headers = SmessService.getHeaders(Accept.V1);
|
|
60
|
+
break;
|
|
61
|
+
default:
|
|
62
|
+
headers = SmessService.getHeaders(Accept.V1, this.$authToken.value);
|
|
63
|
+
}
|
|
64
|
+
if (this.config.clientId) {
|
|
65
|
+
headers[SMESSHeader.ClientId] = this.config.clientId;
|
|
66
|
+
}
|
|
67
|
+
if (this.config.apiKey) {
|
|
68
|
+
headers[SMESSHeader.ApiKey] = this.config.apiKey;
|
|
69
|
+
}
|
|
70
|
+
return SmessService.filterHeaders(headers);
|
|
71
|
+
}
|
|
72
|
+
getPath(...queryParams) {
|
|
73
|
+
let definedPath = this.path;
|
|
74
|
+
const params = definedPath.match(/\$\{(.+?)\}/g);
|
|
75
|
+
params?.forEach((value, index) => {
|
|
76
|
+
definedPath = definedPath.replace(value, String(queryParams[index]));
|
|
77
|
+
});
|
|
78
|
+
return definedPath;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export class CustomerService {
|
|
82
|
+
constructor(config, $authToken) {
|
|
83
|
+
this.config = config;
|
|
84
|
+
this.$authToken = $authToken;
|
|
85
|
+
}
|
|
86
|
+
provider(target) {
|
|
87
|
+
const targetWrapper = new CustomerProvider(this.config, target, this.$authToken);
|
|
88
|
+
return new SmessService(targetWrapper);
|
|
89
|
+
}
|
|
90
|
+
register(payload) {
|
|
91
|
+
return this.provider("register").request(payload);
|
|
92
|
+
}
|
|
93
|
+
getProfile() {
|
|
94
|
+
return this.provider("get-profile").request();
|
|
95
|
+
}
|
|
96
|
+
updateProfile(payload) {
|
|
97
|
+
return this.provider("update-profile").request(payload);
|
|
98
|
+
}
|
|
99
|
+
getCartCollection(query) {
|
|
100
|
+
return this.provider("cart-collection").request(query);
|
|
101
|
+
}
|
|
102
|
+
getCustomerProductCollection(query) {
|
|
103
|
+
return this.provider("customer-product-collection").request(query);
|
|
104
|
+
}
|
|
105
|
+
createCustomerProduct(payload) {
|
|
106
|
+
return this.provider("customer-product-create").request(payload);
|
|
107
|
+
}
|
|
108
|
+
removeCustomerProduct(payload) {
|
|
109
|
+
return this.provider("customer-product-remove").request(payload);
|
|
110
|
+
}
|
|
111
|
+
updateCustomerProductNotes(payload) {
|
|
112
|
+
return this.provider("customer-product-update-notes").request(payload);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { CustomerService, } from "./customer.service";
|
|
2
|
+
import { NetworkingUIEventWrapped, AlertModel, } from "../types/types";
|
|
3
|
+
import { of, BehaviorSubject } from "rxjs";
|
|
4
|
+
describe("CustomerService", () => {
|
|
5
|
+
const config = {
|
|
6
|
+
baseUrl: "https://api.example.com",
|
|
7
|
+
isProd: false,
|
|
8
|
+
clientId: "test-client-id",
|
|
9
|
+
apiKey: "test-api-key",
|
|
10
|
+
};
|
|
11
|
+
let service;
|
|
12
|
+
let $authToken;
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
$authToken = new BehaviorSubject(null);
|
|
15
|
+
service = new CustomerService(config, $authToken);
|
|
16
|
+
});
|
|
17
|
+
it("register success", async () => {
|
|
18
|
+
const payload = {
|
|
19
|
+
email: "test@example.com",
|
|
20
|
+
password: "pass",
|
|
21
|
+
};
|
|
22
|
+
const response = {
|
|
23
|
+
data: { id: 1, email: "test@example.com" },
|
|
24
|
+
};
|
|
25
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
26
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
27
|
+
});
|
|
28
|
+
const result = await service.register(payload).toPromise();
|
|
29
|
+
expect(result?.hasSuccess).toBe(true);
|
|
30
|
+
expect(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: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
39
|
+
});
|
|
40
|
+
const result = await service.register(payload).toPromise();
|
|
41
|
+
expect(result?.hasFailed).toBe(true);
|
|
42
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
43
|
+
});
|
|
44
|
+
it("getProfile success", async () => {
|
|
45
|
+
const response = {
|
|
46
|
+
data: { id: 1, email: "test@example.com" },
|
|
47
|
+
};
|
|
48
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
49
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
50
|
+
});
|
|
51
|
+
const result = await service.getProfile().toPromise();
|
|
52
|
+
expect(result?.hasSuccess).toBe(true);
|
|
53
|
+
expect(result?.response).toEqual(response);
|
|
54
|
+
});
|
|
55
|
+
it("getProfile error", async () => {
|
|
56
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
57
|
+
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
58
|
+
});
|
|
59
|
+
const result = await service.getProfile().toPromise();
|
|
60
|
+
expect(result?.hasFailed).toBe(true);
|
|
61
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
62
|
+
});
|
|
63
|
+
it("updateProfile success", async () => {
|
|
64
|
+
const payload = {
|
|
65
|
+
name: "Test",
|
|
66
|
+
address: "123 Main St",
|
|
67
|
+
postal_code: "12345",
|
|
68
|
+
city: "City",
|
|
69
|
+
state: null,
|
|
70
|
+
country: null,
|
|
71
|
+
contact_email: null,
|
|
72
|
+
phone_number: null,
|
|
73
|
+
};
|
|
74
|
+
const response = { data: { id: 1, name: "Test" } };
|
|
75
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
76
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
77
|
+
});
|
|
78
|
+
const result = await service.updateProfile(payload).toPromise();
|
|
79
|
+
expect(result?.hasSuccess).toBe(true);
|
|
80
|
+
expect(result?.response).toEqual(response);
|
|
81
|
+
});
|
|
82
|
+
it("updateProfile error", async () => {
|
|
83
|
+
const payload = {
|
|
84
|
+
name: "Test",
|
|
85
|
+
address: "123 Main St",
|
|
86
|
+
postal_code: "12345",
|
|
87
|
+
city: "City",
|
|
88
|
+
state: null,
|
|
89
|
+
country: null,
|
|
90
|
+
contact_email: null,
|
|
91
|
+
phone_number: null,
|
|
92
|
+
};
|
|
93
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
94
|
+
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
95
|
+
});
|
|
96
|
+
const result = await service.updateProfile(payload).toPromise();
|
|
97
|
+
expect(result?.hasFailed).toBe(true);
|
|
98
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
99
|
+
});
|
|
100
|
+
it("getCartCollection success", async () => {
|
|
101
|
+
const response = {
|
|
102
|
+
data: { items: [], page: 1, perPage: 24, total: 0 },
|
|
103
|
+
};
|
|
104
|
+
const requestMock = jest
|
|
105
|
+
.fn()
|
|
106
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.succeeded(response)));
|
|
107
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
108
|
+
request: requestMock,
|
|
109
|
+
});
|
|
110
|
+
const query = {
|
|
111
|
+
page: 1,
|
|
112
|
+
per_page: 24,
|
|
113
|
+
status: "confirmed",
|
|
114
|
+
};
|
|
115
|
+
const result = await service.getCartCollection(query).toPromise();
|
|
116
|
+
expect(requestMock).toHaveBeenCalledWith(query);
|
|
117
|
+
expect(result?.hasSuccess).toBe(true);
|
|
118
|
+
expect(result?.response).toEqual(response);
|
|
119
|
+
});
|
|
120
|
+
it("getCartCollection error", async () => {
|
|
121
|
+
const requestMock = jest
|
|
122
|
+
.fn()
|
|
123
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.failed(AlertModel.default())));
|
|
124
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
125
|
+
request: requestMock,
|
|
126
|
+
});
|
|
127
|
+
const query = {
|
|
128
|
+
page: 1,
|
|
129
|
+
per_page: 24,
|
|
130
|
+
};
|
|
131
|
+
const result = await service.getCartCollection(query).toPromise();
|
|
132
|
+
expect(requestMock).toHaveBeenCalledWith(query);
|
|
133
|
+
expect(result?.hasFailed).toBe(true);
|
|
134
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
135
|
+
});
|
|
136
|
+
it("getCustomerProductCollection success", async () => {
|
|
137
|
+
const response = {
|
|
138
|
+
data: { items: [], page: 1, perPage: 24, total: 0 },
|
|
139
|
+
};
|
|
140
|
+
const requestMock = jest
|
|
141
|
+
.fn()
|
|
142
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.succeeded(response)));
|
|
143
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
144
|
+
request: requestMock,
|
|
145
|
+
});
|
|
146
|
+
const query = {
|
|
147
|
+
page: 1,
|
|
148
|
+
per_page: 24,
|
|
149
|
+
};
|
|
150
|
+
const result = await service.getCustomerProductCollection(query).toPromise();
|
|
151
|
+
expect(requestMock).toHaveBeenCalledWith(query);
|
|
152
|
+
expect(result?.hasSuccess).toBe(true);
|
|
153
|
+
expect(result?.response).toEqual(response);
|
|
154
|
+
});
|
|
155
|
+
it("getCustomerProductCollection error", async () => {
|
|
156
|
+
const requestMock = jest
|
|
157
|
+
.fn()
|
|
158
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.failed(AlertModel.default())));
|
|
159
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
160
|
+
request: requestMock,
|
|
161
|
+
});
|
|
162
|
+
const query = {
|
|
163
|
+
page: 1,
|
|
164
|
+
per_page: 24,
|
|
165
|
+
};
|
|
166
|
+
const result = await service.getCustomerProductCollection(query).toPromise();
|
|
167
|
+
expect(requestMock).toHaveBeenCalledWith(query);
|
|
168
|
+
expect(result?.hasFailed).toBe(true);
|
|
169
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
170
|
+
});
|
|
171
|
+
it("createCustomerProduct success", async () => {
|
|
172
|
+
const response = {
|
|
173
|
+
data: { id: "favorite-id", productId: "product-123" },
|
|
174
|
+
};
|
|
175
|
+
const requestMock = jest
|
|
176
|
+
.fn()
|
|
177
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.succeeded(response)));
|
|
178
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
179
|
+
request: requestMock,
|
|
180
|
+
});
|
|
181
|
+
const payload = {
|
|
182
|
+
product_id: "product-123",
|
|
183
|
+
notes: "Customer note for this favorite product",
|
|
184
|
+
};
|
|
185
|
+
const result = await service.createCustomerProduct(payload).toPromise();
|
|
186
|
+
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
187
|
+
expect(result?.hasSuccess).toBe(true);
|
|
188
|
+
expect(result?.response).toEqual(response);
|
|
189
|
+
});
|
|
190
|
+
it("createCustomerProduct error", async () => {
|
|
191
|
+
const requestMock = jest
|
|
192
|
+
.fn()
|
|
193
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.failed(AlertModel.default())));
|
|
194
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
195
|
+
request: requestMock,
|
|
196
|
+
});
|
|
197
|
+
const payload = {
|
|
198
|
+
product_id: "product-123",
|
|
199
|
+
notes: "Customer note for this favorite product",
|
|
200
|
+
};
|
|
201
|
+
const result = await service.createCustomerProduct(payload).toPromise();
|
|
202
|
+
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
203
|
+
expect(result?.hasFailed).toBe(true);
|
|
204
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
205
|
+
});
|
|
206
|
+
it("removeCustomerProduct success", async () => {
|
|
207
|
+
const response = { data: { success: true } };
|
|
208
|
+
const requestMock = jest
|
|
209
|
+
.fn()
|
|
210
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.succeeded(response)));
|
|
211
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
212
|
+
request: requestMock,
|
|
213
|
+
});
|
|
214
|
+
const payload = {
|
|
215
|
+
product_id: "product-123",
|
|
216
|
+
};
|
|
217
|
+
const result = await service.removeCustomerProduct(payload).toPromise();
|
|
218
|
+
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
219
|
+
expect(result?.hasSuccess).toBe(true);
|
|
220
|
+
expect(result?.response).toEqual(response);
|
|
221
|
+
});
|
|
222
|
+
it("removeCustomerProduct error", async () => {
|
|
223
|
+
const requestMock = jest
|
|
224
|
+
.fn()
|
|
225
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.failed(AlertModel.default())));
|
|
226
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
227
|
+
request: requestMock,
|
|
228
|
+
});
|
|
229
|
+
const payload = {
|
|
230
|
+
product_id: "product-123",
|
|
231
|
+
};
|
|
232
|
+
const result = await service.removeCustomerProduct(payload).toPromise();
|
|
233
|
+
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
234
|
+
expect(result?.hasFailed).toBe(true);
|
|
235
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
236
|
+
});
|
|
237
|
+
it("updateCustomerProductNotes success", async () => {
|
|
238
|
+
const response = { data: { success: true } };
|
|
239
|
+
const requestMock = jest
|
|
240
|
+
.fn()
|
|
241
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.succeeded(response)));
|
|
242
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
243
|
+
request: requestMock,
|
|
244
|
+
});
|
|
245
|
+
const payload = {
|
|
246
|
+
product_id: "product-123",
|
|
247
|
+
notes: "Updated note for this favorite product",
|
|
248
|
+
};
|
|
249
|
+
const result = await service
|
|
250
|
+
.updateCustomerProductNotes(payload)
|
|
251
|
+
.toPromise();
|
|
252
|
+
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
253
|
+
expect(result?.hasSuccess).toBe(true);
|
|
254
|
+
expect(result?.response).toEqual(response);
|
|
255
|
+
});
|
|
256
|
+
it("updateCustomerProductNotes error", async () => {
|
|
257
|
+
const requestMock = jest
|
|
258
|
+
.fn()
|
|
259
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.failed(AlertModel.default())));
|
|
260
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
261
|
+
request: requestMock,
|
|
262
|
+
});
|
|
263
|
+
const payload = {
|
|
264
|
+
product_id: "product-123",
|
|
265
|
+
notes: "Updated note for this favorite product",
|
|
266
|
+
};
|
|
267
|
+
const result = await service
|
|
268
|
+
.updateCustomerProductNotes(payload)
|
|
269
|
+
.toPromise();
|
|
270
|
+
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
271
|
+
expect(result?.hasFailed).toBe(true);
|
|
272
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from "../types/types";
|
|
2
|
+
import { SmessService } from "./smess.service";
|
|
3
|
+
import { BehaviorSubject, Observable } from "rxjs";
|
|
4
|
+
export type EmployeeTarget = "get-profile" | "cart-client-collection" | "cart-bulk-action";
|
|
5
|
+
export interface EmployeeCartCollectionQuery {
|
|
6
|
+
page?: number;
|
|
7
|
+
per_page?: number;
|
|
8
|
+
status?: string;
|
|
9
|
+
search?: string;
|
|
10
|
+
sort_by?: string;
|
|
11
|
+
sort_order?: "asc" | "desc";
|
|
12
|
+
}
|
|
13
|
+
export interface EmployeeCartBulkActionRequest {
|
|
14
|
+
create?: Array<{
|
|
15
|
+
cart_id?: string;
|
|
16
|
+
status?: string;
|
|
17
|
+
customer_note?: string;
|
|
18
|
+
customer_id?: string;
|
|
19
|
+
payment_method?: string;
|
|
20
|
+
delivery_type?: string;
|
|
21
|
+
items?: Array<{
|
|
22
|
+
product_id: string;
|
|
23
|
+
quantity: number;
|
|
24
|
+
custom_price?: number;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}>;
|
|
27
|
+
billing_information?: Record<string, unknown>;
|
|
28
|
+
shipping_information?: Record<string, unknown>;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}>;
|
|
31
|
+
update?: Array<{
|
|
32
|
+
cart_id: string;
|
|
33
|
+
status?: string;
|
|
34
|
+
customer_note?: string;
|
|
35
|
+
customer_id?: string;
|
|
36
|
+
payment_method?: string;
|
|
37
|
+
delivery_type?: string;
|
|
38
|
+
items?: Array<{
|
|
39
|
+
product_id: string;
|
|
40
|
+
quantity: number;
|
|
41
|
+
custom_price?: number;
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
}>;
|
|
44
|
+
billing_information?: Record<string, unknown>;
|
|
45
|
+
shipping_information?: Record<string, unknown>;
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}>;
|
|
48
|
+
delete?: Array<{
|
|
49
|
+
cart_id: string;
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}>;
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
export declare class EmployeeProvider implements ProviderType {
|
|
55
|
+
private readonly config;
|
|
56
|
+
private readonly target;
|
|
57
|
+
private readonly $authToken;
|
|
58
|
+
constructor(config: NetworkingConfig, target: EmployeeTarget, $authToken: BehaviorSubject<string | null>);
|
|
59
|
+
get baseURL(): string;
|
|
60
|
+
get path(): string;
|
|
61
|
+
get method(): string;
|
|
62
|
+
get headers(): Record<string, string>;
|
|
63
|
+
getPath(...queryParams: unknown[]): string;
|
|
64
|
+
}
|
|
65
|
+
export declare class EmployeeService {
|
|
66
|
+
private readonly config;
|
|
67
|
+
private readonly $authToken;
|
|
68
|
+
constructor(config: NetworkingConfig, $authToken: BehaviorSubject<string | null>);
|
|
69
|
+
provider(target: EmployeeTarget): SmessService<EmployeeProvider>;
|
|
70
|
+
getProfile(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
71
|
+
getCartCollection(query?: EmployeeCartCollectionQuery): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
72
|
+
bulkCartAction(payload: EmployeeCartBulkActionRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Accept, SMESSHeader, SmessService } from "./smess.service";
|
|
2
|
+
export class EmployeeProvider {
|
|
3
|
+
constructor(config, target, $authToken) {
|
|
4
|
+
this.config = config;
|
|
5
|
+
this.target = target;
|
|
6
|
+
this.$authToken = $authToken;
|
|
7
|
+
}
|
|
8
|
+
get baseURL() {
|
|
9
|
+
return this.config.version
|
|
10
|
+
? `${this.config.baseUrl}/${this.config.version}`
|
|
11
|
+
: this.config.baseUrl;
|
|
12
|
+
}
|
|
13
|
+
get path() {
|
|
14
|
+
switch (this.target) {
|
|
15
|
+
case "get-profile":
|
|
16
|
+
return "/authentication/get-profile";
|
|
17
|
+
case "cart-client-collection":
|
|
18
|
+
return "/store/cart/client/collection";
|
|
19
|
+
case "cart-bulk-action":
|
|
20
|
+
return "/store/cart/bulk-action";
|
|
21
|
+
default:
|
|
22
|
+
return "/authentication/not-found";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
get method() {
|
|
26
|
+
switch (this.target) {
|
|
27
|
+
case "get-profile":
|
|
28
|
+
case "cart-client-collection":
|
|
29
|
+
return "GET";
|
|
30
|
+
case "cart-bulk-action":
|
|
31
|
+
return "POST";
|
|
32
|
+
default:
|
|
33
|
+
return "GET";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
get headers() {
|
|
37
|
+
const headers = SmessService.getHeaders(Accept.V1, this.$authToken.value);
|
|
38
|
+
if (this.config.clientId) {
|
|
39
|
+
headers[SMESSHeader.ClientId] = this.config.clientId;
|
|
40
|
+
}
|
|
41
|
+
if (this.config.apiKey) {
|
|
42
|
+
headers[SMESSHeader.ApiKey] = this.config.apiKey;
|
|
43
|
+
}
|
|
44
|
+
return SmessService.filterHeaders(headers);
|
|
45
|
+
}
|
|
46
|
+
getPath(...queryParams) {
|
|
47
|
+
let definedPath = this.path;
|
|
48
|
+
const params = definedPath.match(/\$\{(.+?)\}/g);
|
|
49
|
+
params?.forEach((value, index) => {
|
|
50
|
+
definedPath = definedPath.replace(value, String(queryParams[index]));
|
|
51
|
+
});
|
|
52
|
+
return definedPath;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export class EmployeeService {
|
|
56
|
+
constructor(config, $authToken) {
|
|
57
|
+
this.config = config;
|
|
58
|
+
this.$authToken = $authToken;
|
|
59
|
+
}
|
|
60
|
+
provider(target) {
|
|
61
|
+
const targetWrapper = new EmployeeProvider(this.config, target, this.$authToken);
|
|
62
|
+
return new SmessService(targetWrapper);
|
|
63
|
+
}
|
|
64
|
+
getProfile() {
|
|
65
|
+
return this.provider("get-profile").request();
|
|
66
|
+
}
|
|
67
|
+
getCartCollection(query) {
|
|
68
|
+
return this.provider("cart-client-collection").request(query);
|
|
69
|
+
}
|
|
70
|
+
bulkCartAction(payload) {
|
|
71
|
+
return this.provider("cart-bulk-action").request(payload);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { EmployeeService, } from "./employee.service";
|
|
2
|
+
import { NetworkingUIEventWrapped, AlertModel, } from "../types/types";
|
|
3
|
+
import { BehaviorSubject, of } from "rxjs";
|
|
4
|
+
describe("EmployeeService", () => {
|
|
5
|
+
const config = {
|
|
6
|
+
baseUrl: "https://api.example.com",
|
|
7
|
+
isProd: false,
|
|
8
|
+
clientId: "test-client-id",
|
|
9
|
+
apiKey: "test-api-key",
|
|
10
|
+
};
|
|
11
|
+
let service;
|
|
12
|
+
let $authToken;
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
$authToken = new BehaviorSubject(null);
|
|
15
|
+
service = new EmployeeService(config, $authToken);
|
|
16
|
+
});
|
|
17
|
+
it("getProfile success", async () => {
|
|
18
|
+
const response = {
|
|
19
|
+
data: { id: "employee-123", email: "employee@example.com" },
|
|
20
|
+
};
|
|
21
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
22
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
23
|
+
});
|
|
24
|
+
const result = await service.getProfile().toPromise();
|
|
25
|
+
expect(result?.hasSuccess).toBe(true);
|
|
26
|
+
expect(result?.response).toEqual(response);
|
|
27
|
+
});
|
|
28
|
+
it("getProfile error", async () => {
|
|
29
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
30
|
+
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
31
|
+
});
|
|
32
|
+
const result = await service.getProfile().toPromise();
|
|
33
|
+
expect(result?.hasFailed).toBe(true);
|
|
34
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
35
|
+
});
|
|
36
|
+
it("getCartCollection success", async () => {
|
|
37
|
+
const response = {
|
|
38
|
+
data: { items: [], page: 1, perPage: 24, total: 0 },
|
|
39
|
+
};
|
|
40
|
+
const requestMock = jest
|
|
41
|
+
.fn()
|
|
42
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.succeeded(response)));
|
|
43
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
44
|
+
request: requestMock,
|
|
45
|
+
});
|
|
46
|
+
const query = {
|
|
47
|
+
page: 1,
|
|
48
|
+
per_page: 24,
|
|
49
|
+
status: "submitted",
|
|
50
|
+
};
|
|
51
|
+
const result = await service.getCartCollection(query).toPromise();
|
|
52
|
+
expect(requestMock).toHaveBeenCalledWith(query);
|
|
53
|
+
expect(result?.hasSuccess).toBe(true);
|
|
54
|
+
expect(result?.response).toEqual(response);
|
|
55
|
+
});
|
|
56
|
+
it("getCartCollection error", async () => {
|
|
57
|
+
const requestMock = jest
|
|
58
|
+
.fn()
|
|
59
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.failed(AlertModel.default())));
|
|
60
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
61
|
+
request: requestMock,
|
|
62
|
+
});
|
|
63
|
+
const query = {
|
|
64
|
+
page: 2,
|
|
65
|
+
per_page: 10,
|
|
66
|
+
};
|
|
67
|
+
const result = await service.getCartCollection(query).toPromise();
|
|
68
|
+
expect(requestMock).toHaveBeenCalledWith(query);
|
|
69
|
+
expect(result?.hasFailed).toBe(true);
|
|
70
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
71
|
+
});
|
|
72
|
+
it("bulkCartAction success", async () => {
|
|
73
|
+
const response = {
|
|
74
|
+
data: { updated: 1 },
|
|
75
|
+
};
|
|
76
|
+
const requestMock = jest
|
|
77
|
+
.fn()
|
|
78
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.succeeded(response)));
|
|
79
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
80
|
+
request: requestMock,
|
|
81
|
+
});
|
|
82
|
+
const payload = {
|
|
83
|
+
update: [
|
|
84
|
+
{
|
|
85
|
+
cart_id: "cart-123",
|
|
86
|
+
status: "submitted",
|
|
87
|
+
items: [
|
|
88
|
+
{
|
|
89
|
+
product_id: "product-1",
|
|
90
|
+
quantity: 2,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
const result = await service.bulkCartAction(payload).toPromise();
|
|
97
|
+
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
98
|
+
expect(result?.hasSuccess).toBe(true);
|
|
99
|
+
expect(result?.response).toEqual(response);
|
|
100
|
+
});
|
|
101
|
+
it("bulkCartAction error", async () => {
|
|
102
|
+
const requestMock = jest
|
|
103
|
+
.fn()
|
|
104
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.failed(AlertModel.default())));
|
|
105
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
106
|
+
request: requestMock,
|
|
107
|
+
});
|
|
108
|
+
const payload = {
|
|
109
|
+
update: [
|
|
110
|
+
{
|
|
111
|
+
cart_id: "cart-456",
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
};
|
|
115
|
+
const result = await service.bulkCartAction(payload).toPromise();
|
|
116
|
+
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
117
|
+
expect(result?.hasFailed).toBe(true);
|
|
118
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare enum LogLevel {
|
|
2
|
+
DEBUG = 0,
|
|
3
|
+
INFO = 1,
|
|
4
|
+
WARN = 2,
|
|
5
|
+
ERROR = 3,
|
|
6
|
+
NONE = 4
|
|
7
|
+
}
|
|
8
|
+
export interface LogEntry {
|
|
9
|
+
level: LogLevel;
|
|
10
|
+
message: string;
|
|
11
|
+
data?: unknown;
|
|
12
|
+
timestamp: number;
|
|
13
|
+
context?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class LoggerService {
|
|
16
|
+
private currentLevel;
|
|
17
|
+
private logs;
|
|
18
|
+
private maxLogs;
|
|
19
|
+
setLogLevel(level: LogLevel): void;
|
|
20
|
+
private shouldLog;
|
|
21
|
+
private formatMessage;
|
|
22
|
+
private getEmojiForLevel;
|
|
23
|
+
private log;
|
|
24
|
+
debug(message: string, data?: unknown, context?: string): void;
|
|
25
|
+
info(message: string, data?: unknown, context?: string): void;
|
|
26
|
+
warn(message: string, data?: unknown, context?: string): void;
|
|
27
|
+
error(message: string, data?: unknown, context?: string): void;
|
|
28
|
+
getLogs(): LogEntry[];
|
|
29
|
+
clearLogs(): void;
|
|
30
|
+
}
|
|
31
|
+
export declare const $logger: LoggerService;
|