@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
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deleteRequest.spec.d.ts","sourceRoot":"","sources":["../../../src/api/__test__/deleteRequest.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { deleteRequest } from "../deleteRequest";
|
|
3
|
-
global.fetch = vi.fn();
|
|
4
|
-
describe("deleteRequest", () => {
|
|
5
|
-
it("should return success response for a successfully delete request", async () => {
|
|
6
|
-
const mockResponse = { message: "Resource deleted successfully" };
|
|
7
|
-
fetch.mockResolvedValueOnce({
|
|
8
|
-
ok: true,
|
|
9
|
-
status: 200,
|
|
10
|
-
json: async () => mockResponse,
|
|
11
|
-
});
|
|
12
|
-
const response = await deleteRequest("https://api.example.com/resource");
|
|
13
|
-
expect(response).toEqual({
|
|
14
|
-
success: true,
|
|
15
|
-
status: 200,
|
|
16
|
-
message: "Resource deleted successfully",
|
|
17
|
-
response: mockResponse,
|
|
18
|
-
cause: null,
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
it("should return failed response for a failed delete request", async () => {
|
|
22
|
-
const mockErrorResponse = { error: "Resource not found" };
|
|
23
|
-
fetch.mockResolvedValueOnce({
|
|
24
|
-
ok: false,
|
|
25
|
-
status: 404,
|
|
26
|
-
json: async () => mockErrorResponse,
|
|
27
|
-
});
|
|
28
|
-
const response = await deleteRequest("https://api.example.com/resource");
|
|
29
|
-
expect(response.success).toBe(false);
|
|
30
|
-
expect(response.status).toBe(404);
|
|
31
|
-
expect(response.response).toEqual(mockErrorResponse);
|
|
32
|
-
expect(response.message).toBeDefined();
|
|
33
|
-
});
|
|
34
|
-
it("should handle network errors gracefully", async () => {
|
|
35
|
-
fetch.mockRejectedValueOnce(new Error("Network Error"));
|
|
36
|
-
const response = await deleteRequest("https://api.example.com/resource");
|
|
37
|
-
expect(response).toEqual({
|
|
38
|
-
success: false,
|
|
39
|
-
status: 0,
|
|
40
|
-
message: "Network error or request failed",
|
|
41
|
-
response: null,
|
|
42
|
-
cause: "Network Error",
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
it("should handle invalid JSON response gracefully", async () => {
|
|
46
|
-
fetch.mockResolvedValueOnce({
|
|
47
|
-
ok: true,
|
|
48
|
-
status: 200,
|
|
49
|
-
json: async () => {
|
|
50
|
-
throw new Error("Invalid JSON");
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
const response = await deleteRequest("https://api.example.com/resource");
|
|
54
|
-
expect(response).toEqual({
|
|
55
|
-
success: true,
|
|
56
|
-
status: 200,
|
|
57
|
-
message: "Resource deleted successfully",
|
|
58
|
-
response: null,
|
|
59
|
-
cause: null,
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
it("should send a body with the delete request if provided", async () => {
|
|
63
|
-
const mockResponse = { message: "Resource deleted successfully" };
|
|
64
|
-
const mockBody = { reason: "No longer needed" };
|
|
65
|
-
fetch.mockResolvedValueOnce({
|
|
66
|
-
ok: true,
|
|
67
|
-
status: 200,
|
|
68
|
-
json: async () => mockResponse,
|
|
69
|
-
});
|
|
70
|
-
const response = await deleteRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
71
|
-
expect(fetch).toHaveBeenCalledWith("https://api.example.com/resource", {
|
|
72
|
-
method: "DELETE",
|
|
73
|
-
headers: { "Content-Type": "application/json" },
|
|
74
|
-
body: JSON.stringify(mockBody),
|
|
75
|
-
});
|
|
76
|
-
expect(response).toEqual({
|
|
77
|
-
success: true,
|
|
78
|
-
status: 200,
|
|
79
|
-
message: "Resource deleted successfully",
|
|
80
|
-
response: mockResponse,
|
|
81
|
-
cause: null,
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getRequest.spec.d.ts","sourceRoot":"","sources":["../../../src/api/__test__/getRequest.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { getRequest } from "../getRequest";
|
|
3
|
-
global.fetch = vi.fn();
|
|
4
|
-
describe("getRequest", () => {
|
|
5
|
-
it("should return success response for a successful request", async () => {
|
|
6
|
-
const mockResponse = { message: "Request successful", data: { id: 1 } };
|
|
7
|
-
fetch.mockResolvedValueOnce({
|
|
8
|
-
ok: true,
|
|
9
|
-
status: 200,
|
|
10
|
-
json: async () => mockResponse,
|
|
11
|
-
});
|
|
12
|
-
const response = await getRequest("https://api.example.com/resource");
|
|
13
|
-
expect(response).toEqual({
|
|
14
|
-
success: true,
|
|
15
|
-
status: 200,
|
|
16
|
-
message: "Request successful",
|
|
17
|
-
response: mockResponse,
|
|
18
|
-
cause: null,
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
it("should return failed response for a failed request", async () => {
|
|
22
|
-
const mockErrorResponse = { error: "Not Found" };
|
|
23
|
-
fetch.mockResolvedValueOnce({
|
|
24
|
-
ok: false,
|
|
25
|
-
status: 404,
|
|
26
|
-
json: async () => mockErrorResponse,
|
|
27
|
-
});
|
|
28
|
-
const response = await getRequest("https://api.example.com/resource");
|
|
29
|
-
expect(response.success).toBe(false);
|
|
30
|
-
expect(response.status).toBe(404);
|
|
31
|
-
expect(response.response).toEqual(mockErrorResponse);
|
|
32
|
-
expect(response.message).toBeDefined();
|
|
33
|
-
});
|
|
34
|
-
it("should handle network errors gracefully", async () => {
|
|
35
|
-
fetch.mockRejectedValueOnce(new Error("Network Error"));
|
|
36
|
-
const response = await getRequest("https://api.example.com/resource");
|
|
37
|
-
expect(response).toEqual({
|
|
38
|
-
success: false,
|
|
39
|
-
status: 0,
|
|
40
|
-
message: "Network error or request failed",
|
|
41
|
-
response: null,
|
|
42
|
-
cause: "Network Error",
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
it("should handle invalid JSON response gracefully", async () => {
|
|
46
|
-
fetch.mockResolvedValueOnce({
|
|
47
|
-
ok: true,
|
|
48
|
-
status: 200,
|
|
49
|
-
json: async () => {
|
|
50
|
-
throw new Error("Invalid JSON");
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
const response = await getRequest("https://api.example.com/resource");
|
|
54
|
-
expect(response).toEqual({
|
|
55
|
-
success: true,
|
|
56
|
-
status: 200,
|
|
57
|
-
message: "Request successful",
|
|
58
|
-
response: null,
|
|
59
|
-
cause: null,
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inboxFlowRequest.spec.d.ts","sourceRoot":"","sources":["../../../src/api/__test__/inboxFlowRequest.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { inboxFlowRequest } from "../inboxFlowRequest";
|
|
3
|
-
import { InboxFlowInstance } from "../../config/inboxFlowInstance";
|
|
4
|
-
import { httpDebug } from "../../services/httpDebug";
|
|
5
|
-
vi.mock("../../config/inboxFlowInstance");
|
|
6
|
-
vi.mock("../../services/httpDebug");
|
|
7
|
-
global.fetch = vi.fn();
|
|
8
|
-
describe("inboxFlowRequest", () => {
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
vi.clearAllMocks();
|
|
11
|
-
});
|
|
12
|
-
it("should send a POST request with correct body and headers", async () => {
|
|
13
|
-
const mockConfig = {
|
|
14
|
-
status: 200,
|
|
15
|
-
method: "POST",
|
|
16
|
-
request: "Request data",
|
|
17
|
-
response: "Response data",
|
|
18
|
-
token: "test-token",
|
|
19
|
-
};
|
|
20
|
-
const mockInboxConfig = {
|
|
21
|
-
inboxChannelId: "channel-id",
|
|
22
|
-
inboxUserToken: "user-token",
|
|
23
|
-
inboxApiUrl: "https://api.example.com/inbox",
|
|
24
|
-
};
|
|
25
|
-
InboxFlowInstance.getInboxConfig.mockReturnValue(mockInboxConfig);
|
|
26
|
-
fetch.mockResolvedValueOnce({
|
|
27
|
-
ok: true,
|
|
28
|
-
status: 200,
|
|
29
|
-
});
|
|
30
|
-
await inboxFlowRequest(mockConfig);
|
|
31
|
-
expect(fetch).toHaveBeenCalledWith(mockInboxConfig.inboxApiUrl, {
|
|
32
|
-
method: "POST",
|
|
33
|
-
body: JSON.stringify({
|
|
34
|
-
status: mockConfig.status,
|
|
35
|
-
channelId: mockInboxConfig.inboxChannelId,
|
|
36
|
-
method: mockConfig.method,
|
|
37
|
-
token: mockConfig.token,
|
|
38
|
-
request: mockConfig.request,
|
|
39
|
-
response: mockConfig.response,
|
|
40
|
-
}),
|
|
41
|
-
headers: {
|
|
42
|
-
"Content-Type": "application/json",
|
|
43
|
-
Authorization: `Bearer ${mockInboxConfig.inboxUserToken}`,
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
it("should not send a request if inbox configuration is not set", async () => {
|
|
48
|
-
InboxFlowInstance.getInboxConfig.mockReturnValue(undefined);
|
|
49
|
-
await inboxFlowRequest({
|
|
50
|
-
status: 200,
|
|
51
|
-
method: "POST",
|
|
52
|
-
request: "Request data",
|
|
53
|
-
response: "Response data",
|
|
54
|
-
token: "test-token",
|
|
55
|
-
});
|
|
56
|
-
expect(fetch).not.toHaveBeenCalled();
|
|
57
|
-
});
|
|
58
|
-
it("should handle fetch errors gracefully", async () => {
|
|
59
|
-
const mockConfig = {
|
|
60
|
-
status: 500,
|
|
61
|
-
method: "ERROR",
|
|
62
|
-
request: "Request data",
|
|
63
|
-
response: "Error response",
|
|
64
|
-
token: "test-token",
|
|
65
|
-
};
|
|
66
|
-
const mockInboxConfig = {
|
|
67
|
-
inboxChannelId: "channel-id",
|
|
68
|
-
inboxUserToken: "user-token",
|
|
69
|
-
inboxApiUrl: "https://api.example.com/inbox",
|
|
70
|
-
};
|
|
71
|
-
InboxFlowInstance.getInboxConfig.mockReturnValue(mockInboxConfig);
|
|
72
|
-
fetch.mockRejectedValueOnce(new Error("Network Error"));
|
|
73
|
-
await inboxFlowRequest(mockConfig);
|
|
74
|
-
expect(httpDebug).toHaveBeenCalledWith("inboxFlowRequest", "Error sending inbox flow request", expect.any(Error));
|
|
75
|
-
});
|
|
76
|
-
it("should not send a request in development environment", async () => {
|
|
77
|
-
const originalEnv = process.env.NODE_ENV;
|
|
78
|
-
process.env.NODE_ENV = "development";
|
|
79
|
-
const mockConfig = {
|
|
80
|
-
status: 200,
|
|
81
|
-
method: "POST",
|
|
82
|
-
request: "Request data",
|
|
83
|
-
response: "Response data",
|
|
84
|
-
token: "test-token",
|
|
85
|
-
};
|
|
86
|
-
const mockInboxConfig = {
|
|
87
|
-
inboxChannelId: "channel-id",
|
|
88
|
-
inboxUserToken: "user-token",
|
|
89
|
-
inboxApiUrl: "https://api.example.com/inbox",
|
|
90
|
-
};
|
|
91
|
-
InboxFlowInstance.getInboxConfig.mockReturnValue(mockInboxConfig);
|
|
92
|
-
await inboxFlowRequest(mockConfig);
|
|
93
|
-
expect(fetch).not.toHaveBeenCalled();
|
|
94
|
-
process.env.NODE_ENV = originalEnv;
|
|
95
|
-
});
|
|
96
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"makeRequest.spec.d.ts","sourceRoot":"","sources":["../../../src/api/__test__/makeRequest.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { makeRequest } from "../makeRequest";
|
|
3
|
-
global.fetch = vi.fn();
|
|
4
|
-
describe("makeRequest", () => {
|
|
5
|
-
it("should return success response for a successful POST request", async () => {
|
|
6
|
-
const mockResponse = { message: "Resource created successfully" };
|
|
7
|
-
const mockBody = { name: "New Resource" };
|
|
8
|
-
fetch.mockResolvedValueOnce({
|
|
9
|
-
ok: true,
|
|
10
|
-
status: 201,
|
|
11
|
-
json: async () => mockResponse,
|
|
12
|
-
});
|
|
13
|
-
const response = await makeRequest("POST", "https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
14
|
-
expect(response).toEqual({
|
|
15
|
-
success: true,
|
|
16
|
-
status: 201,
|
|
17
|
-
message: "Resource created successfully",
|
|
18
|
-
response: mockResponse,
|
|
19
|
-
cause: null,
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
it("should return failed response for a failed PUT request", async () => {
|
|
23
|
-
const mockErrorResponse = { error: "Invalid data" };
|
|
24
|
-
const mockBody = { name: "" };
|
|
25
|
-
fetch.mockResolvedValueOnce({
|
|
26
|
-
ok: false,
|
|
27
|
-
status: 400,
|
|
28
|
-
json: async () => mockErrorResponse,
|
|
29
|
-
});
|
|
30
|
-
const response = await makeRequest("PUT", "https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
31
|
-
expect(response.success).toBe(false);
|
|
32
|
-
expect(response.status).toBe(400);
|
|
33
|
-
expect(response.response).toEqual(mockErrorResponse);
|
|
34
|
-
expect(response.message).toBeDefined();
|
|
35
|
-
});
|
|
36
|
-
it("should handle network errors gracefully", async () => {
|
|
37
|
-
fetch.mockRejectedValueOnce(new Error("Network Error"));
|
|
38
|
-
const response = await makeRequest("GET", "https://api.example.com/resource", { "Content-Type": "application/json" });
|
|
39
|
-
expect(response).toEqual({
|
|
40
|
-
success: false,
|
|
41
|
-
status: 0,
|
|
42
|
-
message: "Network error or request failed",
|
|
43
|
-
response: null,
|
|
44
|
-
cause: "Network Error",
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
it("should handle invalid JSON response gracefully", async () => {
|
|
48
|
-
fetch.mockResolvedValueOnce({
|
|
49
|
-
ok: true,
|
|
50
|
-
status: 200,
|
|
51
|
-
json: async () => {
|
|
52
|
-
throw new Error("Invalid JSON");
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
const response = await makeRequest("GET", "https://api.example.com/resource", { "Content-Type": "application/json" });
|
|
56
|
-
expect(response).toEqual({
|
|
57
|
-
success: true,
|
|
58
|
-
status: 200,
|
|
59
|
-
message: "Request successful",
|
|
60
|
-
response: null,
|
|
61
|
-
cause: null,
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
it("should send headers and body correctly for a DELETE request", async () => {
|
|
65
|
-
const mockResponse = { message: "Resource deleted successfully" };
|
|
66
|
-
fetch.mockResolvedValueOnce({
|
|
67
|
-
ok: true,
|
|
68
|
-
status: 204,
|
|
69
|
-
json: async () => mockResponse,
|
|
70
|
-
});
|
|
71
|
-
const response = await makeRequest("DELETE", "https://api.example.com/resource", { Authorization: "Bearer token" });
|
|
72
|
-
expect(response).toEqual({
|
|
73
|
-
success: true,
|
|
74
|
-
status: 204,
|
|
75
|
-
message: "Resource deleted successfully",
|
|
76
|
-
response: mockResponse,
|
|
77
|
-
cause: null,
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"patchRequest.spec.d.ts","sourceRoot":"","sources":["../../../src/api/__test__/patchRequest.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { patchRequest } from "../patchRequest";
|
|
3
|
-
global.fetch = vi.fn();
|
|
4
|
-
describe("patchRequest", () => {
|
|
5
|
-
it("should return success response for a successful patch request", async () => {
|
|
6
|
-
const mockResponse = { message: "Resource updated successfully" };
|
|
7
|
-
const mockBody = { name: "Updated Name" };
|
|
8
|
-
fetch.mockResolvedValueOnce({
|
|
9
|
-
ok: true,
|
|
10
|
-
status: 200,
|
|
11
|
-
json: async () => mockResponse,
|
|
12
|
-
});
|
|
13
|
-
const response = await patchRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
14
|
-
expect(response).toEqual({
|
|
15
|
-
success: true,
|
|
16
|
-
status: 200,
|
|
17
|
-
message: "Resource updated successfully",
|
|
18
|
-
response: mockResponse,
|
|
19
|
-
cause: null,
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
it("should return failed response for a failed patch request", async () => {
|
|
23
|
-
const mockErrorResponse = { error: "Resource not found" };
|
|
24
|
-
const mockBody = { name: "Updated Name" };
|
|
25
|
-
fetch.mockResolvedValueOnce({
|
|
26
|
-
ok: false,
|
|
27
|
-
status: 404,
|
|
28
|
-
json: async () => mockErrorResponse,
|
|
29
|
-
});
|
|
30
|
-
const response = await patchRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
31
|
-
expect(response.success).toBe(false);
|
|
32
|
-
expect(response.status).toBe(404);
|
|
33
|
-
expect(response.response).toEqual(mockErrorResponse);
|
|
34
|
-
expect(response.message).toBeDefined();
|
|
35
|
-
});
|
|
36
|
-
it("should handle network errors gracefully", async () => {
|
|
37
|
-
const mockBody = { name: "Updated Name" };
|
|
38
|
-
fetch.mockRejectedValueOnce(new Error("Network Error"));
|
|
39
|
-
const response = await patchRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
40
|
-
expect(response).toEqual({
|
|
41
|
-
success: false,
|
|
42
|
-
status: 0,
|
|
43
|
-
message: "Network error or request failed",
|
|
44
|
-
response: null,
|
|
45
|
-
cause: "Network Error",
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
it("should handle invalid JSON response gracefully", async () => {
|
|
49
|
-
const mockBody = { name: "Updated Name" };
|
|
50
|
-
fetch.mockResolvedValueOnce({
|
|
51
|
-
ok: true,
|
|
52
|
-
status: 200,
|
|
53
|
-
json: async () => {
|
|
54
|
-
throw new Error("Invalid JSON");
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
const response = await patchRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
58
|
-
expect(response).toEqual({
|
|
59
|
-
success: true,
|
|
60
|
-
status: 200,
|
|
61
|
-
message: "Resource patched successfully",
|
|
62
|
-
response: null,
|
|
63
|
-
cause: null,
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
it("should send headers and body correctly", async () => {
|
|
67
|
-
const mockResponse = { message: "Resource updated successfully" };
|
|
68
|
-
const mockBody = { name: "Updated Name" };
|
|
69
|
-
const mockHeaders = { Authorization: "Bearer token" };
|
|
70
|
-
fetch.mockResolvedValueOnce({
|
|
71
|
-
ok: true,
|
|
72
|
-
status: 200,
|
|
73
|
-
json: async () => mockResponse,
|
|
74
|
-
});
|
|
75
|
-
const response = await patchRequest("https://api.example.com/resource", mockHeaders, mockBody);
|
|
76
|
-
expect(response).toEqual({
|
|
77
|
-
success: true,
|
|
78
|
-
status: 200,
|
|
79
|
-
message: "Resource updated successfully",
|
|
80
|
-
response: mockResponse,
|
|
81
|
-
cause: null,
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postRequest.spec.d.ts","sourceRoot":"","sources":["../../../src/api/__test__/postRequest.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { postRequest } from "../postRequest";
|
|
3
|
-
global.fetch = vi.fn();
|
|
4
|
-
describe("postRequest", () => {
|
|
5
|
-
it("should return success response for a successful POST request", async () => {
|
|
6
|
-
const mockResponse = { message: "Resource created successfully" };
|
|
7
|
-
const mockBody = { name: "New Resource" };
|
|
8
|
-
fetch.mockResolvedValueOnce({
|
|
9
|
-
ok: true,
|
|
10
|
-
status: 201,
|
|
11
|
-
json: async () => mockResponse,
|
|
12
|
-
});
|
|
13
|
-
const response = await postRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
14
|
-
expect(response).toEqual({
|
|
15
|
-
success: true,
|
|
16
|
-
status: 201,
|
|
17
|
-
message: "Resource created successfully",
|
|
18
|
-
response: mockResponse,
|
|
19
|
-
cause: null,
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
it("should return failed response for a failed POST request", async () => {
|
|
23
|
-
const mockErrorResponse = { error: "Invalid data" };
|
|
24
|
-
const mockBody = { name: "" };
|
|
25
|
-
fetch.mockResolvedValueOnce({
|
|
26
|
-
ok: false,
|
|
27
|
-
status: 400,
|
|
28
|
-
json: async () => mockErrorResponse,
|
|
29
|
-
});
|
|
30
|
-
const response = await postRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
31
|
-
expect(response.success).toBe(false);
|
|
32
|
-
expect(response.status).toBe(400);
|
|
33
|
-
expect(response.response).toEqual(mockErrorResponse);
|
|
34
|
-
expect(response.message).toBeDefined();
|
|
35
|
-
});
|
|
36
|
-
it("should handle network errors gracefully", async () => {
|
|
37
|
-
const mockBody = { name: "New Resource" };
|
|
38
|
-
fetch.mockRejectedValueOnce(new Error("Network Error"));
|
|
39
|
-
const response = await postRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
40
|
-
expect(response).toEqual({
|
|
41
|
-
success: false,
|
|
42
|
-
status: 0,
|
|
43
|
-
message: "Network error or request failed",
|
|
44
|
-
response: null,
|
|
45
|
-
cause: "Network Error",
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
it("should handle invalid JSON response gracefully", async () => {
|
|
49
|
-
const mockBody = { name: "New Resource" };
|
|
50
|
-
fetch.mockResolvedValueOnce({
|
|
51
|
-
ok: true,
|
|
52
|
-
status: 201,
|
|
53
|
-
json: async () => {
|
|
54
|
-
throw new Error("Invalid JSON");
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
const response = await postRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
58
|
-
expect(response).toEqual({
|
|
59
|
-
success: true,
|
|
60
|
-
status: 201,
|
|
61
|
-
message: "Resource created successfully",
|
|
62
|
-
response: null,
|
|
63
|
-
cause: null,
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
it("should send headers and body correctly", async () => {
|
|
67
|
-
const mockResponse = { message: "Resource created successfully" };
|
|
68
|
-
const mockBody = { name: "New Resource" };
|
|
69
|
-
const mockHeaders = { Authorization: "Bearer token" };
|
|
70
|
-
fetch.mockResolvedValueOnce({
|
|
71
|
-
ok: true,
|
|
72
|
-
status: 201,
|
|
73
|
-
json: async () => mockResponse,
|
|
74
|
-
});
|
|
75
|
-
const response = await postRequest("https://api.example.com/resource", mockHeaders, mockBody);
|
|
76
|
-
expect(response).toEqual({
|
|
77
|
-
success: true,
|
|
78
|
-
status: 201,
|
|
79
|
-
message: "Resource created successfully",
|
|
80
|
-
response: mockResponse,
|
|
81
|
-
cause: null,
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"putRequest.spec.d.ts","sourceRoot":"","sources":["../../../src/api/__test__/putRequest.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { putRequest } from "../putRequest";
|
|
3
|
-
global.fetch = vi.fn();
|
|
4
|
-
describe("putRequest", () => {
|
|
5
|
-
it("should return success response for a successful PUT request", async () => {
|
|
6
|
-
const mockResponse = { message: "Resource updated successfully" };
|
|
7
|
-
const mockBody = { name: "Updated Resource" };
|
|
8
|
-
fetch.mockResolvedValueOnce({
|
|
9
|
-
ok: true,
|
|
10
|
-
status: 200,
|
|
11
|
-
json: async () => mockResponse,
|
|
12
|
-
});
|
|
13
|
-
const response = await putRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
14
|
-
expect(response).toEqual({
|
|
15
|
-
success: true,
|
|
16
|
-
status: 200,
|
|
17
|
-
message: "Resource updated successfully",
|
|
18
|
-
response: mockResponse,
|
|
19
|
-
cause: null,
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
it("should return failed response for a failed PUT request", async () => {
|
|
23
|
-
const mockErrorResponse = { error: "Invalid data" };
|
|
24
|
-
const mockBody = { name: "" };
|
|
25
|
-
fetch.mockResolvedValueOnce({
|
|
26
|
-
ok: false,
|
|
27
|
-
status: 400,
|
|
28
|
-
json: async () => mockErrorResponse,
|
|
29
|
-
});
|
|
30
|
-
const response = await putRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
31
|
-
expect(response.success).toBe(false);
|
|
32
|
-
expect(response.status).toBe(400);
|
|
33
|
-
expect(response.response).toEqual(mockErrorResponse);
|
|
34
|
-
expect(response.message).toBeDefined();
|
|
35
|
-
});
|
|
36
|
-
it("should handle network errors gracefully", async () => {
|
|
37
|
-
const mockBody = { name: "Updated Resource" };
|
|
38
|
-
fetch.mockRejectedValueOnce(new Error("Network Error"));
|
|
39
|
-
const response = await putRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
40
|
-
expect(response).toEqual({
|
|
41
|
-
success: false,
|
|
42
|
-
status: 0,
|
|
43
|
-
message: "Network error or request failed",
|
|
44
|
-
response: null,
|
|
45
|
-
cause: "Network Error",
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
it("should handle invalid JSON response gracefully", async () => {
|
|
49
|
-
const mockBody = { name: "Updated Resource" };
|
|
50
|
-
fetch.mockResolvedValueOnce({
|
|
51
|
-
ok: true,
|
|
52
|
-
status: 200,
|
|
53
|
-
json: async () => {
|
|
54
|
-
throw new Error("Invalid JSON");
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
const response = await putRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
58
|
-
expect(response).toEqual({
|
|
59
|
-
success: true,
|
|
60
|
-
status: 200,
|
|
61
|
-
message: "Resource updated successfully",
|
|
62
|
-
response: null,
|
|
63
|
-
cause: null,
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
it("should send headers and body correctly", async () => {
|
|
67
|
-
const mockResponse = { message: "Resource updated successfully" };
|
|
68
|
-
const mockBody = { name: "Updated Resource" };
|
|
69
|
-
const mockHeaders = { Authorization: "Bearer token" };
|
|
70
|
-
fetch.mockResolvedValueOnce({
|
|
71
|
-
ok: true,
|
|
72
|
-
status: 200,
|
|
73
|
-
json: async () => mockResponse,
|
|
74
|
-
});
|
|
75
|
-
const response = await putRequest("https://api.example.com/resource", mockHeaders, mockBody);
|
|
76
|
-
expect(response).toEqual({
|
|
77
|
-
success: true,
|
|
78
|
-
status: 200,
|
|
79
|
-
message: "Resource updated successfully",
|
|
80
|
-
response: mockResponse,
|
|
81
|
-
cause: null,
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apiInstance.spec.d.ts","sourceRoot":"","sources":["../../../src/config/__test__/apiInstance.spec.ts"],"names":[],"mappings":""}
|