@arkyn/server 2.0.1-beta.8 → 2.0.1
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/LICENSE.txt +24 -0
- package/README.md +116 -0
- package/dist/api/__test__/deleteRequest.spec.d.ts +2 -0
- package/dist/api/__test__/deleteRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/deleteRequest.spec.js +84 -0
- package/dist/api/__test__/getRequest.spec.d.ts +2 -0
- package/dist/api/__test__/getRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/getRequest.spec.js +62 -0
- package/dist/api/__test__/inboxFlowRequest.spec.d.ts +2 -0
- package/dist/api/__test__/inboxFlowRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/inboxFlowRequest.spec.js +96 -0
- package/dist/api/__test__/makeRequest.spec.d.ts +2 -0
- package/dist/api/__test__/makeRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/makeRequest.spec.js +80 -0
- package/dist/api/__test__/patchRequest.spec.d.ts +2 -0
- package/dist/api/__test__/patchRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/patchRequest.spec.js +84 -0
- package/dist/api/__test__/postRequest.spec.d.ts +2 -0
- package/dist/api/__test__/postRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/postRequest.spec.js +84 -0
- package/dist/api/__test__/putRequest.spec.d.ts +2 -0
- package/dist/api/__test__/putRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/putRequest.spec.js +84 -0
- package/dist/api/deleteRequest.d.ts +13 -0
- package/dist/api/deleteRequest.d.ts.map +1 -0
- package/dist/api/deleteRequest.js +14 -0
- package/dist/api/getRequest.d.ts +12 -0
- package/dist/api/getRequest.d.ts.map +1 -0
- package/dist/api/getRequest.js +13 -0
- package/dist/api/inboxFlowRequest.d.ts +40 -0
- package/dist/api/inboxFlowRequest.d.ts.map +1 -0
- package/dist/api/inboxFlowRequest.js +63 -0
- package/dist/api/makeRequest.d.ts +38 -0
- package/dist/api/makeRequest.d.ts.map +1 -0
- package/dist/api/makeRequest.js +103 -0
- package/dist/api/patchRequest.d.ts +13 -0
- package/dist/api/patchRequest.d.ts.map +1 -0
- package/dist/api/patchRequest.js +14 -0
- package/dist/api/postRequest.d.ts +13 -0
- package/dist/api/postRequest.d.ts.map +1 -0
- package/dist/api/postRequest.js +14 -0
- package/dist/api/putRequest.d.ts +13 -0
- package/dist/api/putRequest.d.ts.map +1 -0
- package/dist/api/putRequest.js +14 -0
- package/dist/config/__test__/apiInstance.spec.d.ts +2 -0
- package/dist/config/__test__/apiInstance.spec.d.ts.map +1 -0
- package/dist/config/__test__/apiInstance.spec.js +86 -0
- package/dist/config/__test__/inboxFlowInstance.spec.d.ts +2 -0
- package/dist/config/__test__/inboxFlowInstance.spec.d.ts.map +1 -0
- package/dist/config/__test__/inboxFlowInstance.spec.js +48 -0
- package/dist/config/apiInstance.d.ts +80 -0
- package/dist/config/apiInstance.d.ts.map +1 -0
- package/dist/config/apiInstance.js +111 -0
- package/dist/config/inboxFlowInstance.d.ts +44 -0
- package/dist/config/inboxFlowInstance.d.ts.map +1 -0
- package/dist/config/inboxFlowInstance.js +46 -0
- package/dist/http/badResponses/__test__/badGateway.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/badGateway.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/badGateway.spec.js +42 -0
- package/dist/http/badResponses/__test__/badRequest.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/badRequest.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/badRequest.spec.js +40 -0
- package/dist/http/badResponses/__test__/conflict.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/conflict.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/conflict.spec.js +40 -0
- package/dist/http/badResponses/__test__/forbidden.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/forbidden.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/forbidden.spec.js +40 -0
- package/dist/http/badResponses/__test__/notFound.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/notFound.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/notFound.spec.js +40 -0
- package/dist/http/badResponses/__test__/notImplemented.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/notImplemented.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/notImplemented.spec.js +40 -0
- package/dist/http/badResponses/__test__/serverError.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/serverError.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/serverError.spec.js +40 -0
- package/dist/http/badResponses/__test__/unauthorized.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/unauthorized.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/unauthorized.spec.js +40 -0
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.js +66 -0
- package/dist/http/badResponses/badGateway.d.ts +23 -0
- package/dist/http/badResponses/badGateway.d.ts.map +1 -1
- package/dist/http/badResponses/badGateway.js +24 -1
- package/dist/http/badResponses/badRequest.d.ts +23 -0
- package/dist/http/badResponses/badRequest.d.ts.map +1 -1
- package/dist/http/badResponses/badRequest.js +24 -1
- package/dist/http/badResponses/conflict.d.ts +23 -0
- package/dist/http/badResponses/conflict.d.ts.map +1 -1
- package/dist/http/badResponses/conflict.js +24 -1
- package/dist/http/badResponses/forbidden.d.ts +23 -0
- package/dist/http/badResponses/forbidden.d.ts.map +1 -1
- package/dist/http/badResponses/forbidden.js +25 -2
- package/dist/http/badResponses/notFound.d.ts +23 -0
- package/dist/http/badResponses/notFound.d.ts.map +1 -1
- package/dist/http/badResponses/notFound.js +24 -1
- package/dist/http/badResponses/notImplemented.d.ts +23 -0
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
- package/dist/http/badResponses/notImplemented.js +24 -1
- package/dist/http/badResponses/serverError.d.ts +23 -0
- package/dist/http/badResponses/serverError.d.ts.map +1 -1
- package/dist/http/badResponses/serverError.js +24 -1
- package/dist/http/badResponses/unauthorized.d.ts +23 -0
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
- package/dist/http/badResponses/unauthorized.js +24 -1
- package/dist/http/badResponses/unprocessableEntity.d.ts +28 -1
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
- package/dist/http/badResponses/unprocessableEntity.js +30 -3
- package/dist/http/successResponses/__test__/created.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/created.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/created.spec.js +57 -0
- package/dist/http/successResponses/__test__/found.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/found.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/found.spec.js +57 -0
- package/dist/http/successResponses/__test__/noContent.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/noContent.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/noContent.spec.js +40 -0
- package/dist/http/successResponses/__test__/success.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/success.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/success.spec.js +60 -0
- package/dist/http/successResponses/__test__/updated.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/updated.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/updated.spec.js +60 -0
- package/dist/http/successResponses/created.d.ts +25 -0
- package/dist/http/successResponses/created.d.ts.map +1 -1
- package/dist/http/successResponses/created.js +25 -0
- package/dist/http/successResponses/found.d.ts +28 -0
- package/dist/http/successResponses/found.d.ts.map +1 -1
- package/dist/http/successResponses/found.js +28 -0
- package/dist/http/successResponses/noContent.d.ts +16 -1
- package/dist/http/successResponses/noContent.d.ts.map +1 -1
- package/dist/http/successResponses/noContent.js +16 -8
- package/dist/http/successResponses/success.d.ts +25 -0
- package/dist/http/successResponses/success.d.ts.map +1 -1
- package/dist/http/successResponses/success.js +25 -0
- package/dist/http/successResponses/updated.d.ts +25 -0
- package/dist/http/successResponses/updated.d.ts.map +1 -1
- package/dist/http/successResponses/updated.js +25 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/services/__test__/decodeRequestBody.spec.d.ts +2 -0
- package/dist/services/__test__/decodeRequestBody.spec.d.ts.map +1 -0
- package/dist/services/__test__/decodeRequestBody.spec.js +39 -0
- package/dist/services/__test__/errorHandler.spec.d.ts +2 -0
- package/dist/services/__test__/errorHandler.spec.d.ts.map +1 -0
- package/dist/services/__test__/errorHandler.spec.js +115 -0
- package/dist/services/__test__/formParse.spec.d.ts +2 -0
- package/dist/services/__test__/formParse.spec.d.ts.map +1 -0
- package/dist/services/__test__/formParse.spec.js +78 -0
- package/dist/services/__test__/getCaller.spec.d.ts +2 -0
- package/dist/services/__test__/getCaller.spec.d.ts.map +1 -0
- package/dist/services/__test__/getCaller.spec.js +60 -0
- package/dist/services/__test__/getScopedParams.spec.d.ts +2 -0
- package/dist/services/__test__/getScopedParams.spec.d.ts.map +1 -0
- package/dist/services/__test__/getScopedParams.spec.js +51 -0
- package/dist/services/__test__/schemaValidator.spec.d.ts +2 -0
- package/dist/services/__test__/schemaValidator.spec.d.ts.map +1 -0
- package/dist/services/__test__/schemaValidator.spec.js +89 -0
- package/dist/services/decodeErrorMessageFromRequest.d.ts +17 -0
- package/dist/services/decodeErrorMessageFromRequest.d.ts.map +1 -0
- package/dist/services/decodeErrorMessageFromRequest.js +30 -0
- package/dist/services/decodeRequestBody.d.ts.map +1 -1
- package/dist/services/decodeRequestBody.js +12 -16
- package/dist/services/errorHandler.d.ts +42 -1
- package/dist/services/errorHandler.d.ts.map +1 -1
- package/dist/services/errorHandler.js +42 -0
- package/dist/services/formParse.d.ts.map +1 -1
- package/dist/services/formParse.js +4 -2
- package/dist/services/getCaller.d.ts +17 -0
- package/dist/services/getCaller.d.ts.map +1 -0
- package/dist/services/getCaller.js +45 -0
- package/dist/services/httpDebug.d.ts +35 -0
- package/dist/services/httpDebug.d.ts.map +1 -0
- package/dist/services/httpDebug.js +56 -0
- package/dist/services/schemaValidator.d.ts +13 -0
- package/dist/services/schemaValidator.d.ts.map +1 -0
- package/dist/services/schemaValidator.js +51 -0
- package/package.json +13 -6
- package/src/api/__test__/deleteRequest.spec.ts +107 -0
- package/src/api/__test__/getRequest.spec.ts +76 -0
- package/src/api/__test__/inboxFlowRequest.spec.ts +125 -0
- package/src/api/__test__/makeRequest.spec.ts +121 -0
- package/src/api/__test__/patchRequest.spec.ts +125 -0
- package/src/api/__test__/postRequest.spec.ts +125 -0
- package/src/api/__test__/putRequest.spec.ts +125 -0
- package/src/api/deleteRequest.ts +22 -0
- package/src/api/getRequest.ts +20 -0
- package/src/api/inboxFlowRequest.ts +76 -0
- package/src/api/makeRequest.ts +117 -0
- package/src/api/patchRequest.ts +22 -0
- package/src/api/postRequest.ts +22 -0
- package/src/api/putRequest.ts +22 -0
- package/src/config/__test__/apiInstance.spec.ts +129 -0
- package/src/config/__test__/inboxFlowInstance.spec.ts +61 -0
- package/src/config/apiInstance.ts +148 -0
- package/src/config/inboxFlowInstance.ts +65 -0
- package/src/http/badResponses/__test__/badGateway.spec.ts +50 -0
- package/src/http/badResponses/__test__/badRequest.spec.ts +50 -0
- package/src/http/badResponses/__test__/conflict.spec.ts +50 -0
- package/src/http/badResponses/__test__/forbidden.spec.ts +50 -0
- package/src/http/badResponses/__test__/notFound.spec.ts +50 -0
- package/src/http/badResponses/__test__/notImplemented.spec.ts +50 -0
- package/src/http/badResponses/__test__/serverError.spec.ts +50 -0
- package/src/http/badResponses/__test__/unauthorized.spec.ts +50 -0
- package/src/http/badResponses/__test__/unprocessableEntity.spec.ts +76 -0
- package/src/http/badResponses/badGateway.ts +29 -2
- package/src/http/badResponses/badRequest.ts +29 -2
- package/src/http/badResponses/conflict.ts +29 -2
- package/src/http/badResponses/forbidden.ts +30 -3
- package/src/http/badResponses/notFound.ts +29 -2
- package/src/http/badResponses/notImplemented.ts +29 -2
- package/src/http/badResponses/serverError.ts +29 -2
- package/src/http/badResponses/unauthorized.ts +29 -2
- package/src/http/badResponses/unprocessableEntity.ts +33 -2
- package/src/http/successResponses/__test__/created.spec.ts +65 -0
- package/src/http/successResponses/__test__/found.spec.ts +65 -0
- package/src/http/successResponses/__test__/noContent.spec.ts +49 -0
- package/src/http/successResponses/__test__/success.spec.ts +68 -0
- package/src/http/successResponses/__test__/updated.spec.ts +68 -0
- package/src/http/successResponses/created.ts +31 -2
- package/src/http/successResponses/found.ts +32 -0
- package/src/http/successResponses/noContent.ts +20 -11
- package/src/http/successResponses/success.ts +31 -2
- package/src/http/successResponses/updated.ts +31 -2
- package/src/index.ts +9 -1
- package/src/services/__test__/decodeRequestBody.spec.ts +51 -0
- package/src/services/__test__/errorHandler.spec.ts +133 -0
- package/src/services/__test__/formParse.spec.ts +96 -0
- package/src/services/__test__/getCaller.spec.ts +78 -0
- package/src/services/__test__/getScopedParams.spec.ts +68 -0
- package/src/services/__test__/schemaValidator.spec.ts +106 -0
- package/src/services/decodeErrorMessageFromRequest.ts +36 -0
- package/src/services/decodeRequestBody.ts +11 -15
- package/src/services/errorHandler.ts +45 -1
- package/src/services/formParse.ts +4 -5
- package/src/services/getCaller.ts +39 -21
- package/src/services/httpDebug.ts +46 -5
- package/vitest.config.ts +5 -0
- package/dist/http/httpDebug.d.ts +0 -3
- package/dist/http/httpDebug.d.ts.map +0 -1
- package/dist/http/httpDebug.js +0 -15
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import { httpDebug } from "
|
|
1
|
+
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
+
/**
|
|
3
|
+
* Represents an HTTP error response with a status code of 404 (Not Found).
|
|
4
|
+
* This class is used to standardize the structure of a "Not Found" error response,
|
|
5
|
+
* including the response body, headers, status, and status text.
|
|
6
|
+
*/
|
|
2
7
|
class NotFound {
|
|
3
8
|
body;
|
|
4
9
|
cause;
|
|
5
10
|
status = 404;
|
|
6
11
|
statusText;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of the `NotFound` class.
|
|
14
|
+
*
|
|
15
|
+
* @param message - A descriptive message explaining the reason the resource was not found.
|
|
16
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
17
|
+
*/
|
|
7
18
|
constructor(message, cause) {
|
|
8
19
|
this.body = { name: "NotFound", message: message };
|
|
9
20
|
this.statusText = message;
|
|
10
21
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
11
22
|
httpDebug("NotFound", this.body, this.cause);
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Converts the `NotFound` instance into a `Response` object with a JSON body.
|
|
26
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
27
|
+
*
|
|
28
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
29
|
+
*/
|
|
13
30
|
toResponse() {
|
|
14
31
|
const responseInit = {
|
|
15
32
|
headers: { "Content-Type": "application/json" },
|
|
@@ -18,6 +35,12 @@ class NotFound {
|
|
|
18
35
|
};
|
|
19
36
|
return new Response(JSON.stringify(this.body), responseInit);
|
|
20
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts the `NotFound` instance into a `Response` object using the `Response.json` method.
|
|
40
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
41
|
+
*
|
|
42
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
43
|
+
*/
|
|
21
44
|
toJson() {
|
|
22
45
|
const responseInit = {
|
|
23
46
|
status: this.status,
|
|
@@ -1,10 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an HTTP error response with a status code of 501 (Not Implemented).
|
|
3
|
+
* This class is used to standardize the structure of a "Not Implemented" error response,
|
|
4
|
+
* including the response body, headers, status, and status text.
|
|
5
|
+
*/
|
|
1
6
|
declare class NotImplemented {
|
|
2
7
|
body: any;
|
|
3
8
|
cause?: any;
|
|
4
9
|
status: number;
|
|
5
10
|
statusText: string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of the `NotImplemented` class.
|
|
13
|
+
*
|
|
14
|
+
* @param message - A descriptive message explaining why the functionality is not implemented.
|
|
15
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
16
|
+
*/
|
|
6
17
|
constructor(message: string, cause?: any);
|
|
18
|
+
/**
|
|
19
|
+
* Converts the `NotImplemented` instance into a `Response` object with a JSON body.
|
|
20
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
21
|
+
*
|
|
22
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
23
|
+
*/
|
|
7
24
|
toResponse(): Response;
|
|
25
|
+
/**
|
|
26
|
+
* Converts the `NotImplemented` instance into a `Response` object using the `Response.json` method.
|
|
27
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
28
|
+
*
|
|
29
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
30
|
+
*/
|
|
8
31
|
toJson(): Response;
|
|
9
32
|
}
|
|
10
33
|
export { NotImplemented };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notImplemented.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/notImplemented.ts"],"names":[],"mappings":"AAEA,cAAM,cAAc;IAClB,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"notImplemented.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/notImplemented.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,cAAc;IAClB,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import { httpDebug } from "
|
|
1
|
+
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
+
/**
|
|
3
|
+
* Represents an HTTP error response with a status code of 501 (Not Implemented).
|
|
4
|
+
* This class is used to standardize the structure of a "Not Implemented" error response,
|
|
5
|
+
* including the response body, headers, status, and status text.
|
|
6
|
+
*/
|
|
2
7
|
class NotImplemented {
|
|
3
8
|
body;
|
|
4
9
|
cause;
|
|
5
10
|
status = 501;
|
|
6
11
|
statusText;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of the `NotImplemented` class.
|
|
14
|
+
*
|
|
15
|
+
* @param message - A descriptive message explaining why the functionality is not implemented.
|
|
16
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
17
|
+
*/
|
|
7
18
|
constructor(message, cause) {
|
|
8
19
|
this.body = { name: "NotImplemented", message: message };
|
|
9
20
|
this.statusText = message;
|
|
10
21
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
11
22
|
httpDebug("NotImplemented", this.body, this.cause);
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Converts the `NotImplemented` instance into a `Response` object with a JSON body.
|
|
26
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
27
|
+
*
|
|
28
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
29
|
+
*/
|
|
13
30
|
toResponse() {
|
|
14
31
|
const responseInit = {
|
|
15
32
|
headers: { "Content-Type": "application/json" },
|
|
@@ -18,6 +35,12 @@ class NotImplemented {
|
|
|
18
35
|
};
|
|
19
36
|
return new Response(JSON.stringify(this.body), responseInit);
|
|
20
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts the `NotImplemented` instance into a `Response` object using the `Response.json` method.
|
|
40
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
41
|
+
*
|
|
42
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
43
|
+
*/
|
|
21
44
|
toJson() {
|
|
22
45
|
const responseInit = {
|
|
23
46
|
status: this.status,
|
|
@@ -1,10 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an HTTP error response with a status code of 500 (Internal Server Error).
|
|
3
|
+
* This class is used to standardize the structure of a "Server Error" response,
|
|
4
|
+
* including the response body, headers, status, and status text.
|
|
5
|
+
*/
|
|
1
6
|
declare class ServerError {
|
|
2
7
|
body: any;
|
|
3
8
|
cause?: any;
|
|
4
9
|
status: number;
|
|
5
10
|
statusText: string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of the `ServerError` class.
|
|
13
|
+
*
|
|
14
|
+
* @param message - A descriptive message explaining the cause of the server error.
|
|
15
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
16
|
+
*/
|
|
6
17
|
constructor(message: string, cause?: any);
|
|
18
|
+
/**
|
|
19
|
+
* Converts the `ServerError` instance into a `Response` object with a JSON body.
|
|
20
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
21
|
+
*
|
|
22
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
23
|
+
*/
|
|
7
24
|
toResponse(): Response;
|
|
25
|
+
/**
|
|
26
|
+
* Converts the `ServerError` instance into a `Response` object using the `Response.json` method.
|
|
27
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
28
|
+
*
|
|
29
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
30
|
+
*/
|
|
8
31
|
toJson(): Response;
|
|
9
32
|
}
|
|
10
33
|
export { ServerError };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverError.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/serverError.ts"],"names":[],"mappings":"AAEA,cAAM,WAAW;IACf,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"serverError.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/serverError.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,WAAW;IACf,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import { httpDebug } from "
|
|
1
|
+
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
+
/**
|
|
3
|
+
* Represents an HTTP error response with a status code of 500 (Internal Server Error).
|
|
4
|
+
* This class is used to standardize the structure of a "Server Error" response,
|
|
5
|
+
* including the response body, headers, status, and status text.
|
|
6
|
+
*/
|
|
2
7
|
class ServerError {
|
|
3
8
|
body;
|
|
4
9
|
cause;
|
|
5
10
|
status = 500;
|
|
6
11
|
statusText;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of the `ServerError` class.
|
|
14
|
+
*
|
|
15
|
+
* @param message - A descriptive message explaining the cause of the server error.
|
|
16
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
17
|
+
*/
|
|
7
18
|
constructor(message, cause) {
|
|
8
19
|
this.body = { name: "ServerError", message: message };
|
|
9
20
|
this.statusText = message;
|
|
10
21
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
11
22
|
httpDebug("ServerError", this.body, this.cause);
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Converts the `ServerError` instance into a `Response` object with a JSON body.
|
|
26
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
27
|
+
*
|
|
28
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
29
|
+
*/
|
|
13
30
|
toResponse() {
|
|
14
31
|
const responseInit = {
|
|
15
32
|
headers: { "Content-Type": "application/json" },
|
|
@@ -18,6 +35,12 @@ class ServerError {
|
|
|
18
35
|
};
|
|
19
36
|
return new Response(JSON.stringify(this.body), responseInit);
|
|
20
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts the `ServerError` instance into a `Response` object using the `Response.json` method.
|
|
40
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
41
|
+
*
|
|
42
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
43
|
+
*/
|
|
21
44
|
toJson() {
|
|
22
45
|
const responseInit = {
|
|
23
46
|
status: this.status,
|
|
@@ -1,10 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an HTTP error response with a status code of 401 (Unauthorized).
|
|
3
|
+
* This class is used to standardize the structure of an "Unauthorized" error response,
|
|
4
|
+
* including the response body, headers, status, and status text.
|
|
5
|
+
*/
|
|
1
6
|
declare class Unauthorized {
|
|
2
7
|
body: any;
|
|
3
8
|
cause?: any;
|
|
4
9
|
status: number;
|
|
5
10
|
statusText: string;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of the `Unauthorized` class.
|
|
13
|
+
*
|
|
14
|
+
* @param message - A descriptive message explaining why the request is unauthorized.
|
|
15
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
16
|
+
*/
|
|
6
17
|
constructor(message: string, cause?: any);
|
|
18
|
+
/**
|
|
19
|
+
* Converts the `Unauthorized` instance into a `Response` object with a JSON body.
|
|
20
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
21
|
+
*
|
|
22
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
23
|
+
*/
|
|
7
24
|
toResponse(): Response;
|
|
25
|
+
/**
|
|
26
|
+
* Converts the `Unauthorized` instance into a `Response` object using the `Response.json` method.
|
|
27
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
28
|
+
*
|
|
29
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
30
|
+
*/
|
|
8
31
|
toJson(): Response;
|
|
9
32
|
}
|
|
10
33
|
export { Unauthorized };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unauthorized.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unauthorized.ts"],"names":[],"mappings":"AAEA,cAAM,YAAY;IAChB,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"unauthorized.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unauthorized.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,YAAY;IAChB,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import { httpDebug } from "
|
|
1
|
+
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
+
/**
|
|
3
|
+
* Represents an HTTP error response with a status code of 401 (Unauthorized).
|
|
4
|
+
* This class is used to standardize the structure of an "Unauthorized" error response,
|
|
5
|
+
* including the response body, headers, status, and status text.
|
|
6
|
+
*/
|
|
2
7
|
class Unauthorized {
|
|
3
8
|
body;
|
|
4
9
|
cause;
|
|
5
10
|
status = 401;
|
|
6
11
|
statusText;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of the `Unauthorized` class.
|
|
14
|
+
*
|
|
15
|
+
* @param message - A descriptive message explaining why the request is unauthorized.
|
|
16
|
+
* @param cause - Optional additional information about the cause of the error.
|
|
17
|
+
*/
|
|
7
18
|
constructor(message, cause) {
|
|
8
19
|
this.body = { name: "Unauthorized", message: message };
|
|
9
20
|
this.statusText = message;
|
|
10
21
|
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
11
22
|
httpDebug("Unauthorized", this.body, this.cause);
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Converts the `Unauthorized` instance into a `Response` object with a JSON body.
|
|
26
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
27
|
+
*
|
|
28
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
29
|
+
*/
|
|
13
30
|
toResponse() {
|
|
14
31
|
const responseInit = {
|
|
15
32
|
headers: { "Content-Type": "application/json" },
|
|
@@ -18,6 +35,12 @@ class Unauthorized {
|
|
|
18
35
|
};
|
|
19
36
|
return new Response(JSON.stringify(this.body), responseInit);
|
|
20
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts the `Unauthorized` instance into a `Response` object using the `Response.json` method.
|
|
40
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
41
|
+
*
|
|
42
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
43
|
+
*/
|
|
21
44
|
toJson() {
|
|
22
45
|
const responseInit = {
|
|
23
46
|
status: this.status,
|
|
@@ -4,12 +4,39 @@ type UnprocessableEntityProps = {
|
|
|
4
4
|
fields?: Record<string, string>;
|
|
5
5
|
message?: string;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* Represents an HTTP error response with a status code of 422 (Unprocessable Entity).
|
|
9
|
+
* This class is used to standardize the structure of an "Unprocessable Entity" error response,
|
|
10
|
+
* including the response body, headers, status, and status text.
|
|
11
|
+
*/
|
|
7
12
|
declare class UnprocessableEntity {
|
|
8
13
|
body: any;
|
|
9
14
|
status: number;
|
|
10
15
|
statusText: string;
|
|
11
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Creates an instance of the `UnprocessableEntity` class.
|
|
18
|
+
*
|
|
19
|
+
* @param props - An object containing details about the error, such as:
|
|
20
|
+
* - `data`: Additional data related to the error.
|
|
21
|
+
* - `fieldErrors`: A record of field-specific error messages.
|
|
22
|
+
* - `fields`: A record of field values that caused the error.
|
|
23
|
+
* - `message`: A descriptive message explaining the error.
|
|
24
|
+
* @param enableDebug - A boolean indicating whether to enable debug logging for this error.
|
|
25
|
+
*/
|
|
26
|
+
constructor(props: UnprocessableEntityProps, enableDebug?: boolean);
|
|
27
|
+
/**
|
|
28
|
+
* Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
|
|
29
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
30
|
+
*
|
|
31
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
32
|
+
*/
|
|
12
33
|
toResponse(): Response;
|
|
34
|
+
/**
|
|
35
|
+
* Converts the `UnprocessableEntity` instance into a `Response` object using the `Response.json` method.
|
|
36
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
37
|
+
*
|
|
38
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
39
|
+
*/
|
|
13
40
|
toJson(): Response;
|
|
14
41
|
}
|
|
15
42
|
export { UnprocessableEntity };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unprocessableEntity.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unprocessableEntity.ts"],"names":[],"mappings":"AAEA,KAAK,wBAAwB,GAAG;IAC9B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,cAAM,mBAAmB;IACvB,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"unprocessableEntity.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unprocessableEntity.ts"],"names":[],"mappings":"AAEA,KAAK,wBAAwB,GAAG;IAC9B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AAEH,cAAM,mBAAmB;IACvB,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;;;;OASG;gBAES,KAAK,EAAE,wBAAwB,EAAE,WAAW,UAAQ;IAahE;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -1,9 +1,24 @@
|
|
|
1
|
-
import { httpDebug } from "
|
|
1
|
+
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
+
/**
|
|
3
|
+
* Represents an HTTP error response with a status code of 422 (Unprocessable Entity).
|
|
4
|
+
* This class is used to standardize the structure of an "Unprocessable Entity" error response,
|
|
5
|
+
* including the response body, headers, status, and status text.
|
|
6
|
+
*/
|
|
2
7
|
class UnprocessableEntity {
|
|
3
8
|
body;
|
|
4
9
|
status = 422;
|
|
5
10
|
statusText;
|
|
6
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of the `UnprocessableEntity` class.
|
|
13
|
+
*
|
|
14
|
+
* @param props - An object containing details about the error, such as:
|
|
15
|
+
* - `data`: Additional data related to the error.
|
|
16
|
+
* - `fieldErrors`: A record of field-specific error messages.
|
|
17
|
+
* - `fields`: A record of field values that caused the error.
|
|
18
|
+
* - `message`: A descriptive message explaining the error.
|
|
19
|
+
* @param enableDebug - A boolean indicating whether to enable debug logging for this error.
|
|
20
|
+
*/
|
|
21
|
+
constructor(props, enableDebug = false) {
|
|
7
22
|
this.statusText = props.message || "Unprocessable Entity";
|
|
8
23
|
this.body = {
|
|
9
24
|
name: "UnprocessableEntity",
|
|
@@ -12,8 +27,14 @@ class UnprocessableEntity {
|
|
|
12
27
|
fieldErrors: props.fieldErrors,
|
|
13
28
|
fields: props.fields,
|
|
14
29
|
};
|
|
15
|
-
httpDebug("UnprocessableEntity", this.body);
|
|
30
|
+
enableDebug && httpDebug("UnprocessableEntity", this.body);
|
|
16
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
|
|
34
|
+
* This method ensures the response has the appropriate headers, status, and status text.
|
|
35
|
+
*
|
|
36
|
+
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
37
|
+
*/
|
|
17
38
|
toResponse() {
|
|
18
39
|
const responseInit = {
|
|
19
40
|
headers: { "Content-Type": "application/json" },
|
|
@@ -22,6 +43,12 @@ class UnprocessableEntity {
|
|
|
22
43
|
};
|
|
23
44
|
return new Response(JSON.stringify(this.body), responseInit);
|
|
24
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Converts the `UnprocessableEntity` instance into a `Response` object using the `Response.json` method.
|
|
48
|
+
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
49
|
+
*
|
|
50
|
+
* @returns A `Response` object with the JSON body and response metadata.
|
|
51
|
+
*/
|
|
25
52
|
toJson() {
|
|
26
53
|
const responseInit = {
|
|
27
54
|
status: this.status,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"created.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/successResponses/__test__/created.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { Created } from "../created";
|
|
3
|
+
describe("Created", () => {
|
|
4
|
+
it("should create a response with default values", () => {
|
|
5
|
+
const body = { message: "Resource created" };
|
|
6
|
+
const created = new Created(body);
|
|
7
|
+
const response = created.toResponse();
|
|
8
|
+
expect(response.status).toBe(201);
|
|
9
|
+
expect(response.statusText).toBe("Resource created successfully");
|
|
10
|
+
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
11
|
+
response.json().then((data) => {
|
|
12
|
+
expect(data).toEqual(body);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
it("should create a response with custom values", () => {
|
|
16
|
+
const body = { message: "Custom resource created" };
|
|
17
|
+
const init = {
|
|
18
|
+
headers: { "X-Custom-Header": "CustomValue" },
|
|
19
|
+
status: 202,
|
|
20
|
+
statusText: "Accepted",
|
|
21
|
+
};
|
|
22
|
+
const created = new Created(body, init);
|
|
23
|
+
const response = created.toResponse();
|
|
24
|
+
expect(response.status).toBe(202);
|
|
25
|
+
expect(response.statusText).toBe("Accepted");
|
|
26
|
+
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
27
|
+
expect(response.headers.get("X-Custom-Header")).toBe("CustomValue");
|
|
28
|
+
response.json().then((data) => {
|
|
29
|
+
expect(data).toEqual(body);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
it("should create a JSON response with default values", () => {
|
|
33
|
+
const body = { message: "Resource created" };
|
|
34
|
+
const created = new Created(body);
|
|
35
|
+
const response = created.toJson();
|
|
36
|
+
expect(response.status).toBe(201);
|
|
37
|
+
expect(response.statusText).toBe("Resource created successfully");
|
|
38
|
+
response.json().then((data) => {
|
|
39
|
+
expect(data).toEqual(body);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
it("should create a JSON response with custom values", () => {
|
|
43
|
+
const body = { message: "Custom resource created" };
|
|
44
|
+
const init = {
|
|
45
|
+
headers: { "X-Custom-Header": "CustomValue" },
|
|
46
|
+
status: 202,
|
|
47
|
+
statusText: "Accepted",
|
|
48
|
+
};
|
|
49
|
+
const created = new Created(body, init);
|
|
50
|
+
const response = created.toJson();
|
|
51
|
+
expect(response.status).toBe(202);
|
|
52
|
+
expect(response.statusText).toBe("Accepted");
|
|
53
|
+
response.json().then((data) => {
|
|
54
|
+
expect(data).toEqual(body);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"found.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/successResponses/__test__/found.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { Found } from "../found";
|
|
3
|
+
describe("Found", () => {
|
|
4
|
+
it("should create a response with default values", () => {
|
|
5
|
+
const body = { message: "Resource found" };
|
|
6
|
+
const found = new Found(body);
|
|
7
|
+
const response = found.toResponse();
|
|
8
|
+
expect(response.status).toBe(302);
|
|
9
|
+
expect(response.statusText).toBe("Found");
|
|
10
|
+
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
11
|
+
response.json().then((data) => {
|
|
12
|
+
expect(data).toEqual(body);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
it("should create a response with custom values", () => {
|
|
16
|
+
const body = { message: "Custom resource found" };
|
|
17
|
+
const init = {
|
|
18
|
+
headers: { "X-Custom-Header": "CustomValue" },
|
|
19
|
+
status: 301,
|
|
20
|
+
statusText: "Moved Permanently",
|
|
21
|
+
};
|
|
22
|
+
const found = new Found(body, init);
|
|
23
|
+
const response = found.toResponse();
|
|
24
|
+
expect(response.status).toBe(301);
|
|
25
|
+
expect(response.statusText).toBe("Moved Permanently");
|
|
26
|
+
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
27
|
+
expect(response.headers.get("X-Custom-Header")).toBe("CustomValue");
|
|
28
|
+
response.json().then((data) => {
|
|
29
|
+
expect(data).toEqual(body);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
it("should create a JSON response with default values", () => {
|
|
33
|
+
const body = { message: "Resource found" };
|
|
34
|
+
const found = new Found(body);
|
|
35
|
+
const response = found.toJson();
|
|
36
|
+
expect(response.status).toBe(302);
|
|
37
|
+
expect(response.statusText).toBe("Found");
|
|
38
|
+
response.json().then((data) => {
|
|
39
|
+
expect(data).toEqual(body);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
it("should create a JSON response with custom values", () => {
|
|
43
|
+
const body = { message: "Custom resource found" };
|
|
44
|
+
const init = {
|
|
45
|
+
headers: { "X-Custom-Header": "CustomValue" },
|
|
46
|
+
status: 301,
|
|
47
|
+
statusText: "Moved Permanently",
|
|
48
|
+
};
|
|
49
|
+
const found = new Found(body, init);
|
|
50
|
+
const response = found.toJson();
|
|
51
|
+
expect(response.status).toBe(301);
|
|
52
|
+
expect(response.statusText).toBe("Moved Permanently");
|
|
53
|
+
response.json().then((data) => {
|
|
54
|
+
expect(data).toEqual(body);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noContent.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/successResponses/__test__/noContent.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { NoContent } from "../noContent";
|
|
3
|
+
describe("NoContent", () => {
|
|
4
|
+
it("should create a NoContent instance with default values", () => {
|
|
5
|
+
const noContent = new NoContent();
|
|
6
|
+
expect(noContent.status).toBe(204);
|
|
7
|
+
expect(noContent.statusText).toBe("No content");
|
|
8
|
+
expect(noContent.headers).toEqual({});
|
|
9
|
+
});
|
|
10
|
+
it("should create a NoContent instance with custom values", () => {
|
|
11
|
+
const customInit = {
|
|
12
|
+
headers: { "Content-Type": "application/json" },
|
|
13
|
+
status: 200,
|
|
14
|
+
statusText: "Custom Status",
|
|
15
|
+
};
|
|
16
|
+
const noContent = new NoContent(customInit);
|
|
17
|
+
expect(noContent.status).toBe(200);
|
|
18
|
+
expect(noContent.statusText).toBe("Custom Status");
|
|
19
|
+
expect(noContent.headers).toEqual(customInit.headers);
|
|
20
|
+
});
|
|
21
|
+
it("should return a Response object with default values from toResponse", () => {
|
|
22
|
+
const noContent = new NoContent();
|
|
23
|
+
const response = noContent.toResponse();
|
|
24
|
+
expect(response.status).toBe(204);
|
|
25
|
+
expect(response.statusText).toBe("No content");
|
|
26
|
+
expect(response.headers.get("Content-Type")).toBeNull();
|
|
27
|
+
});
|
|
28
|
+
it("should return a Response object with custom values from toResponse", () => {
|
|
29
|
+
const customInit = {
|
|
30
|
+
headers: { "Content-Type": "application/json" },
|
|
31
|
+
status: 200,
|
|
32
|
+
statusText: "Custom Status",
|
|
33
|
+
};
|
|
34
|
+
const noContent = new NoContent(customInit);
|
|
35
|
+
const response = noContent.toResponse();
|
|
36
|
+
expect(response.status).toBe(200);
|
|
37
|
+
expect(response.statusText).toBe("Custom Status");
|
|
38
|
+
expect(response.headers.get("Content-Type")).toBe("application/json");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"success.spec.d.ts","sourceRoot":"","sources":["../../../../src/http/successResponses/__test__/success.spec.ts"],"names":[],"mappings":""}
|