@kumori/aurora-backend-handler 1.0.117 → 1.0.119
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.
|
@@ -171,6 +171,24 @@ export const deleteService = async (data: Service, security: string) => {
|
|
|
171
171
|
return response;
|
|
172
172
|
} catch (err) {
|
|
173
173
|
console.error("Error in service deletion WebSocket request:", err);
|
|
174
|
+
const errorInfo = (err as any)?.error;
|
|
175
|
+
const notification: Notification = {
|
|
176
|
+
type: "error",
|
|
177
|
+
subtype: errors.service.deletionError.subtype,
|
|
178
|
+
date: Date.now().toString(),
|
|
179
|
+
info_content: {
|
|
180
|
+
code: errorInfo?.code ?? ((err as any)?.isTimeout ? "_timeout_" : "_unknown_error_"),
|
|
181
|
+
message: errorInfo?.content ?? (err as any)?.message ?? "Unknown error",
|
|
182
|
+
},
|
|
183
|
+
status: "unread",
|
|
184
|
+
callToAction: false,
|
|
185
|
+
data: {
|
|
186
|
+
service: data.name,
|
|
187
|
+
tenant: data.tenant,
|
|
188
|
+
},
|
|
189
|
+
userError: true,
|
|
190
|
+
};
|
|
191
|
+
eventHelper.notification.publish.creation(notification);
|
|
174
192
|
eventHelper.service.publish.deletionError(data);
|
|
175
193
|
throw err;
|
|
176
194
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumori/aurora-backend-handler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.119",
|
|
4
4
|
"description": "backend handler",
|
|
5
5
|
"main": "backend-handler.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"glob": "^11.0.0"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@kumori/aurora-interfaces": "^1.0.
|
|
14
|
+
"@kumori/aurora-interfaces": "^1.0.35",
|
|
15
15
|
"@kumori/kumori-dsl-generator": "1.0.10",
|
|
16
16
|
"@kumori/kumori-module-generator": "^1.1.6",
|
|
17
17
|
"ts-node": "^10.9.2",
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { errors, Service } from "@kumori/aurora-interfaces";
|
|
2
|
+
import { deleteService } from "../api/service-api-service";
|
|
3
|
+
import { makeGlobalWebSocketRequest } from "../websocket-manager";
|
|
4
|
+
|
|
5
|
+
const mockPublishNotification = jest.fn();
|
|
6
|
+
const mockPublishDeletionError = jest.fn();
|
|
7
|
+
|
|
8
|
+
jest.mock("../backend-handler", () => ({
|
|
9
|
+
eventHelper: {
|
|
10
|
+
notification: { publish: { creation: (...args: unknown[]) => mockPublishNotification(...args) } },
|
|
11
|
+
service: { publish: { deletionError: (...args: unknown[]) => mockPublishDeletionError(...args) } },
|
|
12
|
+
},
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
jest.mock("../websocket-manager", () => ({
|
|
16
|
+
initializeGlobalWebSocketClient: jest.fn().mockResolvedValue(undefined),
|
|
17
|
+
getWebSocketStatus: jest.fn(),
|
|
18
|
+
makeGlobalWebSocketRequest: jest.fn(),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
jest.mock("../environment", () => ({ environment: {} }));
|
|
22
|
+
|
|
23
|
+
jest.mock("../api/deploy-service-helper", () => ({
|
|
24
|
+
deployServiceHelper: jest.fn(),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
const service = { name: "my-service", tenant: "my-tenant" } as Service;
|
|
28
|
+
|
|
29
|
+
describe("deleteService", () => {
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
jest.clearAllMocks();
|
|
32
|
+
jest.spyOn(console, "error").mockImplementation(() => undefined);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
jest.restoreAllMocks();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("devuelve la respuesta y no publica errores cuando la petición funciona", async () => {
|
|
40
|
+
(makeGlobalWebSocketRequest as jest.Mock).mockResolvedValue({ ok: true });
|
|
41
|
+
|
|
42
|
+
await expect(deleteService(service, "")).resolves.toEqual({ ok: true });
|
|
43
|
+
|
|
44
|
+
expect(mockPublishNotification).not.toHaveBeenCalled();
|
|
45
|
+
expect(mockPublishDeletionError).not.toHaveBeenCalled();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("publica una notificación de error con el código y el mensaje del backend ante un 409", async () => {
|
|
49
|
+
const backendError = {
|
|
50
|
+
type: "error",
|
|
51
|
+
error: {
|
|
52
|
+
status: 409,
|
|
53
|
+
code: "_invalid_account_credentials_",
|
|
54
|
+
content:
|
|
55
|
+
"The configured credentials for the '/tenant/hegtestdiogo/account/accountcreatedbydiogo' account are invalid: Authentication failed",
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
(makeGlobalWebSocketRequest as jest.Mock).mockRejectedValue(backendError);
|
|
59
|
+
|
|
60
|
+
await expect(deleteService(service, "")).rejects.toBe(backendError);
|
|
61
|
+
|
|
62
|
+
expect(mockPublishNotification).toHaveBeenCalledTimes(1);
|
|
63
|
+
expect(mockPublishNotification).toHaveBeenCalledWith(
|
|
64
|
+
expect.objectContaining({
|
|
65
|
+
type: "error",
|
|
66
|
+
subtype: errors.service.deletionError.subtype,
|
|
67
|
+
status: "unread",
|
|
68
|
+
userError: true,
|
|
69
|
+
info_content: {
|
|
70
|
+
code: "_invalid_account_credentials_",
|
|
71
|
+
message: backendError.error.content,
|
|
72
|
+
},
|
|
73
|
+
data: { service: "my-service", tenant: "my-tenant" },
|
|
74
|
+
})
|
|
75
|
+
);
|
|
76
|
+
expect(mockPublishDeletionError).toHaveBeenCalledWith(service);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("publica una notificación de error con código _timeout_ cuando la petición expira", async () => {
|
|
80
|
+
const timeoutError = Object.assign(new Error("Request timeout for service:delete_service"), { isTimeout: true });
|
|
81
|
+
(makeGlobalWebSocketRequest as jest.Mock).mockRejectedValue(timeoutError);
|
|
82
|
+
|
|
83
|
+
await expect(deleteService(service, "")).rejects.toBe(timeoutError);
|
|
84
|
+
|
|
85
|
+
expect(mockPublishNotification).toHaveBeenCalledWith(
|
|
86
|
+
expect.objectContaining({
|
|
87
|
+
subtype: errors.service.deletionError.subtype,
|
|
88
|
+
info_content: { code: "_timeout_", message: "Request timeout for service:delete_service" },
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
expect(mockPublishDeletionError).toHaveBeenCalledWith(service);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("publica una notificación de error genérica cuando el error no tiene formato del backend", async () => {
|
|
95
|
+
(makeGlobalWebSocketRequest as jest.Mock).mockRejectedValue(new Error("WebSocket connection closed"));
|
|
96
|
+
|
|
97
|
+
await expect(deleteService(service, "")).rejects.toThrow("WebSocket connection closed");
|
|
98
|
+
|
|
99
|
+
expect(mockPublishNotification).toHaveBeenCalledWith(
|
|
100
|
+
expect.objectContaining({
|
|
101
|
+
info_content: { code: "_unknown_error_", message: "WebSocket connection closed" },
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
});
|