@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,50 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { Conflict } from "../conflict";
3
-
4
- describe("Conflict", () => {
5
- it("should create an instance with the correct properties", () => {
6
- const message = "Conflict occurred";
7
- const cause = { reason: "Duplicate entry" };
8
- const error = new Conflict(message, cause);
9
-
10
- expect(error.body).toEqual({ name: "Conflict", message });
11
- expect(error.status).toBe(409);
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 = "Conflict occurred";
18
- const error = new Conflict(message);
19
-
20
- expect(error.body).toEqual({ name: "Conflict", message });
21
- expect(error.status).toBe(409);
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 = "Conflict occurred";
28
- const error = new Conflict(message);
29
- const response = error.toResponse();
30
-
31
- expect(response.status).toBe(409);
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: "Conflict", message });
37
- });
38
-
39
- it("should return a Response object from toJson", async () => {
40
- const message = "Conflict occurred";
41
- const error = new Conflict(message);
42
- const response = error.toJson();
43
-
44
- expect(response.status).toBe(409);
45
- expect(response.statusText).toBe(message);
46
-
47
- const body = await response.json();
48
- expect(body).toEqual({ name: "Conflict", message });
49
- });
50
- });
@@ -1,50 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { Forbidden } from "../forbidden";
3
-
4
- describe("Forbidden", () => {
5
- it("should create an instance with the correct properties", () => {
6
- const message = "Access is forbidden";
7
- const cause = { reason: "Insufficient permissions" };
8
- const error = new Forbidden(message, cause);
9
-
10
- expect(error.body).toEqual({ name: "Forbidden", message });
11
- expect(error.status).toBe(403);
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 = "Access is forbidden";
18
- const error = new Forbidden(message);
19
-
20
- expect(error.body).toEqual({ name: "Forbidden", message });
21
- expect(error.status).toBe(403);
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 = "Access is forbidden";
28
- const error = new Forbidden(message);
29
- const response = error.toResponse();
30
-
31
- expect(response.status).toBe(403);
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: "Forbidden", message });
37
- });
38
-
39
- it("should return a Response object from toJson", async () => {
40
- const message = "Access is forbidden";
41
- const error = new Forbidden(message);
42
- const response = error.toJson();
43
-
44
- expect(response.status).toBe(403);
45
- expect(response.statusText).toBe(message);
46
-
47
- const body = await response.json();
48
- expect(body).toEqual({ name: "Forbidden", message });
49
- });
50
- });
@@ -1,50 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { NotFound } from "../notFound";
3
-
4
- describe("NotFound", () => {
5
- it("should create an instance with the correct properties", () => {
6
- const message = "Resource not found";
7
- const cause = { reason: "ID does not exist" };
8
- const error = new NotFound(message, cause);
9
-
10
- expect(error.body).toEqual({ name: "NotFound", message });
11
- expect(error.status).toBe(404);
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 = "Resource not found";
18
- const error = new NotFound(message);
19
-
20
- expect(error.body).toEqual({ name: "NotFound", message });
21
- expect(error.status).toBe(404);
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 = "Resource not found";
28
- const error = new NotFound(message);
29
- const response = error.toResponse();
30
-
31
- expect(response.status).toBe(404);
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: "NotFound", message });
37
- });
38
-
39
- it("should return a Response object from toJson", async () => {
40
- const message = "Resource not found";
41
- const error = new NotFound(message);
42
- const response = error.toJson();
43
-
44
- expect(response.status).toBe(404);
45
- expect(response.statusText).toBe(message);
46
-
47
- const body = await response.json();
48
- expect(body).toEqual({ name: "NotFound", message });
49
- });
50
- });
@@ -1,50 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { NotImplemented } from "../notImplemented";
3
-
4
- describe("NotImplemented", () => {
5
- it("should create an instance with the correct properties", () => {
6
- const message = "Feature not implemented";
7
- const cause = { reason: "Under development" };
8
- const error = new NotImplemented(message, cause);
9
-
10
- expect(error.body).toEqual({ name: "NotImplemented", message });
11
- expect(error.status).toBe(501);
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 = "Feature not implemented";
18
- const error = new NotImplemented(message);
19
-
20
- expect(error.body).toEqual({ name: "NotImplemented", message });
21
- expect(error.status).toBe(501);
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 = "Feature not implemented";
28
- const error = new NotImplemented(message);
29
- const response = error.toResponse();
30
-
31
- expect(response.status).toBe(501);
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: "NotImplemented", message });
37
- });
38
-
39
- it("should return a Response object from toJson", async () => {
40
- const message = "Feature not implemented";
41
- const error = new NotImplemented(message);
42
- const response = error.toJson();
43
-
44
- expect(response.status).toBe(501);
45
- expect(response.statusText).toBe(message);
46
-
47
- const body = await response.json();
48
- expect(body).toEqual({ name: "NotImplemented", message });
49
- });
50
- });
@@ -1,50 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { ServerError } from "../serverError";
3
-
4
- describe("ServerError", () => {
5
- it("should create an instance with the correct properties", () => {
6
- const message = "Internal server error occurred";
7
- const cause = { reason: "Database connection failed" };
8
- const error = new ServerError(message, cause);
9
-
10
- expect(error.body).toEqual({ name: "ServerError", message });
11
- expect(error.status).toBe(500);
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 = "Internal server error occurred";
18
- const error = new ServerError(message);
19
-
20
- expect(error.body).toEqual({ name: "ServerError", message });
21
- expect(error.status).toBe(500);
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 = "Internal server error occurred";
28
- const error = new ServerError(message);
29
- const response = error.toResponse();
30
-
31
- expect(response.status).toBe(500);
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: "ServerError", message });
37
- });
38
-
39
- it("should return a Response object from toJson", async () => {
40
- const message = "Internal server error occurred";
41
- const error = new ServerError(message);
42
- const response = error.toJson();
43
-
44
- expect(response.status).toBe(500);
45
- expect(response.statusText).toBe(message);
46
-
47
- const body = await response.json();
48
- expect(body).toEqual({ name: "ServerError", message });
49
- });
50
- });
@@ -1,50 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { Unauthorized } from "../unauthorized";
3
-
4
- describe("Unauthorized", () => {
5
- it("should create an instance with the correct properties", () => {
6
- const message = "Unauthorized access";
7
- const cause = { reason: "Invalid token" };
8
- const error = new Unauthorized(message, cause);
9
-
10
- expect(error.body).toEqual({ name: "Unauthorized", message });
11
- expect(error.status).toBe(401);
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 = "Unauthorized access";
18
- const error = new Unauthorized(message);
19
-
20
- expect(error.body).toEqual({ name: "Unauthorized", message });
21
- expect(error.status).toBe(401);
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 = "Unauthorized access";
28
- const error = new Unauthorized(message);
29
- const response = error.toResponse();
30
-
31
- expect(response.status).toBe(401);
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: "Unauthorized", message });
37
- });
38
-
39
- it("should return a Response object from toJson", async () => {
40
- const message = "Unauthorized access";
41
- const error = new Unauthorized(message);
42
- const response = error.toJson();
43
-
44
- expect(response.status).toBe(401);
45
- expect(response.statusText).toBe(message);
46
-
47
- const body = await response.json();
48
- expect(body).toEqual({ name: "Unauthorized", message });
49
- });
50
- });
@@ -1,76 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { UnprocessableEntity } from "../unprocessableEntity";
3
-
4
- describe("UnprocessableEntity", () => {
5
- it("should create an instance with the correct properties", () => {
6
- const props = {
7
- message: "Validation failed",
8
- data: { invalidField: "email" },
9
- fieldErrors: { email: "Invalid format" },
10
- fields: { email: "example@domain" },
11
- };
12
- const error = new UnprocessableEntity(props);
13
-
14
- expect(error.body).toEqual({
15
- name: "UnprocessableEntity",
16
- message: props.message,
17
- data: props.data,
18
- fieldErrors: props.fieldErrors,
19
- fields: props.fields,
20
- });
21
- expect(error.status).toBe(422);
22
- expect(error.statusText).toBe(props.message);
23
- });
24
-
25
- it("should create an instance without optional properties", () => {
26
- const props = { message: "Validation failed" };
27
- const error = new UnprocessableEntity(props);
28
-
29
- expect(error.body).toEqual({
30
- name: "UnprocessableEntity",
31
- message: props.message,
32
- data: undefined,
33
- fieldErrors: undefined,
34
- fields: undefined,
35
- });
36
- expect(error.status).toBe(422);
37
- expect(error.statusText).toBe(props.message);
38
- });
39
-
40
- it("should return a Response object from toResponse", async () => {
41
- const props = { message: "Validation failed" };
42
- const error = new UnprocessableEntity(props);
43
- const response = error.toResponse();
44
-
45
- expect(response.status).toBe(422);
46
- expect(response.statusText).toBe(props.message);
47
- expect(response.headers.get("Content-Type")).toBe("application/json");
48
-
49
- const body = await response.json();
50
- expect(body).toEqual({
51
- name: "UnprocessableEntity",
52
- message: props.message,
53
- data: undefined,
54
- fieldErrors: undefined,
55
- fields: undefined,
56
- });
57
- });
58
-
59
- it("should return a Response object from toJson", async () => {
60
- const props = { message: "Validation failed" };
61
- const error = new UnprocessableEntity(props);
62
- const response = error.toJson();
63
-
64
- expect(response.status).toBe(422);
65
- expect(response.statusText).toBe(props.message);
66
-
67
- const body = await response.json();
68
- expect(body).toEqual({
69
- name: "UnprocessableEntity",
70
- message: props.message,
71
- data: undefined,
72
- fieldErrors: undefined,
73
- fields: undefined,
74
- });
75
- });
76
- });
@@ -1,65 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { Created } from "../created";
3
-
4
- describe("Created", () => {
5
- it("should create a response with default values", () => {
6
- const body = { message: "Resource created" };
7
- const created = new Created(body);
8
-
9
- const response = created.toResponse();
10
- expect(response.status).toBe(201);
11
- expect(response.statusText).toBe("Resource created successfully");
12
- expect(response.headers.get("Content-Type")).toBe("application/json");
13
- response.json().then((data) => {
14
- expect(data).toEqual(body);
15
- });
16
- });
17
-
18
- it("should create a response with custom values", () => {
19
- const body = { message: "Custom resource created" };
20
- const init = {
21
- headers: { "X-Custom-Header": "CustomValue" },
22
- status: 202,
23
- statusText: "Accepted",
24
- };
25
- const created = new Created(body, init);
26
-
27
- const response = created.toResponse();
28
- expect(response.status).toBe(202);
29
- expect(response.statusText).toBe("Accepted");
30
- expect(response.headers.get("Content-Type")).toBe("application/json");
31
- expect(response.headers.get("X-Custom-Header")).toBe("CustomValue");
32
- response.json().then((data) => {
33
- expect(data).toEqual(body);
34
- });
35
- });
36
-
37
- it("should create a JSON response with default values", () => {
38
- const body = { message: "Resource created" };
39
- const created = new Created(body);
40
-
41
- const response = created.toJson();
42
- expect(response.status).toBe(201);
43
- expect(response.statusText).toBe("Resource created successfully");
44
- response.json().then((data) => {
45
- expect(data).toEqual(body);
46
- });
47
- });
48
-
49
- it("should create a JSON response with custom values", () => {
50
- const body = { message: "Custom resource created" };
51
- const init = {
52
- headers: { "X-Custom-Header": "CustomValue" },
53
- status: 202,
54
- statusText: "Accepted",
55
- };
56
- const created = new Created(body, init);
57
-
58
- const response = created.toJson();
59
- expect(response.status).toBe(202);
60
- expect(response.statusText).toBe("Accepted");
61
- response.json().then((data) => {
62
- expect(data).toEqual(body);
63
- });
64
- });
65
- });
@@ -1,65 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { Found } from "../found";
3
-
4
- describe("Found", () => {
5
- it("should create a response with default values", () => {
6
- const body = { message: "Resource found" };
7
- const found = new Found(body);
8
-
9
- const response = found.toResponse();
10
- expect(response.status).toBe(302);
11
- expect(response.statusText).toBe("Found");
12
- expect(response.headers.get("Content-Type")).toBe("application/json");
13
- response.json().then((data) => {
14
- expect(data).toEqual(body);
15
- });
16
- });
17
-
18
- it("should create a response with custom values", () => {
19
- const body = { message: "Custom resource found" };
20
- const init = {
21
- headers: { "X-Custom-Header": "CustomValue" },
22
- status: 301,
23
- statusText: "Moved Permanently",
24
- };
25
- const found = new Found(body, init);
26
-
27
- const response = found.toResponse();
28
- expect(response.status).toBe(301);
29
- expect(response.statusText).toBe("Moved Permanently");
30
- expect(response.headers.get("Content-Type")).toBe("application/json");
31
- expect(response.headers.get("X-Custom-Header")).toBe("CustomValue");
32
- response.json().then((data) => {
33
- expect(data).toEqual(body);
34
- });
35
- });
36
-
37
- it("should create a JSON response with default values", () => {
38
- const body = { message: "Resource found" };
39
- const found = new Found(body);
40
-
41
- const response = found.toJson();
42
- expect(response.status).toBe(302);
43
- expect(response.statusText).toBe("Found");
44
- response.json().then((data) => {
45
- expect(data).toEqual(body);
46
- });
47
- });
48
-
49
- it("should create a JSON response with custom values", () => {
50
- const body = { message: "Custom resource found" };
51
- const init = {
52
- headers: { "X-Custom-Header": "CustomValue" },
53
- status: 301,
54
- statusText: "Moved Permanently",
55
- };
56
- const found = new Found(body, init);
57
-
58
- const response = found.toJson();
59
- expect(response.status).toBe(301);
60
- expect(response.statusText).toBe("Moved Permanently");
61
- response.json().then((data) => {
62
- expect(data).toEqual(body);
63
- });
64
- });
65
- });
@@ -1,49 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { NoContent } from "../noContent";
3
-
4
- describe("NoContent", () => {
5
- it("should create a NoContent instance with default values", () => {
6
- const noContent = new NoContent();
7
-
8
- expect(noContent.status).toBe(204);
9
- expect(noContent.statusText).toBe("No content");
10
- expect(noContent.headers).toEqual({});
11
- });
12
-
13
- it("should create a NoContent instance with custom values", () => {
14
- const customInit = {
15
- headers: { "Content-Type": "application/json" },
16
- status: 200,
17
- statusText: "Custom Status",
18
- };
19
- const noContent = new NoContent(customInit);
20
-
21
- expect(noContent.status).toBe(200);
22
- expect(noContent.statusText).toBe("Custom Status");
23
- expect(noContent.headers).toEqual(customInit.headers);
24
- });
25
-
26
- it("should return a Response object with default values from toResponse", () => {
27
- const noContent = new NoContent();
28
- const response = noContent.toResponse();
29
-
30
- expect(response.status).toBe(204);
31
- expect(response.statusText).toBe("No content");
32
- expect(response.headers.get("Content-Type")).toBeNull();
33
- });
34
-
35
- it("should return a Response object with custom values from toResponse", () => {
36
- const customInit = {
37
- headers: { "Content-Type": "application/json" },
38
- status: 200,
39
- statusText: "Custom Status",
40
- };
41
-
42
- const noContent = new NoContent(customInit);
43
- const response = noContent.toResponse();
44
-
45
- expect(response.status).toBe(200);
46
- expect(response.statusText).toBe("Custom Status");
47
- expect(response.headers.get("Content-Type")).toBe("application/json");
48
- });
49
- });
@@ -1,68 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { Success } from "../success";
3
-
4
- describe("Success", () => {
5
- it("should create a response with default values", () => {
6
- const body = { message: "Success" };
7
- const success = new Success(body);
8
-
9
- const response = success.toResponse();
10
- expect(response.status).toBe(200);
11
- expect(response.statusText).toBe("OK");
12
- expect(response.headers.get("Content-Type")).toBe("application/json");
13
- return response.json().then((data) => {
14
- expect(data).toEqual(body);
15
- });
16
- });
17
-
18
- it("should create a response with custom values", () => {
19
- const body = { message: "Custom Success" };
20
- const init = {
21
- headers: { "X-Custom-Header": "CustomValue" },
22
- status: 201,
23
- statusText: "Created",
24
- };
25
- const success = new Success(body, init);
26
-
27
- const response = success.toResponse();
28
- expect(response.status).toBe(201);
29
- expect(response.statusText).toBe("Created");
30
- expect(response.headers.get("Content-Type")).toBe("application/json");
31
- expect(response.headers.get("X-Custom-Header")).toBe("CustomValue");
32
- return response.json().then((data) => {
33
- expect(data).toEqual(body);
34
- });
35
- });
36
-
37
- it("should create a JSON response with default values using toJson", () => {
38
- const body = { message: "Success" };
39
- const success = new Success(body);
40
-
41
- const response = success.toJson();
42
- expect(response.status).toBe(200);
43
- expect(response.statusText).toBe("OK");
44
- expect(response.headers.get("Content-Type")).toBe("application/json");
45
- return response.json().then((data) => {
46
- expect(data).toEqual(body);
47
- });
48
- });
49
-
50
- it("should create a JSON response with custom values using toJson", () => {
51
- const body = { message: "Custom Success" };
52
- const init = {
53
- headers: { "X-Custom-Header": "CustomValue" },
54
- status: 201,
55
- statusText: "Created",
56
- };
57
- const success = new Success(body, init);
58
-
59
- const response = success.toJson();
60
- expect(response.status).toBe(201);
61
- expect(response.statusText).toBe("Created");
62
- expect(response.headers.get("Content-Type")).toBe("application/json");
63
- expect(response.headers.get("X-Custom-Header")).toBe("CustomValue");
64
- return response.json().then((data) => {
65
- expect(data).toEqual(body);
66
- });
67
- });
68
- });