express-zod-api 5.1.0-beta1 → 5.1.0-beta2
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/CHANGELOG.md +4 -0
- package/README.md +34 -3
- package/dist/mock.js +8 -5
- package/dist/mock.js.map +1 -1
- package/dist-esm/mock.js +5 -5
- package/dist-esm/mock.js.map +1 -1
- package/dist-esm/package.json +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -41,8 +41,9 @@ Start your API server with I/O schema validation and custom middlewares in minut
|
|
|
41
41
|
13. [Enabling HTTPS](#enabling-https)
|
|
42
42
|
14. [Exporting endpoint types to frontend](#exporting-endpoint-types-to-frontend)
|
|
43
43
|
15. [Creating a documentation](#creating-a-documentation)
|
|
44
|
-
5. [
|
|
45
|
-
1. [
|
|
44
|
+
5. [Additional hints](#additional-hints)
|
|
45
|
+
1. [How to test endpoints](#how-to-test-endpoints)
|
|
46
|
+
2. [Excessive properties in endpoint output](#excessive-properties-in-endpoint-output)
|
|
46
47
|
6. [Your input to my output](#your-input-to-my-output)
|
|
47
48
|
|
|
48
49
|
You can find the release notes in [Changelog](CHANGELOG.md). Along with recommendations for migrating from
|
|
@@ -660,7 +661,37 @@ const exampleEndpoint = defaultEndpointsFactory.build({
|
|
|
660
661
|
_See the example of the generated documentation
|
|
661
662
|
[here](https://github.com/RobinTail/express-zod-api/blob/master/example/example.swagger.yaml)_
|
|
662
663
|
|
|
663
|
-
#
|
|
664
|
+
# Additional hints
|
|
665
|
+
|
|
666
|
+
## How to test endpoints
|
|
667
|
+
|
|
668
|
+
The way to test endpoints is to mock the request, response, and logger objects, invoke the `execute()` method, and
|
|
669
|
+
assert the expectations for calls of certain mocked methods. The library provides a special method that makes mocking
|
|
670
|
+
easier, so the test might look the following way:
|
|
671
|
+
|
|
672
|
+
```typescript
|
|
673
|
+
import { testEndpoint } from "express-zod-api";
|
|
674
|
+
|
|
675
|
+
test("should respond successfully", async () => {
|
|
676
|
+
const { responseMock, loggerMock } = await testEndpoint({
|
|
677
|
+
endpoint: yourEndpoint,
|
|
678
|
+
// available options: requestProps, responseProps, configProps, loggerProps
|
|
679
|
+
requestProps: {
|
|
680
|
+
method: "POST", // default: GET
|
|
681
|
+
body: { ... },
|
|
682
|
+
},
|
|
683
|
+
});
|
|
684
|
+
expect(loggerMock.error).toBeCalledTimes(0);
|
|
685
|
+
expect(responseMock.status).toBeCalledWith(200);
|
|
686
|
+
expect(responseMock.json).toBeCalledWith({
|
|
687
|
+
status: "success",
|
|
688
|
+
data: { ... },
|
|
689
|
+
});
|
|
690
|
+
});
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
_This method is optimized for the standard result handler. With the flexibility to customize, you can add additional
|
|
694
|
+
properties as needed._
|
|
664
695
|
|
|
665
696
|
## Excessive properties in endpoint output
|
|
666
697
|
|
package/dist/mock.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.testEndpoint = void 0;
|
|
4
|
-
const
|
|
7
|
+
const http_1 = __importDefault(require("http"));
|
|
5
8
|
const mime_1 = require("./mime");
|
|
6
9
|
/**
|
|
7
10
|
* @description You need to install Jest and probably @types/jest to use this method
|
|
@@ -18,11 +21,11 @@ const testEndpoint = async ({ endpoint, requestProps, responseProps, configProps
|
|
|
18
21
|
const responseMock = {
|
|
19
22
|
writableEnded: false,
|
|
20
23
|
statusCode: 200,
|
|
21
|
-
statusMessage:
|
|
24
|
+
statusMessage: http_1.default.STATUS_CODES[200],
|
|
22
25
|
set: jest.fn(() => responseMock),
|
|
23
|
-
status: jest.fn((
|
|
24
|
-
responseMock.statusCode =
|
|
25
|
-
responseMock.statusMessage =
|
|
26
|
+
status: jest.fn((code) => {
|
|
27
|
+
responseMock.statusCode = code;
|
|
28
|
+
responseMock.statusMessage = http_1.default.STATUS_CODES[code];
|
|
26
29
|
return responseMock;
|
|
27
30
|
}),
|
|
28
31
|
json: jest.fn(() => responseMock),
|
package/dist/mock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":";;;;;;AACA,gDAAwB;AAIxB,iCAAkC;AAYlC;;GAEG;AACI,MAAM,YAAY,GAAG,KAAK,EAI/B,EACA,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,QAAQ,GACyB,EAAE,EAAE;IACrC,IAAI,CAAC,IAAI,IAAI,QAAQ,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;KAC7E;IACD,MAAM,WAAW,GAGhB;QACC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,eAAQ,CAAC;QAC/B,GAAG,YAAY;KAChB,CAAC;IACF,MAAM,YAAY,GAOjB;QACC,aAAa,EAAE,KAAK;QACpB,UAAU,EAAE,GAAG;QACf,aAAa,EAAE,cAAI,CAAC,YAAY,CAAC,GAAG,CAAC;QACrC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC;QAChC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,IAAY,EAAE,EAAE;YAC/B,YAAY,CAAC,UAAU,GAAG,IAAI,CAAC;YAC/B,YAAY,CAAC,aAAa,GAAG,cAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YACrD,OAAO,YAAY,CAAC;QACtB,CAAC,CAAC;QACF,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC;QACjC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;YAChB,YAAY,CAAC,aAAa,GAAG,IAAI,CAAC;YAClC,OAAO,YAAY,CAAC;QACtB,CAAC,CAAC;QACF,GAAG,aAAa;KACjB,CAAC;IACF,MAAM,UAAU,GAGf;QACC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QACf,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QACf,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;QAChB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;QAChB,GAAG,WAAW;KACf,CAAC;IACF,MAAM,UAAU,GAAG;QACjB,IAAI,EAAE,KAAK;QACX,MAAM,EAAE,UAAU;QAClB,GAAG,WAAW;KACf,CAAC;IACF,MAAM,QAAQ,CAAC,OAAO,CAAC;QACrB,OAAO,EAAE,WAAiC;QAC1C,QAAQ,EAAE,YAAmC;QAC7C,MAAM,EAAE,UAA0B;QAClC,MAAM,EAAE,UAA+B;KACxC,CAAC,CAAC;IACH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;AACnD,CAAC,CAAC;AArEW,QAAA,YAAY,gBAqEvB"}
|
package/dist-esm/mock.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import http from "http";
|
|
2
2
|
import { mimeJson } from "./mime.js";
|
|
3
3
|
/**
|
|
4
4
|
* @description You need to install Jest and probably @types/jest to use this method
|
|
@@ -15,11 +15,11 @@ export const testEndpoint = async ({ endpoint, requestProps, responseProps, conf
|
|
|
15
15
|
const responseMock = {
|
|
16
16
|
writableEnded: false,
|
|
17
17
|
statusCode: 200,
|
|
18
|
-
statusMessage:
|
|
18
|
+
statusMessage: http.STATUS_CODES[200],
|
|
19
19
|
set: jest.fn(() => responseMock),
|
|
20
|
-
status: jest.fn((
|
|
21
|
-
responseMock.statusCode =
|
|
22
|
-
responseMock.statusMessage =
|
|
20
|
+
status: jest.fn((code) => {
|
|
21
|
+
responseMock.statusCode = code;
|
|
22
|
+
responseMock.statusMessage = http.STATUS_CODES[code];
|
|
23
23
|
return responseMock;
|
|
24
24
|
}),
|
|
25
25
|
json: jest.fn(() => responseMock),
|
package/dist-esm/mock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAYlC;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAI/B,EACA,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,QAAQ,GACyB,EAAE,EAAE;IACrC,IAAI,CAAC,IAAI,IAAI,QAAQ,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;KAC7E;IACD,MAAM,WAAW,GAGhB;QACC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC;QAC/B,GAAG,YAAY;KAChB,CAAC;IACF,MAAM,YAAY,GAOjB;QACC,aAAa,EAAE,KAAK;QACpB,UAAU,EAAE,GAAG;QACf,aAAa,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;QACrC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC;QAChC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,IAAY,EAAE,EAAE;YAC/B,YAAY,CAAC,UAAU,GAAG,IAAI,CAAC;YAC/B,YAAY,CAAC,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YACrD,OAAO,YAAY,CAAC;QACtB,CAAC,CAAC;QACF,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC;QACjC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;YAChB,YAAY,CAAC,aAAa,GAAG,IAAI,CAAC;YAClC,OAAO,YAAY,CAAC;QACtB,CAAC,CAAC;QACF,GAAG,aAAa;KACjB,CAAC;IACF,MAAM,UAAU,GAGf;QACC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QACf,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QACf,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;QAChB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;QAChB,GAAG,WAAW;KACf,CAAC;IACF,MAAM,UAAU,GAAG;QACjB,IAAI,EAAE,KAAK;QACX,MAAM,EAAE,UAAU;QAClB,GAAG,WAAW;KACf,CAAC;IACF,MAAM,QAAQ,CAAC,OAAO,CAAC;QACrB,OAAO,EAAE,WAAiC;QAC1C,QAAQ,EAAE,YAAmC;QAC7C,MAAM,EAAE,UAA0B;QAClC,MAAM,EAAE,UAA+B;KACxC,CAAC,CAAC;IACH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;AACnD,CAAC,CAAC"}
|
package/dist-esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"5.1.0-
|
|
1
|
+
{"type":"module","version":"5.1.0-beta2"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-zod-api",
|
|
3
|
-
"version": "5.1.0-
|
|
3
|
+
"version": "5.1.0-beta2",
|
|
4
4
|
"description": "A Typescript library to help you get an API server up and running with I/O schema validation and custom middlewares in minutes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"zod": "3.11.6"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"jest": "
|
|
49
|
-
"
|
|
48
|
+
"@types/jest": "*",
|
|
49
|
+
"jest": ">=25 <28"
|
|
50
50
|
},
|
|
51
51
|
"peerDependenciesMeta": {
|
|
52
52
|
"jest": {
|