@smess/networking 1.0.24 → 1.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/services/employee.service.js +4 -3
- package/dist/src/services/employee.service.test.js +13 -6
- package/dist/src/services/utils/withAuthReset.d.ts +3 -0
- package/dist/src/services/utils/withAuthReset.js +8 -0
- package/package.json +1 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -5,9 +5,11 @@ export * from "./services/store.service";
|
|
|
5
5
|
export * from "./services/store.cart.service";
|
|
6
6
|
export * from "./services/store.product.service";
|
|
7
7
|
export * from "./services/customer.service";
|
|
8
|
+
export * from "./services/employee.service";
|
|
8
9
|
export * from "./services/order.service";
|
|
9
10
|
export * from "./services/cache.service";
|
|
10
11
|
export * from "./services/smess.service";
|
|
12
|
+
export * from "./services/utils/withAuthReset";
|
|
11
13
|
export * from "./core/base.provider";
|
|
12
14
|
export * from "./core/base.service.wrapper";
|
|
13
15
|
export * from "./core/axios.observable";
|
package/dist/src/index.js
CHANGED
|
@@ -5,9 +5,11 @@ export * from "./services/store.service";
|
|
|
5
5
|
export * from "./services/store.cart.service";
|
|
6
6
|
export * from "./services/store.product.service";
|
|
7
7
|
export * from "./services/customer.service";
|
|
8
|
+
export * from "./services/employee.service";
|
|
8
9
|
export * from "./services/order.service";
|
|
9
10
|
export * from "./services/cache.service";
|
|
10
11
|
export * from "./services/smess.service";
|
|
12
|
+
export * from "./services/utils/withAuthReset";
|
|
11
13
|
export * from "./core/base.provider";
|
|
12
14
|
export * from "./core/base.service.wrapper";
|
|
13
15
|
export * from "./core/axios.observable";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Accept, SMESSHeader, SmessService } from "./smess.service";
|
|
2
|
+
import { withAuthReset } from "./utils/withAuthReset";
|
|
2
3
|
export class EmployeeProvider {
|
|
3
4
|
constructor(config, target, $authToken) {
|
|
4
5
|
this.config = config;
|
|
@@ -62,12 +63,12 @@ export class EmployeeService {
|
|
|
62
63
|
return new SmessService(targetWrapper);
|
|
63
64
|
}
|
|
64
65
|
getProfile() {
|
|
65
|
-
return this.provider("get-profile").request();
|
|
66
|
+
return withAuthReset(this.provider("get-profile").request(), this.$authToken);
|
|
66
67
|
}
|
|
67
68
|
getCartCollection(query) {
|
|
68
|
-
return this.provider("cart-client-collection").request(query);
|
|
69
|
+
return withAuthReset(this.provider("cart-client-collection").request(query), this.$authToken);
|
|
69
70
|
}
|
|
70
71
|
bulkCartAction(payload) {
|
|
71
|
-
return this.provider("cart-bulk-action").request(payload);
|
|
72
|
+
return withAuthReset(this.provider("cart-bulk-action").request(payload), this.$authToken);
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -25,13 +25,16 @@ describe("EmployeeService", () => {
|
|
|
25
25
|
expect(result?.hasSuccess).toBe(true);
|
|
26
26
|
expect(result?.response).toEqual(response);
|
|
27
27
|
});
|
|
28
|
-
it("getProfile error", async () => {
|
|
28
|
+
it("getProfile error clears auth token", async () => {
|
|
29
|
+
const alert = new AlertModel("Unauthorized", 401, true);
|
|
30
|
+
$authToken.next("token-123");
|
|
29
31
|
jest.spyOn(service, "provider").mockReturnValue({
|
|
30
|
-
request: () => of(NetworkingUIEventWrapped.failed(
|
|
32
|
+
request: () => of(NetworkingUIEventWrapped.failed(alert)),
|
|
31
33
|
});
|
|
32
34
|
const result = await service.getProfile().toPromise();
|
|
33
35
|
expect(result?.hasFailed).toBe(true);
|
|
34
36
|
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
37
|
+
expect($authToken.value).toBeNull();
|
|
35
38
|
});
|
|
36
39
|
it("getCartCollection success", async () => {
|
|
37
40
|
const response = {
|
|
@@ -53,10 +56,11 @@ describe("EmployeeService", () => {
|
|
|
53
56
|
expect(result?.hasSuccess).toBe(true);
|
|
54
57
|
expect(result?.response).toEqual(response);
|
|
55
58
|
});
|
|
56
|
-
it("getCartCollection error", async () => {
|
|
59
|
+
it("getCartCollection error clears auth token", async () => {
|
|
57
60
|
const requestMock = jest
|
|
58
61
|
.fn()
|
|
59
|
-
.mockReturnValue(of(NetworkingUIEventWrapped.failed(AlertModel
|
|
62
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.failed(new AlertModel("Unauthorized", 401, true))));
|
|
63
|
+
$authToken.next("token-456");
|
|
60
64
|
jest.spyOn(service, "provider").mockReturnValue({
|
|
61
65
|
request: requestMock,
|
|
62
66
|
});
|
|
@@ -68,6 +72,7 @@ describe("EmployeeService", () => {
|
|
|
68
72
|
expect(requestMock).toHaveBeenCalledWith(query);
|
|
69
73
|
expect(result?.hasFailed).toBe(true);
|
|
70
74
|
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
75
|
+
expect($authToken.value).toBeNull();
|
|
71
76
|
});
|
|
72
77
|
it("bulkCartAction success", async () => {
|
|
73
78
|
const response = {
|
|
@@ -98,10 +103,11 @@ describe("EmployeeService", () => {
|
|
|
98
103
|
expect(result?.hasSuccess).toBe(true);
|
|
99
104
|
expect(result?.response).toEqual(response);
|
|
100
105
|
});
|
|
101
|
-
it("bulkCartAction error", async () => {
|
|
106
|
+
it("bulkCartAction error clears auth token", async () => {
|
|
102
107
|
const requestMock = jest
|
|
103
108
|
.fn()
|
|
104
|
-
.mockReturnValue(of(NetworkingUIEventWrapped.failed(AlertModel
|
|
109
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.failed(new AlertModel("Unauthorized", 401, true))));
|
|
110
|
+
$authToken.next("token-789");
|
|
105
111
|
jest.spyOn(service, "provider").mockReturnValue({
|
|
106
112
|
request: requestMock,
|
|
107
113
|
});
|
|
@@ -116,5 +122,6 @@ describe("EmployeeService", () => {
|
|
|
116
122
|
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
117
123
|
expect(result?.hasFailed).toBe(true);
|
|
118
124
|
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
125
|
+
expect($authToken.value).toBeNull();
|
|
119
126
|
});
|
|
120
127
|
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { BehaviorSubject, Observable } from "rxjs";
|
|
2
|
+
import { NetworkingUIEventWrapped } from "../../types/types";
|
|
3
|
+
export declare const withAuthReset: <T>(source$: Observable<NetworkingUIEventWrapped<T>>, $authToken: BehaviorSubject<string | null>) => Observable<NetworkingUIEventWrapped<T>>;
|