@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.
Files changed (117) hide show
  1. package/package.json +1 -1
  2. package/dist/api/__test__/deleteRequest.spec.d.ts +0 -2
  3. package/dist/api/__test__/deleteRequest.spec.d.ts.map +0 -1
  4. package/dist/api/__test__/deleteRequest.spec.js +0 -84
  5. package/dist/api/__test__/getRequest.spec.d.ts +0 -2
  6. package/dist/api/__test__/getRequest.spec.d.ts.map +0 -1
  7. package/dist/api/__test__/getRequest.spec.js +0 -62
  8. package/dist/api/__test__/inboxFlowRequest.spec.d.ts +0 -2
  9. package/dist/api/__test__/inboxFlowRequest.spec.d.ts.map +0 -1
  10. package/dist/api/__test__/inboxFlowRequest.spec.js +0 -96
  11. package/dist/api/__test__/makeRequest.spec.d.ts +0 -2
  12. package/dist/api/__test__/makeRequest.spec.d.ts.map +0 -1
  13. package/dist/api/__test__/makeRequest.spec.js +0 -80
  14. package/dist/api/__test__/patchRequest.spec.d.ts +0 -2
  15. package/dist/api/__test__/patchRequest.spec.d.ts.map +0 -1
  16. package/dist/api/__test__/patchRequest.spec.js +0 -84
  17. package/dist/api/__test__/postRequest.spec.d.ts +0 -2
  18. package/dist/api/__test__/postRequest.spec.d.ts.map +0 -1
  19. package/dist/api/__test__/postRequest.spec.js +0 -84
  20. package/dist/api/__test__/putRequest.spec.d.ts +0 -2
  21. package/dist/api/__test__/putRequest.spec.d.ts.map +0 -1
  22. package/dist/api/__test__/putRequest.spec.js +0 -84
  23. package/dist/config/__test__/apiInstance.spec.d.ts +0 -2
  24. package/dist/config/__test__/apiInstance.spec.d.ts.map +0 -1
  25. package/dist/config/__test__/apiInstance.spec.js +0 -86
  26. package/dist/config/__test__/inboxFlowInstance.spec.d.ts +0 -2
  27. package/dist/config/__test__/inboxFlowInstance.spec.d.ts.map +0 -1
  28. package/dist/config/__test__/inboxFlowInstance.spec.js +0 -48
  29. package/dist/http/badResponses/__test__/badGateway.spec.d.ts +0 -2
  30. package/dist/http/badResponses/__test__/badGateway.spec.d.ts.map +0 -1
  31. package/dist/http/badResponses/__test__/badGateway.spec.js +0 -42
  32. package/dist/http/badResponses/__test__/badRequest.spec.d.ts +0 -2
  33. package/dist/http/badResponses/__test__/badRequest.spec.d.ts.map +0 -1
  34. package/dist/http/badResponses/__test__/badRequest.spec.js +0 -40
  35. package/dist/http/badResponses/__test__/conflict.spec.d.ts +0 -2
  36. package/dist/http/badResponses/__test__/conflict.spec.d.ts.map +0 -1
  37. package/dist/http/badResponses/__test__/conflict.spec.js +0 -40
  38. package/dist/http/badResponses/__test__/forbidden.spec.d.ts +0 -2
  39. package/dist/http/badResponses/__test__/forbidden.spec.d.ts.map +0 -1
  40. package/dist/http/badResponses/__test__/forbidden.spec.js +0 -40
  41. package/dist/http/badResponses/__test__/notFound.spec.d.ts +0 -2
  42. package/dist/http/badResponses/__test__/notFound.spec.d.ts.map +0 -1
  43. package/dist/http/badResponses/__test__/notFound.spec.js +0 -40
  44. package/dist/http/badResponses/__test__/notImplemented.spec.d.ts +0 -2
  45. package/dist/http/badResponses/__test__/notImplemented.spec.d.ts.map +0 -1
  46. package/dist/http/badResponses/__test__/notImplemented.spec.js +0 -40
  47. package/dist/http/badResponses/__test__/serverError.spec.d.ts +0 -2
  48. package/dist/http/badResponses/__test__/serverError.spec.d.ts.map +0 -1
  49. package/dist/http/badResponses/__test__/serverError.spec.js +0 -40
  50. package/dist/http/badResponses/__test__/unauthorized.spec.d.ts +0 -2
  51. package/dist/http/badResponses/__test__/unauthorized.spec.d.ts.map +0 -1
  52. package/dist/http/badResponses/__test__/unauthorized.spec.js +0 -40
  53. package/dist/http/badResponses/__test__/unprocessableEntity.spec.d.ts +0 -2
  54. package/dist/http/badResponses/__test__/unprocessableEntity.spec.d.ts.map +0 -1
  55. package/dist/http/badResponses/__test__/unprocessableEntity.spec.js +0 -66
  56. package/dist/http/successResponses/__test__/created.spec.d.ts +0 -2
  57. package/dist/http/successResponses/__test__/created.spec.d.ts.map +0 -1
  58. package/dist/http/successResponses/__test__/created.spec.js +0 -57
  59. package/dist/http/successResponses/__test__/found.spec.d.ts +0 -2
  60. package/dist/http/successResponses/__test__/found.spec.d.ts.map +0 -1
  61. package/dist/http/successResponses/__test__/found.spec.js +0 -57
  62. package/dist/http/successResponses/__test__/noContent.spec.d.ts +0 -2
  63. package/dist/http/successResponses/__test__/noContent.spec.d.ts.map +0 -1
  64. package/dist/http/successResponses/__test__/noContent.spec.js +0 -40
  65. package/dist/http/successResponses/__test__/success.spec.d.ts +0 -2
  66. package/dist/http/successResponses/__test__/success.spec.d.ts.map +0 -1
  67. package/dist/http/successResponses/__test__/success.spec.js +0 -60
  68. package/dist/http/successResponses/__test__/updated.spec.d.ts +0 -2
  69. package/dist/http/successResponses/__test__/updated.spec.d.ts.map +0 -1
  70. package/dist/http/successResponses/__test__/updated.spec.js +0 -60
  71. package/dist/services/__test__/decodeRequestBody.spec.d.ts +0 -2
  72. package/dist/services/__test__/decodeRequestBody.spec.d.ts.map +0 -1
  73. package/dist/services/__test__/decodeRequestBody.spec.js +0 -39
  74. package/dist/services/__test__/errorHandler.spec.d.ts +0 -2
  75. package/dist/services/__test__/errorHandler.spec.d.ts.map +0 -1
  76. package/dist/services/__test__/errorHandler.spec.js +0 -115
  77. package/dist/services/__test__/formParse.spec.d.ts +0 -2
  78. package/dist/services/__test__/formParse.spec.d.ts.map +0 -1
  79. package/dist/services/__test__/formParse.spec.js +0 -78
  80. package/dist/services/__test__/getCaller.spec.d.ts +0 -2
  81. package/dist/services/__test__/getCaller.spec.d.ts.map +0 -1
  82. package/dist/services/__test__/getCaller.spec.js +0 -60
  83. package/dist/services/__test__/getScopedParams.spec.d.ts +0 -2
  84. package/dist/services/__test__/getScopedParams.spec.d.ts.map +0 -1
  85. package/dist/services/__test__/getScopedParams.spec.js +0 -51
  86. package/dist/services/__test__/schemaValidator.spec.d.ts +0 -2
  87. package/dist/services/__test__/schemaValidator.spec.d.ts.map +0 -1
  88. package/dist/services/__test__/schemaValidator.spec.js +0 -89
  89. package/src/api/__test__/deleteRequest.spec.ts +0 -107
  90. package/src/api/__test__/getRequest.spec.ts +0 -76
  91. package/src/api/__test__/inboxFlowRequest.spec.ts +0 -125
  92. package/src/api/__test__/makeRequest.spec.ts +0 -121
  93. package/src/api/__test__/patchRequest.spec.ts +0 -125
  94. package/src/api/__test__/postRequest.spec.ts +0 -125
  95. package/src/api/__test__/putRequest.spec.ts +0 -125
  96. package/src/config/__test__/apiInstance.spec.ts +0 -129
  97. package/src/config/__test__/inboxFlowInstance.spec.ts +0 -61
  98. package/src/http/badResponses/__test__/badGateway.spec.ts +0 -50
  99. package/src/http/badResponses/__test__/badRequest.spec.ts +0 -50
  100. package/src/http/badResponses/__test__/conflict.spec.ts +0 -50
  101. package/src/http/badResponses/__test__/forbidden.spec.ts +0 -50
  102. package/src/http/badResponses/__test__/notFound.spec.ts +0 -50
  103. package/src/http/badResponses/__test__/notImplemented.spec.ts +0 -50
  104. package/src/http/badResponses/__test__/serverError.spec.ts +0 -50
  105. package/src/http/badResponses/__test__/unauthorized.spec.ts +0 -50
  106. package/src/http/badResponses/__test__/unprocessableEntity.spec.ts +0 -76
  107. package/src/http/successResponses/__test__/created.spec.ts +0 -65
  108. package/src/http/successResponses/__test__/found.spec.ts +0 -65
  109. package/src/http/successResponses/__test__/noContent.spec.ts +0 -49
  110. package/src/http/successResponses/__test__/success.spec.ts +0 -68
  111. package/src/http/successResponses/__test__/updated.spec.ts +0 -68
  112. package/src/services/__test__/decodeRequestBody.spec.ts +0 -51
  113. package/src/services/__test__/errorHandler.spec.ts +0 -133
  114. package/src/services/__test__/formParse.spec.ts +0 -96
  115. package/src/services/__test__/getCaller.spec.ts +0 -78
  116. package/src/services/__test__/getScopedParams.spec.ts +0 -68
  117. package/src/services/__test__/schemaValidator.spec.ts +0 -106
