@arkyn/server 2.0.1 → 2.0.2
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/package.json +1 -1
- package/dist/api/__test__/deleteRequest.spec.d.ts +0 -2
- package/dist/api/__test__/deleteRequest.spec.d.ts.map +0 -1
- package/dist/api/__test__/deleteRequest.spec.js +0 -84
- package/dist/api/__test__/getRequest.spec.d.ts +0 -2
- package/dist/api/__test__/getRequest.spec.d.ts.map +0 -1
- package/dist/api/__test__/getRequest.spec.js +0 -62
- package/dist/api/__test__/inboxFlowRequest.spec.d.ts +0 -2
- package/dist/api/__test__/inboxFlowRequest.spec.d.ts.map +0 -1
- package/dist/api/__test__/inboxFlowRequest.spec.js +0 -96
- package/dist/api/__test__/makeRequest.spec.d.ts +0 -2
- package/dist/api/__test__/makeRequest.spec.d.ts.map +0 -1
- package/dist/api/__test__/makeRequest.spec.js +0 -80
- package/dist/api/__test__/patchRequest.spec.d.ts +0 -2
- package/dist/api/__test__/patchRequest.spec.d.ts.map +0 -1
- package/dist/api/__test__/patchRequest.spec.js +0 -84
- package/dist/api/__test__/postRequest.spec.d.ts +0 -2
- package/dist/api/__test__/postRequest.spec.d.ts.map +0 -1
- package/dist/api/__test__/postRequest.spec.js +0 -84
- package/dist/api/__test__/putRequest.spec.d.ts +0 -2
- package/dist/api/__test__/putRequest.spec.d.ts.map +0 -1
- package/dist/api/__test__/putRequest.spec.js +0 -84
- package/dist/config/__test__/apiInstance.spec.d.ts +0 -2
- package/dist/config/__test__/apiInstance.spec.d.ts.map +0 -1
- package/dist/config/__test__/apiInstance.spec.js +0 -86
- package/dist/config/__test__/inboxFlowInstance.spec.d.ts +0 -2
- package/dist/config/__test__/inboxFlowInstance.spec.d.ts.map +0 -1
- package/dist/config/__test__/inboxFlowInstance.spec.js +0 -48
- package/dist/http/badResponses/__test__/badGateway.spec.d.ts +0 -2
- package/dist/http/badResponses/__test__/badGateway.spec.d.ts.map +0 -1
- package/dist/http/badResponses/__test__/badGateway.spec.js +0 -42
- package/dist/http/badResponses/__test__/badRequest.spec.d.ts +0 -2
- package/dist/http/badResponses/__test__/badRequest.spec.d.ts.map +0 -1
- package/dist/http/badResponses/__test__/badRequest.spec.js +0 -40
- package/dist/http/badResponses/__test__/conflict.spec.d.ts +0 -2
- package/dist/http/badResponses/__test__/conflict.spec.d.ts.map +0 -1
- package/dist/http/badResponses/__test__/conflict.spec.js +0 -40
- package/dist/http/badResponses/__test__/forbidden.spec.d.ts +0 -2
- package/dist/http/badResponses/__test__/forbidden.spec.d.ts.map +0 -1
- package/dist/http/badResponses/__test__/forbidden.spec.js +0 -40
- package/dist/http/badResponses/__test__/notFound.spec.d.ts +0 -2
- package/dist/http/badResponses/__test__/notFound.spec.d.ts.map +0 -1
- package/dist/http/badResponses/__test__/notFound.spec.js +0 -40
- package/dist/http/badResponses/__test__/notImplemented.spec.d.ts +0 -2
- package/dist/http/badResponses/__test__/notImplemented.spec.d.ts.map +0 -1
- package/dist/http/badResponses/__test__/notImplemented.spec.js +0 -40
- package/dist/http/badResponses/__test__/serverError.spec.d.ts +0 -2
- package/dist/http/badResponses/__test__/serverError.spec.d.ts.map +0 -1
- package/dist/http/badResponses/__test__/serverError.spec.js +0 -40
- package/dist/http/badResponses/__test__/unauthorized.spec.d.ts +0 -2
- package/dist/http/badResponses/__test__/unauthorized.spec.d.ts.map +0 -1
- package/dist/http/badResponses/__test__/unauthorized.spec.js +0 -40
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.d.ts +0 -2
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.d.ts.map +0 -1
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.js +0 -66
- package/dist/http/successResponses/__test__/created.spec.d.ts +0 -2
- package/dist/http/successResponses/__test__/created.spec.d.ts.map +0 -1
- package/dist/http/successResponses/__test__/created.spec.js +0 -57
- package/dist/http/successResponses/__test__/found.spec.d.ts +0 -2
- package/dist/http/successResponses/__test__/found.spec.d.ts.map +0 -1
- package/dist/http/successResponses/__test__/found.spec.js +0 -57
- package/dist/http/successResponses/__test__/noContent.spec.d.ts +0 -2
- package/dist/http/successResponses/__test__/noContent.spec.d.ts.map +0 -1
- package/dist/http/successResponses/__test__/noContent.spec.js +0 -40
- package/dist/http/successResponses/__test__/success.spec.d.ts +0 -2
- package/dist/http/successResponses/__test__/success.spec.d.ts.map +0 -1
- package/dist/http/successResponses/__test__/success.spec.js +0 -60
- package/dist/http/successResponses/__test__/updated.spec.d.ts +0 -2
- package/dist/http/successResponses/__test__/updated.spec.d.ts.map +0 -1
- package/dist/http/successResponses/__test__/updated.spec.js +0 -60
- package/dist/services/__test__/decodeRequestBody.spec.d.ts +0 -2
- package/dist/services/__test__/decodeRequestBody.spec.d.ts.map +0 -1
- package/dist/services/__test__/decodeRequestBody.spec.js +0 -39
- package/dist/services/__test__/errorHandler.spec.d.ts +0 -2
- package/dist/services/__test__/errorHandler.spec.d.ts.map +0 -1
- package/dist/services/__test__/errorHandler.spec.js +0 -115
- package/dist/services/__test__/formParse.spec.d.ts +0 -2
- package/dist/services/__test__/formParse.spec.d.ts.map +0 -1
- package/dist/services/__test__/formParse.spec.js +0 -78
- package/dist/services/__test__/getCaller.spec.d.ts +0 -2
- package/dist/services/__test__/getCaller.spec.d.ts.map +0 -1
- package/dist/services/__test__/getCaller.spec.js +0 -60
- package/dist/services/__test__/getScopedParams.spec.d.ts +0 -2
- package/dist/services/__test__/getScopedParams.spec.d.ts.map +0 -1
- package/dist/services/__test__/getScopedParams.spec.js +0 -51
- package/dist/services/__test__/schemaValidator.spec.d.ts +0 -2
- package/dist/services/__test__/schemaValidator.spec.d.ts.map +0 -1
- package/dist/services/__test__/schemaValidator.spec.js +0 -89
- package/src/api/__test__/deleteRequest.spec.ts +0 -107
- package/src/api/__test__/getRequest.spec.ts +0 -76
- package/src/api/__test__/inboxFlowRequest.spec.ts +0 -125
- package/src/api/__test__/makeRequest.spec.ts +0 -121
- package/src/api/__test__/patchRequest.spec.ts +0 -125
- package/src/api/__test__/postRequest.spec.ts +0 -125
- package/src/api/__test__/putRequest.spec.ts +0 -125
- package/src/config/__test__/apiInstance.spec.ts +0 -129
- package/src/config/__test__/inboxFlowInstance.spec.ts +0 -61
- package/src/http/badResponses/__test__/badGateway.spec.ts +0 -50
- package/src/http/badResponses/__test__/badRequest.spec.ts +0 -50
- package/src/http/badResponses/__test__/conflict.spec.ts +0 -50
- package/src/http/badResponses/__test__/forbidden.spec.ts +0 -50
- package/src/http/badResponses/__test__/notFound.spec.ts +0 -50
- package/src/http/badResponses/__test__/notImplemented.spec.ts +0 -50
- package/src/http/badResponses/__test__/serverError.spec.ts +0 -50
- package/src/http/badResponses/__test__/unauthorized.spec.ts +0 -50
- package/src/http/badResponses/__test__/unprocessableEntity.spec.ts +0 -76
- package/src/http/successResponses/__test__/created.spec.ts +0 -65
- package/src/http/successResponses/__test__/found.spec.ts +0 -65
- package/src/http/successResponses/__test__/noContent.spec.ts +0 -49
- package/src/http/successResponses/__test__/success.spec.ts +0 -68
- package/src/http/successResponses/__test__/updated.spec.ts +0 -68
- package/src/services/__test__/decodeRequestBody.spec.ts +0 -51
- package/src/services/__test__/errorHandler.spec.ts +0 -133
- package/src/services/__test__/formParse.spec.ts +0 -96
- package/src/services/__test__/getCaller.spec.ts +0 -78
- package/src/services/__test__/getScopedParams.spec.ts +0 -68
- package/src/services/__test__/schemaValidator.spec.ts +0 -106
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { patchRequest } from "../patchRequest";
|
|
3
|
-
|
|
4
|
-
global.fetch = vi.fn() as any;
|
|
5
|
-
|
|
6
|
-
describe("patchRequest", () => {
|
|
7
|
-
it("should return success response for a successful patch request", async () => {
|
|
8
|
-
const mockResponse = { message: "Resource updated successfully" };
|
|
9
|
-
const mockBody = { name: "Updated Name" };
|
|
10
|
-
|
|
11
|
-
(fetch as any).mockResolvedValueOnce({
|
|
12
|
-
ok: true,
|
|
13
|
-
status: 200,
|
|
14
|
-
json: async () => mockResponse,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const response = await patchRequest(
|
|
18
|
-
"https://api.example.com/resource",
|
|
19
|
-
{ "Content-Type": "application/json" },
|
|
20
|
-
mockBody
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
expect(response).toEqual({
|
|
24
|
-
success: true,
|
|
25
|
-
status: 200,
|
|
26
|
-
message: "Resource updated successfully",
|
|
27
|
-
response: mockResponse,
|
|
28
|
-
cause: null,
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("should return failed response for a failed patch request", async () => {
|
|
33
|
-
const mockErrorResponse = { error: "Resource not found" };
|
|
34
|
-
const mockBody = { name: "Updated Name" };
|
|
35
|
-
|
|
36
|
-
(fetch as any).mockResolvedValueOnce({
|
|
37
|
-
ok: false,
|
|
38
|
-
status: 404,
|
|
39
|
-
json: async () => mockErrorResponse,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const response = await patchRequest(
|
|
43
|
-
"https://api.example.com/resource",
|
|
44
|
-
{ "Content-Type": "application/json" },
|
|
45
|
-
mockBody
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
expect(response.success).toBe(false);
|
|
49
|
-
expect(response.status).toBe(404);
|
|
50
|
-
expect(response.response).toEqual(mockErrorResponse);
|
|
51
|
-
expect(response.message).toBeDefined();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should handle network errors gracefully", async () => {
|
|
55
|
-
const mockBody = { name: "Updated Name" };
|
|
56
|
-
|
|
57
|
-
(fetch as any).mockRejectedValueOnce(new Error("Network Error"));
|
|
58
|
-
|
|
59
|
-
const response = await patchRequest(
|
|
60
|
-
"https://api.example.com/resource",
|
|
61
|
-
{ "Content-Type": "application/json" },
|
|
62
|
-
mockBody
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
expect(response).toEqual({
|
|
66
|
-
success: false,
|
|
67
|
-
status: 0,
|
|
68
|
-
message: "Network error or request failed",
|
|
69
|
-
response: null,
|
|
70
|
-
cause: "Network Error",
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("should handle invalid JSON response gracefully", async () => {
|
|
75
|
-
const mockBody = { name: "Updated Name" };
|
|
76
|
-
|
|
77
|
-
(fetch as any).mockResolvedValueOnce({
|
|
78
|
-
ok: true,
|
|
79
|
-
status: 200,
|
|
80
|
-
json: async () => {
|
|
81
|
-
throw new Error("Invalid JSON");
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const response = await patchRequest(
|
|
86
|
-
"https://api.example.com/resource",
|
|
87
|
-
{ "Content-Type": "application/json" },
|
|
88
|
-
mockBody
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
expect(response).toEqual({
|
|
92
|
-
success: true,
|
|
93
|
-
status: 200,
|
|
94
|
-
message: "Resource patched successfully",
|
|
95
|
-
response: null,
|
|
96
|
-
cause: null,
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("should send headers and body correctly", async () => {
|
|
101
|
-
const mockResponse = { message: "Resource updated successfully" };
|
|
102
|
-
const mockBody = { name: "Updated Name" };
|
|
103
|
-
const mockHeaders = { Authorization: "Bearer token" };
|
|
104
|
-
|
|
105
|
-
(fetch as any).mockResolvedValueOnce({
|
|
106
|
-
ok: true,
|
|
107
|
-
status: 200,
|
|
108
|
-
json: async () => mockResponse,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const response = await patchRequest(
|
|
112
|
-
"https://api.example.com/resource",
|
|
113
|
-
mockHeaders,
|
|
114
|
-
mockBody
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
expect(response).toEqual({
|
|
118
|
-
success: true,
|
|
119
|
-
status: 200,
|
|
120
|
-
message: "Resource updated successfully",
|
|
121
|
-
response: mockResponse,
|
|
122
|
-
cause: null,
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { postRequest } from "../postRequest";
|
|
3
|
-
|
|
4
|
-
global.fetch = vi.fn() as any;
|
|
5
|
-
|
|
6
|
-
describe("postRequest", () => {
|
|
7
|
-
it("should return success response for a successful POST request", async () => {
|
|
8
|
-
const mockResponse = { message: "Resource created successfully" };
|
|
9
|
-
const mockBody = { name: "New Resource" };
|
|
10
|
-
|
|
11
|
-
(fetch as any).mockResolvedValueOnce({
|
|
12
|
-
ok: true,
|
|
13
|
-
status: 201,
|
|
14
|
-
json: async () => mockResponse,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const response = await postRequest(
|
|
18
|
-
"https://api.example.com/resource",
|
|
19
|
-
{ "Content-Type": "application/json" },
|
|
20
|
-
mockBody
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
expect(response).toEqual({
|
|
24
|
-
success: true,
|
|
25
|
-
status: 201,
|
|
26
|
-
message: "Resource created successfully",
|
|
27
|
-
response: mockResponse,
|
|
28
|
-
cause: null,
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("should return failed response for a failed POST request", async () => {
|
|
33
|
-
const mockErrorResponse = { error: "Invalid data" };
|
|
34
|
-
const mockBody = { name: "" };
|
|
35
|
-
|
|
36
|
-
(fetch as any).mockResolvedValueOnce({
|
|
37
|
-
ok: false,
|
|
38
|
-
status: 400,
|
|
39
|
-
json: async () => mockErrorResponse,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const response = await postRequest(
|
|
43
|
-
"https://api.example.com/resource",
|
|
44
|
-
{ "Content-Type": "application/json" },
|
|
45
|
-
mockBody
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
expect(response.success).toBe(false);
|
|
49
|
-
expect(response.status).toBe(400);
|
|
50
|
-
expect(response.response).toEqual(mockErrorResponse);
|
|
51
|
-
expect(response.message).toBeDefined();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should handle network errors gracefully", async () => {
|
|
55
|
-
const mockBody = { name: "New Resource" };
|
|
56
|
-
|
|
57
|
-
(fetch as any).mockRejectedValueOnce(new Error("Network Error"));
|
|
58
|
-
|
|
59
|
-
const response = await postRequest(
|
|
60
|
-
"https://api.example.com/resource",
|
|
61
|
-
{ "Content-Type": "application/json" },
|
|
62
|
-
mockBody
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
expect(response).toEqual({
|
|
66
|
-
success: false,
|
|
67
|
-
status: 0,
|
|
68
|
-
message: "Network error or request failed",
|
|
69
|
-
response: null,
|
|
70
|
-
cause: "Network Error",
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("should handle invalid JSON response gracefully", async () => {
|
|
75
|
-
const mockBody = { name: "New Resource" };
|
|
76
|
-
|
|
77
|
-
(fetch as any).mockResolvedValueOnce({
|
|
78
|
-
ok: true,
|
|
79
|
-
status: 201,
|
|
80
|
-
json: async () => {
|
|
81
|
-
throw new Error("Invalid JSON");
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const response = await postRequest(
|
|
86
|
-
"https://api.example.com/resource",
|
|
87
|
-
{ "Content-Type": "application/json" },
|
|
88
|
-
mockBody
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
expect(response).toEqual({
|
|
92
|
-
success: true,
|
|
93
|
-
status: 201,
|
|
94
|
-
message: "Resource created successfully",
|
|
95
|
-
response: null,
|
|
96
|
-
cause: null,
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("should send headers and body correctly", async () => {
|
|
101
|
-
const mockResponse = { message: "Resource created successfully" };
|
|
102
|
-
const mockBody = { name: "New Resource" };
|
|
103
|
-
const mockHeaders = { Authorization: "Bearer token" };
|
|
104
|
-
|
|
105
|
-
(fetch as any).mockResolvedValueOnce({
|
|
106
|
-
ok: true,
|
|
107
|
-
status: 201,
|
|
108
|
-
json: async () => mockResponse,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const response = await postRequest(
|
|
112
|
-
"https://api.example.com/resource",
|
|
113
|
-
mockHeaders,
|
|
114
|
-
mockBody
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
expect(response).toEqual({
|
|
118
|
-
success: true,
|
|
119
|
-
status: 201,
|
|
120
|
-
message: "Resource created successfully",
|
|
121
|
-
response: mockResponse,
|
|
122
|
-
cause: null,
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { putRequest } from "../putRequest";
|
|
3
|
-
|
|
4
|
-
global.fetch = vi.fn() as any;
|
|
5
|
-
|
|
6
|
-
describe("putRequest", () => {
|
|
7
|
-
it("should return success response for a successful PUT request", async () => {
|
|
8
|
-
const mockResponse = { message: "Resource updated successfully" };
|
|
9
|
-
const mockBody = { name: "Updated Resource" };
|
|
10
|
-
|
|
11
|
-
(fetch as any).mockResolvedValueOnce({
|
|
12
|
-
ok: true,
|
|
13
|
-
status: 200,
|
|
14
|
-
json: async () => mockResponse,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const response = await putRequest(
|
|
18
|
-
"https://api.example.com/resource",
|
|
19
|
-
{ "Content-Type": "application/json" },
|
|
20
|
-
mockBody
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
expect(response).toEqual({
|
|
24
|
-
success: true,
|
|
25
|
-
status: 200,
|
|
26
|
-
message: "Resource updated successfully",
|
|
27
|
-
response: mockResponse,
|
|
28
|
-
cause: null,
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("should return failed response for a failed PUT request", async () => {
|
|
33
|
-
const mockErrorResponse = { error: "Invalid data" };
|
|
34
|
-
const mockBody = { name: "" };
|
|
35
|
-
|
|
36
|
-
(fetch as any).mockResolvedValueOnce({
|
|
37
|
-
ok: false,
|
|
38
|
-
status: 400,
|
|
39
|
-
json: async () => mockErrorResponse,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const response = await putRequest(
|
|
43
|
-
"https://api.example.com/resource",
|
|
44
|
-
{ "Content-Type": "application/json" },
|
|
45
|
-
mockBody
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
expect(response.success).toBe(false);
|
|
49
|
-
expect(response.status).toBe(400);
|
|
50
|
-
expect(response.response).toEqual(mockErrorResponse);
|
|
51
|
-
expect(response.message).toBeDefined();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should handle network errors gracefully", async () => {
|
|
55
|
-
const mockBody = { name: "Updated Resource" };
|
|
56
|
-
|
|
57
|
-
(fetch as any).mockRejectedValueOnce(new Error("Network Error"));
|
|
58
|
-
|
|
59
|
-
const response = await putRequest(
|
|
60
|
-
"https://api.example.com/resource",
|
|
61
|
-
{ "Content-Type": "application/json" },
|
|
62
|
-
mockBody
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
expect(response).toEqual({
|
|
66
|
-
success: false,
|
|
67
|
-
status: 0,
|
|
68
|
-
message: "Network error or request failed",
|
|
69
|
-
response: null,
|
|
70
|
-
cause: "Network Error",
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("should handle invalid JSON response gracefully", async () => {
|
|
75
|
-
const mockBody = { name: "Updated Resource" };
|
|
76
|
-
|
|
77
|
-
(fetch as any).mockResolvedValueOnce({
|
|
78
|
-
ok: true,
|
|
79
|
-
status: 200,
|
|
80
|
-
json: async () => {
|
|
81
|
-
throw new Error("Invalid JSON");
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const response = await putRequest(
|
|
86
|
-
"https://api.example.com/resource",
|
|
87
|
-
{ "Content-Type": "application/json" },
|
|
88
|
-
mockBody
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
expect(response).toEqual({
|
|
92
|
-
success: true,
|
|
93
|
-
status: 200,
|
|
94
|
-
message: "Resource updated successfully",
|
|
95
|
-
response: null,
|
|
96
|
-
cause: null,
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("should send headers and body correctly", async () => {
|
|
101
|
-
const mockResponse = { message: "Resource updated successfully" };
|
|
102
|
-
const mockBody = { name: "Updated Resource" };
|
|
103
|
-
const mockHeaders = { Authorization: "Bearer token" };
|
|
104
|
-
|
|
105
|
-
(fetch as any).mockResolvedValueOnce({
|
|
106
|
-
ok: true,
|
|
107
|
-
status: 200,
|
|
108
|
-
json: async () => mockResponse,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const response = await putRequest(
|
|
112
|
-
"https://api.example.com/resource",
|
|
113
|
-
mockHeaders,
|
|
114
|
-
mockBody
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
expect(response).toEqual({
|
|
118
|
-
success: true,
|
|
119
|
-
status: 200,
|
|
120
|
-
message: "Resource updated successfully",
|
|
121
|
-
response: mockResponse,
|
|
122
|
-
cause: null,
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { ApiInstance } from "../apiInstance";
|
|
3
|
-
import { getRequest } from "../../api/getRequest";
|
|
4
|
-
import { postRequest } from "../../api/postRequest";
|
|
5
|
-
import { putRequest } from "../../api/putRequest";
|
|
6
|
-
import { patchRequest } from "../../api/patchRequest";
|
|
7
|
-
import { deleteRequest } from "../../api/deleteRequest";
|
|
8
|
-
|
|
9
|
-
vi.mock("../../api/getRequest");
|
|
10
|
-
vi.mock("../../api/postRequest");
|
|
11
|
-
vi.mock("../../api/putRequest");
|
|
12
|
-
vi.mock("../../api/patchRequest");
|
|
13
|
-
vi.mock("../../api/deleteRequest");
|
|
14
|
-
|
|
15
|
-
describe("ApiInstance", () => {
|
|
16
|
-
const baseUrl = "https://api.example.com";
|
|
17
|
-
const baseHeaders = { "Content-Type": "application/json" };
|
|
18
|
-
const baseToken = "base-token";
|
|
19
|
-
|
|
20
|
-
const apiInstance = new ApiInstance({
|
|
21
|
-
baseUrl,
|
|
22
|
-
baseHeaders,
|
|
23
|
-
baseToken,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should send a GET request with correct headers and URL", async () => {
|
|
27
|
-
const mockResponse = { success: true, data: "GET response" };
|
|
28
|
-
(getRequest as any).mockResolvedValueOnce(mockResponse);
|
|
29
|
-
|
|
30
|
-
const response = await apiInstance.GET("/resource", {});
|
|
31
|
-
|
|
32
|
-
expect(getRequest).toHaveBeenCalledWith(
|
|
33
|
-
`${baseUrl}/resource`,
|
|
34
|
-
expect.objectContaining({
|
|
35
|
-
Authorization: `Bearer ${baseToken}`,
|
|
36
|
-
"Content-Type": "application/json",
|
|
37
|
-
})
|
|
38
|
-
);
|
|
39
|
-
expect(response).toEqual(mockResponse);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("should send a POST request with correct headers, URL, and body", async () => {
|
|
43
|
-
const mockResponse = { success: true, data: "POST response" };
|
|
44
|
-
const mockBody = { name: "New Resource" };
|
|
45
|
-
(postRequest as any).mockResolvedValueOnce(mockResponse);
|
|
46
|
-
|
|
47
|
-
const response = await apiInstance.POST("/resource", { body: mockBody });
|
|
48
|
-
|
|
49
|
-
expect(postRequest).toHaveBeenCalledWith(
|
|
50
|
-
`${baseUrl}/resource`,
|
|
51
|
-
expect.objectContaining({
|
|
52
|
-
Authorization: `Bearer ${baseToken}`,
|
|
53
|
-
"Content-Type": "application/json",
|
|
54
|
-
}),
|
|
55
|
-
mockBody
|
|
56
|
-
);
|
|
57
|
-
expect(response).toEqual(mockResponse);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("should send a PUT request with correct headers, URL, and body", async () => {
|
|
61
|
-
const mockResponse = { success: true, data: "PUT response" };
|
|
62
|
-
const mockBody = { name: "Updated Resource" };
|
|
63
|
-
(putRequest as any).mockResolvedValueOnce(mockResponse);
|
|
64
|
-
|
|
65
|
-
const response = await apiInstance.PUT("/resource", { body: mockBody });
|
|
66
|
-
|
|
67
|
-
expect(putRequest).toHaveBeenCalledWith(
|
|
68
|
-
`${baseUrl}/resource`,
|
|
69
|
-
expect.objectContaining({
|
|
70
|
-
Authorization: `Bearer ${baseToken}`,
|
|
71
|
-
"Content-Type": "application/json",
|
|
72
|
-
}),
|
|
73
|
-
mockBody
|
|
74
|
-
);
|
|
75
|
-
expect(response).toEqual(mockResponse);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("should send a PATCH request with correct headers, URL, and body", async () => {
|
|
79
|
-
const mockResponse = { success: true, data: "PATCH response" };
|
|
80
|
-
const mockBody = { name: "Partially Updated Resource" };
|
|
81
|
-
(patchRequest as any).mockResolvedValueOnce(mockResponse);
|
|
82
|
-
|
|
83
|
-
const response = await apiInstance.PATCH("/resource", { body: mockBody });
|
|
84
|
-
|
|
85
|
-
expect(patchRequest).toHaveBeenCalledWith(
|
|
86
|
-
`${baseUrl}/resource`,
|
|
87
|
-
expect.objectContaining({
|
|
88
|
-
Authorization: `Bearer ${baseToken}`,
|
|
89
|
-
"Content-Type": "application/json",
|
|
90
|
-
}),
|
|
91
|
-
mockBody
|
|
92
|
-
);
|
|
93
|
-
expect(response).toEqual(mockResponse);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("should send a DELETE request with correct headers, URL, and body", async () => {
|
|
97
|
-
const mockResponse = { success: true, data: "DELETE response" };
|
|
98
|
-
const mockBody = { id: 1 };
|
|
99
|
-
(deleteRequest as any).mockResolvedValueOnce(mockResponse);
|
|
100
|
-
|
|
101
|
-
const response = await apiInstance.DELETE("/resource", { body: mockBody });
|
|
102
|
-
|
|
103
|
-
expect(deleteRequest).toHaveBeenCalledWith(
|
|
104
|
-
`${baseUrl}/resource`,
|
|
105
|
-
expect.objectContaining({
|
|
106
|
-
Authorization: `Bearer ${baseToken}`,
|
|
107
|
-
"Content-Type": "application/json",
|
|
108
|
-
}),
|
|
109
|
-
mockBody
|
|
110
|
-
);
|
|
111
|
-
expect(response).toEqual(mockResponse);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it("should override base token with provided token", async () => {
|
|
115
|
-
const mockResponse = { success: true, data: "GET response with token" };
|
|
116
|
-
(getRequest as any).mockResolvedValueOnce(mockResponse);
|
|
117
|
-
|
|
118
|
-
const response = await apiInstance.GET("/resource", { token: "new-token" });
|
|
119
|
-
|
|
120
|
-
expect(getRequest).toHaveBeenCalledWith(
|
|
121
|
-
`${baseUrl}/resource`,
|
|
122
|
-
expect.objectContaining({
|
|
123
|
-
Authorization: `Bearer new-token`,
|
|
124
|
-
"Content-Type": "application/json",
|
|
125
|
-
})
|
|
126
|
-
);
|
|
127
|
-
expect(response).toEqual(mockResponse);
|
|
128
|
-
});
|
|
129
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { InboxFlowInstance } from "../inboxFlowInstance";
|
|
3
|
-
|
|
4
|
-
describe("InboxFlowInstance", () => {
|
|
5
|
-
it("should set the inbox configuration if not already set", () => {
|
|
6
|
-
const inboxConfig = {
|
|
7
|
-
inboxChannelId: "channel-123",
|
|
8
|
-
inboxUserToken: "user-token-abc",
|
|
9
|
-
inboxApiUrl: "https://custom-inbox-api.com",
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
InboxFlowInstance.setInboxConfig(inboxConfig);
|
|
13
|
-
|
|
14
|
-
const config = InboxFlowInstance.getInboxConfig();
|
|
15
|
-
expect(config).toEqual(inboxConfig);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("should not overwrite the inbox configuration if already set", () => {
|
|
19
|
-
const initialConfig = {
|
|
20
|
-
inboxChannelId: "channel-123",
|
|
21
|
-
inboxUserToken: "user-token-abc",
|
|
22
|
-
inboxApiUrl: "https://custom-inbox-api.com",
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const newConfig = {
|
|
26
|
-
inboxChannelId: "channel-456",
|
|
27
|
-
inboxUserToken: "user-token-def",
|
|
28
|
-
inboxApiUrl: "https://another-inbox-api.com",
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
InboxFlowInstance.setInboxConfig(initialConfig);
|
|
32
|
-
InboxFlowInstance.setInboxConfig(newConfig);
|
|
33
|
-
|
|
34
|
-
const config = InboxFlowInstance.getInboxConfig();
|
|
35
|
-
expect(config).toEqual(initialConfig);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("should return undefined if no configuration is set", () => {
|
|
39
|
-
InboxFlowInstance.resetInboxConfig();
|
|
40
|
-
|
|
41
|
-
const config = InboxFlowInstance.getInboxConfig();
|
|
42
|
-
expect(config).toBeUndefined();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("should use the default API URL if none is provided", () => {
|
|
46
|
-
const inboxConfig = {
|
|
47
|
-
inboxChannelId: "channel-123",
|
|
48
|
-
inboxUserToken: "user-token-abc",
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const defaultInboxURL = `https://logs-inbox-flow-logs.vw6wo7.easypanel.host/api/call`;
|
|
52
|
-
|
|
53
|
-
InboxFlowInstance.setInboxConfig(inboxConfig);
|
|
54
|
-
|
|
55
|
-
const config = InboxFlowInstance.getInboxConfig();
|
|
56
|
-
expect(config).toEqual({
|
|
57
|
-
...inboxConfig,
|
|
58
|
-
inboxApiUrl: defaultInboxURL,
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { BadGateway } from "../badGateway";
|
|
3
|
-
|
|
4
|
-
describe("BadGateway", () => {
|
|
5
|
-
it("should create an instance with the correct properties", () => {
|
|
6
|
-
const message = "Bad Gateway error occurred";
|
|
7
|
-
const cause = { reason: "Upstream server is down" };
|
|
8
|
-
const error = new BadGateway(message, cause);
|
|
9
|
-
|
|
10
|
-
expect(error.body).toEqual({ name: "BadGateway", message });
|
|
11
|
-
expect(error.status).toBe(502);
|
|
12
|
-
expect(error.statusText).toBe(message);
|
|
13
|
-
expect(error.cause).toBe(JSON.stringify(cause));
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("should create an instance without a cause", () => {
|
|
17
|
-
const message = "Bad Gateway error occurred";
|
|
18
|
-
const error = new BadGateway(message);
|
|
19
|
-
|
|
20
|
-
expect(error.body).toEqual({ name: "BadGateway", message });
|
|
21
|
-
expect(error.status).toBe(502);
|
|
22
|
-
expect(error.statusText).toBe(message);
|
|
23
|
-
expect(error.cause).toBeUndefined();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should return a Response object from toResponse", () => {
|
|
27
|
-
const message = "Bad Gateway error occurred";
|
|
28
|
-
const error = new BadGateway(message);
|
|
29
|
-
const response = error.toResponse();
|
|
30
|
-
|
|
31
|
-
expect(response.status).toBe(502);
|
|
32
|
-
expect(response.statusText).toBe(message);
|
|
33
|
-
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
34
|
-
response.json().then((body) => {
|
|
35
|
-
expect(body).toEqual({ name: "BadGateway", message });
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should return a Response object from toJson", () => {
|
|
40
|
-
const message = "Bad Gateway error occurred";
|
|
41
|
-
const error = new BadGateway(message);
|
|
42
|
-
const response = error.toJson();
|
|
43
|
-
|
|
44
|
-
expect(response.status).toBe(502);
|
|
45
|
-
expect(response.statusText).toBe(message);
|
|
46
|
-
response.json().then((body) => {
|
|
47
|
-
expect(body).toEqual({ name: "BadGateway", message });
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { BadRequest } from "../badRequest";
|
|
3
|
-
|
|
4
|
-
describe("BadRequest", () => {
|
|
5
|
-
it("should create an instance with the correct properties", () => {
|
|
6
|
-
const message = "Invalid request data";
|
|
7
|
-
const cause = { field: "email", error: "Invalid format" };
|
|
8
|
-
const error = new BadRequest(message, cause);
|
|
9
|
-
|
|
10
|
-
expect(error.body).toEqual({ name: "BadRequest", message });
|
|
11
|
-
expect(error.status).toBe(400);
|
|
12
|
-
expect(error.statusText).toBe(message);
|
|
13
|
-
expect(error.cause).toBe(JSON.stringify(cause));
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("should create an instance without a cause", () => {
|
|
17
|
-
const message = "Invalid request data";
|
|
18
|
-
const error = new BadRequest(message);
|
|
19
|
-
|
|
20
|
-
expect(error.body).toEqual({ name: "BadRequest", message });
|
|
21
|
-
expect(error.status).toBe(400);
|
|
22
|
-
expect(error.statusText).toBe(message);
|
|
23
|
-
expect(error.cause).toBeUndefined();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should return a Response object from toResponse", async () => {
|
|
27
|
-
const message = "Invalid request data";
|
|
28
|
-
const error = new BadRequest(message);
|
|
29
|
-
const response = error.toResponse();
|
|
30
|
-
|
|
31
|
-
expect(response.status).toBe(400);
|
|
32
|
-
expect(response.statusText).toBe(message);
|
|
33
|
-
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
34
|
-
|
|
35
|
-
const body = await response.json();
|
|
36
|
-
expect(body).toEqual({ name: "BadRequest", message });
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should return a Response object from toJson", async () => {
|
|
40
|
-
const message = "Invalid request data";
|
|
41
|
-
const error = new BadRequest(message);
|
|
42
|
-
const response = error.toJson();
|
|
43
|
-
|
|
44
|
-
expect(response.status).toBe(400);
|
|
45
|
-
expect(response.statusText).toBe(message);
|
|
46
|
-
|
|
47
|
-
const body = await response.json();
|
|
48
|
-
expect(body).toEqual({ name: "BadRequest", message });
|
|
49
|
-
});
|
|
50
|
-
});
|