@flink-app/test-utils 2.0.0-alpha.82 → 2.0.0-alpha.83
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 +6 -0
- package/dist/mocks.d.ts +14 -1
- package/dist/mocks.js +17 -0
- package/package.json +2 -2
- package/src/mocks.ts +21 -1
package/CHANGELOG.md
CHANGED
package/dist/mocks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FlinkAuthPlugin, FlinkRequest } from "@flink-app/flink";
|
|
1
|
+
import { FlinkAuthPlugin, FlinkContext, FlinkRequest } from "@flink-app/flink";
|
|
2
2
|
interface TestFlinkRequest<T, P, Q> extends Omit<Partial<FlinkRequest<T, P, Q>>, "body" | "params" | "query"> {
|
|
3
3
|
body?: T;
|
|
4
4
|
params?: P;
|
|
@@ -17,4 +17,17 @@ export declare function mockReq<T, P, Q>(req?: TestFlinkRequest<T, P, Q>): Flink
|
|
|
17
17
|
* @returns
|
|
18
18
|
*/
|
|
19
19
|
export declare function noOpAuthPlugin(): FlinkAuthPlugin;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a mock FlinkContext with only the parts you need.
|
|
22
|
+
* Useful for testing services with mocked dependencies.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const carService = new CarService();
|
|
27
|
+
* carService.ctx = mockCtx<AppCtx>({
|
|
28
|
+
* repos: { carRepo: mockCarRepo },
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function mockCtx<C extends FlinkContext>(partial?: Partial<C>): C;
|
|
20
33
|
export {};
|
package/dist/mocks.js
CHANGED
|
@@ -49,6 +49,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
50
|
exports.mockReq = mockReq;
|
|
51
51
|
exports.noOpAuthPlugin = noOpAuthPlugin;
|
|
52
|
+
exports.mockCtx = mockCtx;
|
|
52
53
|
/**
|
|
53
54
|
* Creates a mocked FlinkRequest object where only essential properties are required.
|
|
54
55
|
* Will convert req body to JSON to ensure the body is a plain object.
|
|
@@ -81,3 +82,19 @@ function noOpAuthPlugin() {
|
|
|
81
82
|
}); }); },
|
|
82
83
|
};
|
|
83
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Creates a mock FlinkContext with only the parts you need.
|
|
87
|
+
* Useful for testing services with mocked dependencies.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const carService = new CarService();
|
|
92
|
+
* carService.ctx = mockCtx<AppCtx>({
|
|
93
|
+
* repos: { carRepo: mockCarRepo },
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
function mockCtx(partial) {
|
|
98
|
+
if (partial === void 0) { partial = {}; }
|
|
99
|
+
return __assign({ repos: {}, plugins: {} }, partial);
|
|
100
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flink-app/test-utils",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.83",
|
|
4
4
|
"description": "Test utils for Flink",
|
|
5
5
|
"author": "joel@frost.se",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"jasmine-ts": "^0.3.3",
|
|
24
24
|
"ts-node": "^10.9.2",
|
|
25
25
|
"tsc-watch": "^4.2.9",
|
|
26
|
-
"@flink-app/flink": "2.0.0-alpha.
|
|
26
|
+
"@flink-app/flink": "2.0.0-alpha.83"
|
|
27
27
|
},
|
|
28
28
|
"gitHead": "4243e3b3cd6d4e1ca001a61baa8436bf2bbe4113",
|
|
29
29
|
"scripts": {
|
package/src/mocks.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FlinkAuthPlugin, FlinkRequest } from "@flink-app/flink";
|
|
1
|
+
import { FlinkAuthPlugin, FlinkContext, FlinkRequest } from "@flink-app/flink";
|
|
2
2
|
|
|
3
3
|
interface TestFlinkRequest<T, P, Q> extends Omit<Partial<FlinkRequest<T, P, Q>>, "body" | "params" | "query"> {
|
|
4
4
|
body?: T;
|
|
@@ -42,3 +42,23 @@ export function noOpAuthPlugin(): FlinkAuthPlugin {
|
|
|
42
42
|
createToken: async () => "mock-token",
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Creates a mock FlinkContext with only the parts you need.
|
|
48
|
+
* Useful for testing services with mocked dependencies.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const carService = new CarService();
|
|
53
|
+
* carService.ctx = mockCtx<AppCtx>({
|
|
54
|
+
* repos: { carRepo: mockCarRepo },
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function mockCtx<C extends FlinkContext>(partial: Partial<C> = {}): C {
|
|
59
|
+
return {
|
|
60
|
+
repos: {},
|
|
61
|
+
plugins: {},
|
|
62
|
+
...partial,
|
|
63
|
+
} as C;
|
|
64
|
+
}
|