@@ -1,86 +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
- vi.mock("../../api/getRequest");
9
- vi.mock("../../api/postRequest");
10
- vi.mock("../../api/putRequest");
11
- vi.mock("../../api/patchRequest");
12
- vi.mock("../../api/deleteRequest");
13
- describe("ApiInstance", () => {
14
- const baseUrl = "https://api.example.com";
15
- const baseHeaders = { "Content-Type": "application/json" };
16
- const baseToken = "base-token";
17
- const apiInstance = new ApiInstance({
18
- baseUrl,
19
- baseHeaders,
20
- baseToken,
21
- });
22
- it("should send a GET request with correct headers and URL", async () => {
23
- const mockResponse = { success: true, data: "GET response" };
24
- getRequest.mockResolvedValueOnce(mockResponse);
25
- const response = await apiInstance.GET("/resource", {});
26
- expect(getRequest).toHaveBeenCalledWith(`${baseUrl}/resource`, expect.objectContaining({
27
- Authorization: `Bearer ${baseToken}`,
28
- "Content-Type": "application/json",
29
- }));
30
- expect(response).toEqual(mockResponse);
31
- });
32
- it("should send a POST request with correct headers, URL, and body", async () => {
33
- const mockResponse = { success: true, data: "POST response" };
34
- const mockBody = { name: "New Resource" };
35
- postRequest.mockResolvedValueOnce(mockResponse);
36
- const response = await apiInstance.POST("/resource", { body: mockBody });
37
- expect(postRequest).toHaveBeenCalledWith(`${baseUrl}/resource`, expect.objectContaining({
38
- Authorization: `Bearer ${baseToken}`,
39
- "Content-Type": "application/json",
40
- }), mockBody);
41
- expect(response).toEqual(mockResponse);
42
- });
43
- it("should send a PUT request with correct headers, URL, and body", async () => {
44
- const mockResponse = { success: true, data: "PUT response" };
45
- const mockBody = { name: "Updated Resource" };
46
- putRequest.mockResolvedValueOnce(mockResponse);
47
- const response = await apiInstance.PUT("/resource", { body: mockBody });
48
- expect(putRequest).toHaveBeenCalledWith(`${baseUrl}/resource`, expect.objectContaining({
49
- Authorization: `Bearer ${baseToken}`,
50
- "Content-Type": "application/json",
51
- }), mockBody);
52
- expect(response).toEqual(mockResponse);
53
- });
54
- it("should send a PATCH request with correct headers, URL, and body", async () => {
55
- const mockResponse = { success: true, data: "PATCH response" };
56
- const mockBody = { name: "Partially Updated Resource" };
57
- patchRequest.mockResolvedValueOnce(mockResponse);
58
- const response = await apiInstance.PATCH("/resource", { body: mockBody });
59
- expect(patchRequest).toHaveBeenCalledWith(`${baseUrl}/resource`, expect.objectContaining({
60
- Authorization: `Bearer ${baseToken}`,
61
- "Content-Type": "application/json",
62
- }), mockBody);
63
- expect(response).toEqual(mockResponse);
64
- });
65
- it("should send a DELETE request with correct headers, URL, and body", async () => {
66
- const mockResponse = { success: true, data: "DELETE response" };
67
- const mockBody = { id: 1 };
68
- deleteRequest.mockResolvedValueOnce(mockResponse);
69
- const response = await apiInstance.DELETE("/resource", { body: mockBody });
70
- expect(deleteRequest).toHaveBeenCalledWith(`${baseUrl}/resource`, expect.objectContaining({
71
- Authorization: `Bearer ${baseToken}`,
72
- "Content-Type": "application/json",
73
- }), mockBody);
74
- expect(response).toEqual(mockResponse);
75
- });
76
- it("should override base token with provided token", async () => {
77
- const mockResponse = { success: true, data: "GET response with token" };
78
- getRequest.mockResolvedValueOnce(mockResponse);
79
- const response = await apiInstance.GET("/resource", { token: "new-token" });
80
- expect(getRequest).toHaveBeenCalledWith(`${baseUrl}/resource`, expect.objectContaining({
81
- Authorization: `Bearer new-token`,
82
- "Content-Type": "application/json",
83
- }));
84
- expect(response).toEqual(mockResponse);
85
- });
86
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=inboxFlowInstance.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inboxFlowInstance.spec.d.ts","sourceRoot":"","sources":["../../../src/config/__test__/inboxFlowInstance.spec.ts"],"names":[],"mappings":""}
@@ -1,48 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { InboxFlowInstance } from "../inboxFlowInstance";
3
- describe("InboxFlowInstance", () => {
4
- it("should set the inbox configuration if not already set", () => {
5
- const inboxConfig = {
6
- inboxChannelId: "channel-123",
7
- inboxUserToken: "user-token-abc",
8
- inboxApiUrl: "https://custom-inbox-api.com",
9
- };
10
- InboxFlowInstance.setInboxConfig(inboxConfig);
11
- const config = InboxFlowInstance.getInboxConfig();
12
- expect(config).toEqual(inboxConfig);
13
- });
14
- it("should not overwrite the inbox configuration if already set", () => {
15
- const initialConfig = {
16
- inboxChannelId: "channel-123",
17
- inboxUserToken: "user-token-abc",
18
- inboxApiUrl: "https://custom-inbox-api.com",
19
- };
20
- const newConfig = {
21
- inboxChannelId: "channel-456",
22
- inboxUserToken: "user-token-def",
23
- inboxApiUrl: "https://another-inbox-api.com",
24
- };
25
- InboxFlowInstance.setInboxConfig(initialConfig);
26
- InboxFlowInstance.setInboxConfig(newConfig);
27
- const config = InboxFlowInstance.getInboxConfig();
28
- expect(config).toEqual(initialConfig);
29
- });
30
- it("should return undefined if no configuration is set", () => {
31
- InboxFlowInstance.resetInboxConfig();
32
- const config = InboxFlowInstance.getInboxConfig();
33
- expect(config).toBeUndefined();
34
- });
35
- it("should use the default API URL if none is provided", () => {
36
- const inboxConfig = {
37
- inboxChannelId: "channel-123",
38
- inboxUserToken: "user-token-abc",
39
- };
40
- const defaultInboxURL = `https://logs-inbox-flow-logs.vw6wo7.easypanel.host/api/call`;
41
- InboxFlowInstance.setInboxConfig(inboxConfig);
42
- const config = InboxFlowInstance.getInboxConfig();
43
- expect(config).toEqual({
44
- ...inboxConfig,
45
- inboxApiUrl: defaultInboxURL,
46
- });
47
- });
48
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=badGateway.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"badGateway.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/badResponses/__test__/badGateway.spec.ts"],"names":[],"mappings":""}
@@ -1,42 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { BadGateway } from "../badGateway";
3
- describe("BadGateway", () => {
4
- it("should create an instance with the correct properties", () => {
5
- const message = "Bad Gateway error occurred";
6
- const cause = { reason: "Upstream server is down" };
7
- const error = new BadGateway(message, cause);
8
- expect(error.body).toEqual({ name: "BadGateway", message });
9
- expect(error.status).toBe(502);
10
- expect(error.statusText).toBe(message);
11
- expect(error.cause).toBe(JSON.stringify(cause));
12
- });
13
- it("should create an instance without a cause", () => {
14
- const message = "Bad Gateway error occurred";
15
- const error = new BadGateway(message);
16
- expect(error.body).toEqual({ name: "BadGateway", message });
17
- expect(error.status).toBe(502);
18
- expect(error.statusText).toBe(message);
19
- expect(error.cause).toBeUndefined();
20
- });
21
- it("should return a Response object from toResponse", () => {
22
- const message = "Bad Gateway error occurred";
23
- const error = new BadGateway(message);
24
- const response = error.toResponse();
25
- expect(response.status).toBe(502);
26
- expect(response.statusText).toBe(message);
27
- expect(response.headers.get("Content-Type")).toBe("application/json");
28
- response.json().then((body) => {
29
- expect(body).toEqual({ name: "BadGateway", message });
30
- });
31
- });
32
- it("should return a Response object from toJson", () => {
33
- const message = "Bad Gateway error occurred";
34
- const error = new BadGateway(message);
35
- const response = error.toJson();
36
- expect(response.status).toBe(502);
37
- expect(response.statusText).toBe(message);
38
- response.json().then((body) => {
39
- expect(body).toEqual({ name: "BadGateway", message });
40
- });
41
- });
42
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=badRequest.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"badRequest.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/badResponses/__test__/badRequest.spec.ts"],"names":[],"mappings":""}
@@ -1,40 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { BadRequest } from "../badRequest";
3
- describe("BadRequest", () => {
4
- it("should create an instance with the correct properties", () => {
5
- const message = "Invalid request data";
6
- const cause = { field: "email", error: "Invalid format" };
7
- const error = new BadRequest(message, cause);
8
- expect(error.body).toEqual({ name: "BadRequest", message });
9
- expect(error.status).toBe(400);
10
- expect(error.statusText).toBe(message);
11
- expect(error.cause).toBe(JSON.stringify(cause));
12
- });
13
- it("should create an instance without a cause", () => {
14
- const message = "Invalid request data";
15
- const error = new BadRequest(message);
16
- expect(error.body).toEqual({ name: "BadRequest", message });
17
- expect(error.status).toBe(400);
18
- expect(error.statusText).toBe(message);
19
- expect(error.cause).toBeUndefined();
20
- });
21
- it("should return a Response object from toResponse", async () => {
22
- const message = "Invalid request data";
23
- const error = new BadRequest(message);
24
- const response = error.toResponse();
25
- expect(response.status).toBe(400);
26
- expect(response.statusText).toBe(message);
27
- expect(response.headers.get("Content-Type")).toBe("application/json");
28
- const body = await response.json();
29
- expect(body).toEqual({ name: "BadRequest", message });
30
- });
31
- it("should return a Response object from toJson", async () => {
32
- const message = "Invalid request data";
33
- const error = new BadRequest(message);
34
- const response = error.toJson();
35
- expect(response.status).toBe(400);
36
- expect(response.statusText).toBe(message);
37
- const body = await response.json();
38
- expect(body).toEqual({ name: "BadRequest", message });
39
- });
40
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=conflict.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"conflict.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/badResponses/__test__/conflict.spec.ts"],"names":[],"mappings":""}
@@ -1,40 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { Conflict } from "../conflict";
3
- describe("Conflict", () => {
4
- it("should create an instance with the correct properties", () => {
5
- const message = "Conflict occurred";
6
- const cause = { reason: "Duplicate entry" };
7
- const error = new Conflict(message, cause);
8
- expect(error.body).toEqual({ name: "Conflict", message });
9
- expect(error.status).toBe(409);
10
- expect(error.statusText).toBe(message);
11
- expect(error.cause).toBe(JSON.stringify(cause));
12
- });
13
- it("should create an instance without a cause", () => {
14
- const message = "Conflict occurred";
15
- const error = new Conflict(message);
16
- expect(error.body).toEqual({ name: "Conflict", message });
17
- expect(error.status).toBe(409);
18
- expect(error.statusText).toBe(message);
19
- expect(error.cause).toBeUndefined();
20
- });
21
- it("should return a Response object from toResponse", async () => {
22
- const message = "Conflict occurred";
23
- const error = new Conflict(message);
24
- const response = error.toResponse();
25
- expect(response.status).toBe(409);
26
- expect(response.statusText).toBe(message);
27
- expect(response.headers.get("Content-Type")).toBe("application/json");
28
- const body = await response.json();
29
- expect(body).toEqual({ name: "Conflict", message });
30
- });
31
- it("should return a Response object from toJson", async () => {
32
- const message = "Conflict occurred";
33
- const error = new Conflict(message);
34
- const response = error.toJson();
35
- expect(response.status).toBe(409);
36
- expect(response.statusText).toBe(message);
37
- const body = await response.json();
38
- expect(body).toEqual({ name: "Conflict", message });
39
- });
40
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=forbidden.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"forbidden.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/badResponses/__test__/forbidden.spec.ts"],"names":[],"mappings":""}
@@ -1,40 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { Forbidden } from "../forbidden";
3
- describe("Forbidden", () => {
4
- it("should create an instance with the correct properties", () => {
5
- const message = "Access is forbidden";
6
- const cause = { reason: "Insufficient permissions" };
7
- const error = new Forbidden(message, cause);
8
- expect(error.body).toEqual({ name: "Forbidden", message });
9
- expect(error.status).toBe(403);
10
- expect(error.statusText).toBe(message);
11
- expect(error.cause).toBe(JSON.stringify(cause));
12
- });
13
- it("should create an instance without a cause", () => {
14
- const message = "Access is forbidden";
15
- const error = new Forbidden(message);
16
- expect(error.body).toEqual({ name: "Forbidden", message });
17
- expect(error.status).toBe(403);
18
- expect(error.statusText).toBe(message);
19
- expect(error.cause).toBeUndefined();
20
- });
21
- it("should return a Response object from toResponse", async () => {
22
- const message = "Access is forbidden";
23
- const error = new Forbidden(message);
24
- const response = error.toResponse();
25
- expect(response.status).toBe(403);
26
- expect(response.statusText).toBe(message);
27
- expect(response.headers.get("Content-Type")).toBe("application/json");
28
- const body = await response.json();
29
- expect(body).toEqual({ name: "Forbidden", message });
30
- });
31
- it("should return a Response object from toJson", async () => {
32
- const message = "Access is forbidden";
33
- const error = new Forbidden(message);
34
- const response = error.toJson();
35
- expect(response.status).toBe(403);
36
- expect(response.statusText).toBe(message);
37
- const body = await response.json();
38
- expect(body).toEqual({ name: "Forbidden", message });
39
- });
40
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=notFound.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"notFound.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/badResponses/__test__/notFound.spec.ts"],"names":[],"mappings":""}
@@ -1,40 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { NotFound } from "../notFound";
3
- describe("NotFound", () => {
4
- it("should create an instance with the correct properties", () => {
5
- const message = "Resource not found";
6
- const cause = { reason: "ID does not exist" };
7
- const error = new NotFound(message, cause);
8
- expect(error.body).toEqual({ name: "NotFound", message });
9
- expect(error.status).toBe(404);
10
- expect(error.statusText).toBe(message);
11
- expect(error.cause).toBe(JSON.stringify(cause));
12
- });
13
- it("should create an instance without a cause", () => {
14
- const message = "Resource not found";
15
- const error = new NotFound(message);
16
- expect(error.body).toEqual({ name: "NotFound", message });
17
- expect(error.status).toBe(404);
18
- expect(error.statusText).toBe(message);
19
- expect(error.cause).toBeUndefined();
20
- });
21
- it("should return a Response object from toResponse", async () => {
22
- const message = "Resource not found";
23
- const error = new NotFound(message);
24
- const response = error.toResponse();
25
- expect(response.status).toBe(404);
26
- expect(response.statusText).toBe(message);
27
- expect(response.headers.get("Content-Type")).toBe("application/json");
28
- const body = await response.json();
29
- expect(body).toEqual({ name: "NotFound", message });
30
- });
31
- it("should return a Response object from toJson", async () => {
32
- const message = "Resource not found";
33
- const error = new NotFound(message);
34
- const response = error.toJson();
35
- expect(response.status).toBe(404);
36
- expect(response.statusText).toBe(message);
37
- const body = await response.json();
38
- expect(body).toEqual({ name: "NotFound", message });
39
- });
40
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=notImplemented.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"notImplemented.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/badResponses/__test__/notImplemented.spec.ts"],"names":[],"mappings":""}
@@ -1,40 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { NotImplemented } from "../notImplemented";
3
- describe("NotImplemented", () => {
4
- it("should create an instance with the correct properties", () => {
5
- const message = "Feature not implemented";
6
- const cause = { reason: "Under development" };
7
- const error = new NotImplemented(message, cause);
8
- expect(error.body).toEqual({ name: "NotImplemented", message });
9
- expect(error.status).toBe(501);
10
- expect(error.statusText).toBe(message);
11
- expect(error.cause).toBe(JSON.stringify(cause));
12
- });
13
- it("should create an instance without a cause", () => {
14
- const message = "Feature not implemented";
15
- const error = new NotImplemented(message);
16
- expect(error.body).toEqual({ name: "NotImplemented", message });
17
- expect(error.status).toBe(501);
18
- expect(error.statusText).toBe(message);
19
- expect(error.cause).toBeUndefined();
20
- });
21
- it("should return a Response object from toResponse", async () => {
22
- const message = "Feature not implemented";
23
- const error = new NotImplemented(message);
24
- const response = error.toResponse();
25
- expect(response.status).toBe(501);
26
- expect(response.statusText).toBe(message);
27
- expect(response.headers.get("Content-Type")).toBe("application/json");
28
- const body = await response.json();
29
- expect(body).toEqual({ name: "NotImplemented", message });
30
- });
31
- it("should return a Response object from toJson", async () => {
32
- const message = "Feature not implemented";
33
- const error = new NotImplemented(message);
34
- const response = error.toJson();
35
- expect(response.status).toBe(501);
36
- expect(response.statusText).toBe(message);
37
- const body = await response.json();
38
- expect(body).toEqual({ name: "NotImplemented", message });
39
- });
40
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=serverError.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serverError.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/badResponses/__test__/serverError.spec.ts"],"names":[],"mappings":""}
@@ -1,40 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { ServerError } from "../serverError";
3
- describe("ServerError", () => {
4
- it("should create an instance with the correct properties", () => {
5
- const message = "Internal server error occurred";
6
- const cause = { reason: "Database connection failed" };
7
- const error = new ServerError(message, cause);
8
- expect(error.body).toEqual({ name: "ServerError", message });
9
- expect(error.status).toBe(500);
10
- expect(error.statusText).toBe(message);
11
- expect(error.cause).toBe(JSON.stringify(cause));
12
- });
13
- it("should create an instance without a cause", () => {
14
- const message = "Internal server error occurred";
15
- const error = new ServerError(message);
16
- expect(error.body).toEqual({ name: "ServerError", message });
17
- expect(error.status).toBe(500);
18
- expect(error.statusText).toBe(message);
19
- expect(error.cause).toBeUndefined();
20
- });
21
- it("should return a Response object from toResponse", async () => {
22
- const message = "Internal server error occurred";
23
- const error = new ServerError(message);
24
- const response = error.toResponse();
25
- expect(response.status).toBe(500);
26
- expect(response.statusText).toBe(message);
27
- expect(response.headers.get("Content-Type")).toBe("application/json");
28
- const body = await response.json();
29
- expect(body).toEqual({ name: "ServerError", message });
30
- });
31
- it("should return a Response object from toJson", async () => {
32
- const message = "Internal server error occurred";
33
- const error = new ServerError(message);
34
- const response = error.toJson();
35
- expect(response.status).toBe(500);
36
- expect(response.statusText).toBe(message);
37
- const body = await response.json();
38
- expect(body).toEqual({ name: "ServerError", message });
39
- });
40
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=unauthorized.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unauthorized.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/badResponses/__test__/unauthorized.spec.ts"],"names":[],"mappings":""}
@@ -1,40 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { Unauthorized } from "../unauthorized";
3
- describe("Unauthorized", () => {
4
- it("should create an instance with the correct properties", () => {
5
- const message = "Unauthorized access";
6
- const cause = { reason: "Invalid token" };
7
- const error = new Unauthorized(message, cause);
8
- expect(error.body).toEqual({ name: "Unauthorized", message });
9
- expect(error.status).toBe(401);
10
- expect(error.statusText).toBe(message);
11
- expect(error.cause).toBe(JSON.stringify(cause));
12
- });
13
- it("should create an instance without a cause", () => {
14
- const message = "Unauthorized access";
15
- const error = new Unauthorized(message);
16
- expect(error.body).toEqual({ name: "Unauthorized", message });
17
- expect(error.status).toBe(401);
18
- expect(error.statusText).toBe(message);
19
- expect(error.cause).toBeUndefined();
20
- });
21
- it("should return a Response object from toResponse", async () => {
22
- const message = "Unauthorized access";
23
- const error = new Unauthorized(message);
24
- const response = error.toResponse();
25
- expect(response.status).toBe(401);
26
- expect(response.statusText).toBe(message);
27
- expect(response.headers.get("Content-Type")).toBe("application/json");
28
- const body = await response.json();
29
- expect(body).toEqual({ name: "Unauthorized", message });
30
- });
31
- it("should return a Response object from toJson", async () => {
32
- const message = "Unauthorized access";
33
- const error = new Unauthorized(message);
34
- const response = error.toJson();
35
- expect(response.status).toBe(401);
36
- expect(response.statusText).toBe(message);
37
- const body = await response.json();
38
- expect(body).toEqual({ name: "Unauthorized", message });
39
- });
40
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=unprocessableEntity.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unprocessableEntity.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/badResponses/__test__/unprocessableEntity.spec.ts"],"names":[],"mappings":""}
@@ -1,66 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { UnprocessableEntity } from "../unprocessableEntity";
3
- describe("UnprocessableEntity", () => {
4
- it("should create an instance with the correct properties", () => {
5
- const props = {
6
- message: "Validation failed",
7
- data: { invalidField: "email" },
8
- fieldErrors: { email: "Invalid format" },
9
- fields: { email: "example@domain" },
10
- };
11
- const error = new UnprocessableEntity(props);
12
- expect(error.body).toEqual({
13
- name: "UnprocessableEntity",
14
- message: props.message,
15
- data: props.data,
16
- fieldErrors: props.fieldErrors,
17
- fields: props.fields,
18
- });
19
- expect(error.status).toBe(422);
20
- expect(error.statusText).toBe(props.message);
21
- });
22
- it("should create an instance without optional properties", () => {
23
- const props = { message: "Validation failed" };
24
- const error = new UnprocessableEntity(props);
25
- expect(error.body).toEqual({
26
- name: "UnprocessableEntity",
27
- message: props.message,
28
- data: undefined,
29
- fieldErrors: undefined,
30
- fields: undefined,
31
- });
32
- expect(error.status).toBe(422);
33
- expect(error.statusText).toBe(props.message);
34
- });
35
- it("should return a Response object from toResponse", async () => {
36
- const props = { message: "Validation failed" };
37
- const error = new UnprocessableEntity(props);
38
- const response = error.toResponse();
39
- expect(response.status).toBe(422);
40
- expect(response.statusText).toBe(props.message);
41
- expect(response.headers.get("Content-Type")).toBe("application/json");
42
- const body = await response.json();
43
- expect(body).toEqual({
44
- name: "UnprocessableEntity",
45
- message: props.message,
46
- data: undefined,
47
- fieldErrors: undefined,
48
- fields: undefined,
49
- });
50
- });
51
- it("should return a Response object from toJson", async () => {
52
- const props = { message: "Validation failed" };
53
- const error = new UnprocessableEntity(props);
54
- const response = error.toJson();
55
- expect(response.status).toBe(422);
56
- expect(response.statusText).toBe(props.message);
57
- const body = await response.json();
58
- expect(body).toEqual({
59
- name: "UnprocessableEntity",
60
- message: props.message,
61
- data: undefined,
62
- fieldErrors: undefined,
63
- fields: undefined,
64
- });
65
- });
66
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=created.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"created.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/successResponses/__test__/created.spec.ts"],"names":[],"mappings":""}