@loopstack/testing 0.15.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.
package/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ Copyright 2025 Loopstack GmbH
8
+
9
+ Licensed under the Apache License, Version 2.0 (the "License");
10
+ you may not use this skeleton application except in compliance with the License.
11
+ You may obtain a copy of the License at
12
+
13
+ http://www.apache.org/licenses/LICENSE-2.0
14
+
15
+ Unless required by applicable law or agreed to in writing, software
16
+ distributed under the License is distributed on an "AS IS" BASIS,
17
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ See the License for the specific language governing permissions and
19
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # Loopstack Testing Module
@@ -0,0 +1 @@
1
+ export * from './test-builder';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./test-builder"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA8B"}
@@ -0,0 +1,2 @@
1
+ import { TestingModuleBuilder } from '@nestjs/testing';
2
+ export declare function mockCoreModuleProviders(builder: TestingModuleBuilder): TestingModuleBuilder;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mockCoreModuleProviders = mockCoreModuleProviders;
4
+ const typeorm_1 = require("@nestjs/typeorm");
5
+ const common_1 = require("@loopstack/common");
6
+ const core_1 = require("@loopstack/core");
7
+ const createMockRepository = () => ({
8
+ find: jest.fn().mockResolvedValue([]),
9
+ findOne: jest.fn().mockResolvedValue(null),
10
+ findOneBy: jest.fn().mockResolvedValue(null),
11
+ findBy: jest.fn().mockResolvedValue([]),
12
+ create: jest.fn().mockImplementation((dto) => dto),
13
+ save: jest.fn().mockImplementation((entity) => Promise.resolve({ id: 'mock-id', ...entity })),
14
+ update: jest.fn().mockResolvedValue({ affected: 1 }),
15
+ delete: jest.fn().mockResolvedValue({ affected: 1 }),
16
+ remove: jest.fn().mockResolvedValue({}),
17
+ });
18
+ function mockCoreModuleProviders(builder) {
19
+ return builder
20
+ .overrideProvider((0, typeorm_1.getRepositoryToken)(common_1.PipelineEntity))
21
+ .useValue(createMockRepository)
22
+ .overrideProvider((0, typeorm_1.getRepositoryToken)(common_1.WorkflowEntity))
23
+ .useValue(createMockRepository)
24
+ .overrideProvider((0, typeorm_1.getRepositoryToken)(common_1.DocumentEntity))
25
+ .useValue(createMockRepository)
26
+ .overrideProvider((0, typeorm_1.getRepositoryToken)(common_1.WorkspaceEntity))
27
+ .useValue(createMockRepository)
28
+ .overrideProvider((0, typeorm_1.getRepositoryToken)(common_1.NamespaceEntity))
29
+ .useValue(createMockRepository)
30
+ .overrideProvider(core_1.MigrationsService)
31
+ .useValue({})
32
+ .overrideProvider(core_1.TaskSchedulerService)
33
+ .useValue({});
34
+ }
35
+ //# sourceMappingURL=core-module-mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-module-mock.js","sourceRoot":"","sources":["../../src/test-builder/core-module-mock.ts"],"names":[],"mappings":";;AAiBA,0DAgBC;AAhCD,6CAAqD;AACrD,8CAAqH;AACrH,0CAA0E;AAE1E,MAAM,oBAAoB,GAAG,GAAG,EAAE,CAAC,CAAC;IAClC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC;IACrC,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC;IAC1C,SAAS,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC;IAC5C,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC;IACvC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC;IAClD,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;IAC7F,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;IACpD,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;IACpD,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC;CACxC,CAAC,CAAC;AAEH,SAAgB,uBAAuB,CAAC,OAA6B;IACnE,OAAO,OAAO;SACX,gBAAgB,CAAC,IAAA,4BAAkB,EAAC,uBAAc,CAAC,CAAC;SACpD,QAAQ,CAAC,oBAAoB,CAAC;SAC9B,gBAAgB,CAAC,IAAA,4BAAkB,EAAC,uBAAc,CAAC,CAAC;SACpD,QAAQ,CAAC,oBAAoB,CAAC;SAC9B,gBAAgB,CAAC,IAAA,4BAAkB,EAAC,uBAAc,CAAC,CAAC;SACpD,QAAQ,CAAC,oBAAoB,CAAC;SAC9B,gBAAgB,CAAC,IAAA,4BAAkB,EAAC,wBAAe,CAAC,CAAC;SACrD,QAAQ,CAAC,oBAAoB,CAAC;SAC9B,gBAAgB,CAAC,IAAA,4BAAkB,EAAC,wBAAe,CAAC,CAAC;SACrD,QAAQ,CAAC,oBAAoB,CAAC;SAC9B,gBAAgB,CAAC,wBAAiB,CAAC;SACnC,QAAQ,CAAC,EAAE,CAAC;SACZ,gBAAgB,CAAC,2BAAoB,CAAC;SACtC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { DocumentEntity } from '@loopstack/common';
2
+ export declare function createDocumentMock<T>(source: new (...args: any[]) => any, content: T, documentProps?: Partial<DocumentEntity>): DocumentEntity;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDocumentMock = createDocumentMock;
4
+ function createDocumentMock(source, content, documentProps = {}) {
5
+ return {
6
+ ...documentProps,
7
+ blockName: source.name,
8
+ content: content,
9
+ };
10
+ }
11
+ //# sourceMappingURL=create-document-mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-document-mock.js","sourceRoot":"","sources":["../../src/test-builder/create-document-mock.ts"],"names":[],"mappings":";;AAEA,gDAUC;AAVD,SAAgB,kBAAkB,CAChC,MAAmC,EACnC,OAAU,EACV,gBAAyC,EAAE;IAE3C,OAAO;QACL,GAAG,aAAa;QAChB,SAAS,EAAE,MAAM,CAAC,IAAI;QACtB,OAAO,EAAE,OAAO;KACI,CAAC;AACzB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { TestingModuleBuilder } from '@nestjs/testing';
2
+ export declare function createTestingModule(options: {
3
+ imports: any[];
4
+ providers: any[];
5
+ }): TestingModuleBuilder;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTestingModule = createTestingModule;
4
+ const testing_1 = require("@nestjs/testing");
5
+ const config_1 = require("@nestjs/config");
6
+ const core_1 = require("@loopstack/core");
7
+ function createTestingModule(options) {
8
+ return testing_1.Test.createTestingModule({
9
+ imports: [
10
+ config_1.ConfigModule.forRoot({
11
+ isGlobal: true,
12
+ }),
13
+ core_1.LoopCoreModule,
14
+ ...options.imports,
15
+ ],
16
+ providers: [
17
+ ...options.providers,
18
+ ]
19
+ });
20
+ }
21
+ //# sourceMappingURL=create-testing-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-testing-module.js","sourceRoot":"","sources":["../../src/test-builder/create-testing-module.ts"],"names":[],"mappings":";;AAIA,kDAaC;AAjBD,6CAA6D;AAC7D,2CAA8C;AAC9C,0CAAiD;AAEjD,SAAgB,mBAAmB,CAAC,OAA4C;IAC9E,OAAO,cAAI,CAAC,mBAAmB,CAAC;QAC9B,OAAO,EAAE;YACP,qBAAY,CAAC,OAAO,CAAC;gBACnB,QAAQ,EAAE,IAAI;aACf,CAAC;YACF,qBAAc;YACd,GAAG,OAAO,CAAC,OAAO;SACnB;QACD,SAAS,EAAE;YACT,GAAG,OAAO,CAAC,SAAS;SACrB;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { WorkflowExecutionContextDto } from '@loopstack/core';
2
+ export declare function getToolResult(ctx: WorkflowExecutionContextDto, transitionId: string | number, toolId: string | number): any;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getToolResult = getToolResult;
4
+ function getToolResult(ctx, transitionId, toolId) {
5
+ return ctx.state.transitionResults?.[transitionId]?.toolResults?.[toolId];
6
+ }
7
+ //# sourceMappingURL=get-tool-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-tool-result.js","sourceRoot":"","sources":["../../src/test-builder/get-tool-result.ts"],"names":[],"mappings":";;AAEA,sCAMC;AAND,SAAgB,aAAa,CAC3B,GAAgC,EAChC,YAA6B,EAC7B,MAAuB;IAEvB,OAAO,GAAG,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,YAAY,CAAC,EAAE,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from './core-module-mock';
2
+ export * from './workflow-test-builder';
3
+ export * from './create-testing-module';
4
+ export * from './create-document-mock';
5
+ export * from './get-tool-result';
6
+ export * from './tool-test-builder';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./core-module-mock"), exports);
18
+ __exportStar(require("./workflow-test-builder"), exports);
19
+ __exportStar(require("./create-testing-module"), exports);
20
+ __exportStar(require("./create-document-mock"), exports);
21
+ __exportStar(require("./get-tool-result"), exports);
22
+ __exportStar(require("./tool-test-builder"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test-builder/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,0DAAwC;AACxC,0DAAwC;AACxC,yDAAuC;AACvC,oDAAkC;AAClC,sDAAoC"}
@@ -0,0 +1,23 @@
1
+ import { TestingModule } from '@nestjs/testing';
2
+ import { Type } from '@nestjs/common';
3
+ import { ToolBase, WorkflowExecution } from '@loopstack/core';
4
+ export interface ToolMock {
5
+ validate: jest.Mock;
6
+ execute: jest.Mock;
7
+ }
8
+ export declare function createToolMock(): ToolMock;
9
+ export declare function createExecutionContext(overrides?: any): WorkflowExecution;
10
+ export declare class ToolTestBuilder<TTool extends ToolBase<any> = ToolBase<any>> {
11
+ private toolClass?;
12
+ private providers;
13
+ private overrides;
14
+ forTool<T extends ToolBase<any>>(toolClass: Type<T>): ToolTestBuilder<T>;
15
+ withProvider(...providers: Type<any>[]): this;
16
+ withProviders(...providers: any[]): this;
17
+ withMock<T>(token: Type<T> | string | symbol, mock: Partial<T> | any): this;
18
+ withOverride<T>(token: Type<T> | string | symbol, mock: Partial<T> | any): this;
19
+ withToolMock<T>(toolClass: Type<T>): this;
20
+ compile(): Promise<TestingModule>;
21
+ private verifyToolDecorators;
22
+ }
23
+ export declare function createToolTest(): ToolTestBuilder;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ToolTestBuilder = void 0;
4
+ exports.createToolMock = createToolMock;
5
+ exports.createExecutionContext = createExecutionContext;
6
+ exports.createToolTest = createToolTest;
7
+ const testing_1 = require("@nestjs/testing");
8
+ const common_1 = require("@loopstack/common");
9
+ const lodash_1 = require("lodash");
10
+ function createToolMock() {
11
+ return {
12
+ validate: jest.fn().mockImplementation((v) => v),
13
+ execute: jest.fn().mockResolvedValue({ data: undefined }),
14
+ };
15
+ }
16
+ function createExecutionContext(overrides) {
17
+ return (0, lodash_1.merge)({
18
+ runtime: {
19
+ error: false,
20
+ stop: false,
21
+ availableTransitions: [],
22
+ transition: {
23
+ id: 'test-transition',
24
+ from: 'start',
25
+ to: 'end',
26
+ },
27
+ persistenceState: { documentsUpdated: false },
28
+ },
29
+ }, overrides);
30
+ }
31
+ class ToolTestBuilder {
32
+ toolClass;
33
+ providers = [];
34
+ overrides = new Map();
35
+ forTool(toolClass) {
36
+ this.verifyToolDecorators(toolClass);
37
+ this.toolClass = toolClass;
38
+ this.providers.push(toolClass);
39
+ return this;
40
+ }
41
+ withProvider(...providers) {
42
+ this.providers.push(...providers);
43
+ return this;
44
+ }
45
+ withProviders(...providers) {
46
+ this.providers.push(...providers);
47
+ return this;
48
+ }
49
+ withMock(token, mock) {
50
+ this.providers.push({
51
+ provide: token,
52
+ useValue: mock,
53
+ });
54
+ return this;
55
+ }
56
+ withOverride(token, mock) {
57
+ this.overrides.set(token, mock);
58
+ return this;
59
+ }
60
+ withToolMock(toolClass) {
61
+ const mock = createToolMock();
62
+ this.providers.push({
63
+ provide: toolClass,
64
+ useValue: mock,
65
+ });
66
+ return this;
67
+ }
68
+ async compile() {
69
+ if (!this.toolClass) {
70
+ throw new Error('Tool class not set. Call forTool() first.');
71
+ }
72
+ let builder = testing_1.Test.createTestingModule({
73
+ providers: this.providers,
74
+ });
75
+ for (const [token, mock] of this.overrides) {
76
+ builder = builder.overrideProvider(token).useValue(mock);
77
+ }
78
+ const module = await builder.compile();
79
+ return module;
80
+ }
81
+ verifyToolDecorators(toolClass) {
82
+ const blockConfig = Reflect.getMetadata(common_1.BLOCK_METADATA_KEY, toolClass);
83
+ if (!blockConfig) {
84
+ throw new Error(`Tool ${toolClass.name} is not decorated with @BlockConfig`);
85
+ }
86
+ }
87
+ }
88
+ exports.ToolTestBuilder = ToolTestBuilder;
89
+ function createToolTest() {
90
+ return new ToolTestBuilder();
91
+ }
92
+ //# sourceMappingURL=tool-test-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-test-builder.js","sourceRoot":"","sources":["../../src/test-builder/tool-test-builder.ts"],"names":[],"mapp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AS,CAAC,CAAC;QACvE,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,QAAQ,SAAS,CAAC,IAAI,qCAAqC,CAC5D,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AA3FD,0CA2FC;AAeD,SAAgB,cAAc;IAC5B,OAAO,IAAI,eAAe,EAAE,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { TestingModule } from '@nestjs/testing';
2
+ import { Type } from '@nestjs/common';
3
+ import { WorkflowEntity } from '@loopstack/common';
4
+ export declare const DEFAULT_WORKFLOW_ENTITY: Omit<WorkflowEntity, 'namespace'>;
5
+ export interface WorkflowServiceMock {
6
+ save: jest.Mock;
7
+ create: jest.Mock;
8
+ findOneByQuery: jest.Mock;
9
+ }
10
+ export declare function createWorkflowServiceMock(mockEntity?: {}): WorkflowServiceMock;
11
+ export declare class WorkflowTestBuilder<TWorkflow = any> {
12
+ private imports;
13
+ private providers;
14
+ private overrides;
15
+ private workflowClass?;
16
+ private workflowServiceMock;
17
+ private module;
18
+ constructor();
19
+ forWorkflow<T>(workflowClass: Type<T>): WorkflowTestBuilder<T>;
20
+ withImports(...imports: any[]): this;
21
+ withProvider(...providers: Type<any>[]): this;
22
+ withProviders(...providers: any[]): this;
23
+ withMock<T>(token: Type<T> | string | symbol, mock: Partial<T> | any): this;
24
+ withOverride<T>(token: Type<T> | string | symbol, mock: Partial<T> | any): this;
25
+ withToolMock<T>(toolClass: Type<T>): this;
26
+ withToolOverride<T>(toolClass: Type<T>): this;
27
+ withExistingWorkflow(entity: Partial<WorkflowEntity>): this;
28
+ compile(): Promise<TestingModule>;
29
+ }
30
+ export declare function createWorkflowTest(): WorkflowTestBuilder;
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkflowTestBuilder = exports.DEFAULT_WORKFLOW_ENTITY = void 0;
4
+ exports.createWorkflowServiceMock = createWorkflowServiceMock;
5
+ exports.createWorkflowTest = createWorkflowTest;
6
+ const common_1 = require("@loopstack/common");
7
+ const core_1 = require("@loopstack/core");
8
+ const core_module_mock_1 = require("./core-module-mock");
9
+ const create_testing_module_1 = require("./create-testing-module");
10
+ const tool_test_builder_1 = require("./tool-test-builder");
11
+ exports.DEFAULT_WORKFLOW_ENTITY = {
12
+ id: '00000000-0000-0000-0000-000000000000',
13
+ blockName: '',
14
+ title: '',
15
+ index: '1',
16
+ progress: 0,
17
+ status: common_1.WorkflowState.Pending,
18
+ hasError: false,
19
+ errorMessage: null,
20
+ createdAt: new Date(),
21
+ updatedAt: new Date(),
22
+ place: 'start',
23
+ transitionResults: null,
24
+ inputData: {},
25
+ availableTransitions: null,
26
+ history: null,
27
+ schema: null,
28
+ error: null,
29
+ ui: null,
30
+ namespaceId: '',
31
+ pipelineId: '',
32
+ labels: [],
33
+ hashRecord: null,
34
+ createdBy: '',
35
+ documents: [],
36
+ dependencies: [],
37
+ };
38
+ function createWorkflowServiceMock(mockEntity = {}) {
39
+ return {
40
+ save: jest.fn(),
41
+ create: jest.fn().mockImplementation((input) => Promise.resolve({
42
+ ...exports.DEFAULT_WORKFLOW_ENTITY,
43
+ ...input,
44
+ id: crypto.randomUUID(),
45
+ ...mockEntity,
46
+ })),
47
+ findOneByQuery: jest.fn().mockResolvedValue(undefined),
48
+ };
49
+ }
50
+ class WorkflowTestBuilder {
51
+ imports = [];
52
+ providers = [];
53
+ overrides = new Map();
54
+ workflowClass;
55
+ workflowServiceMock;
56
+ module;
57
+ constructor() {
58
+ this.workflowServiceMock = createWorkflowServiceMock();
59
+ }
60
+ forWorkflow(workflowClass) {
61
+ this.workflowClass = workflowClass;
62
+ this.providers.push(workflowClass);
63
+ return this;
64
+ }
65
+ withImports(...imports) {
66
+ this.imports.push(...imports);
67
+ return this;
68
+ }
69
+ withProvider(...providers) {
70
+ this.providers.push(...providers);
71
+ return this;
72
+ }
73
+ withProviders(...providers) {
74
+ this.providers.push(...providers);
75
+ return this;
76
+ }
77
+ withMock(token, mock) {
78
+ this.providers.push({
79
+ provide: token,
80
+ useValue: mock,
81
+ });
82
+ return this;
83
+ }
84
+ withOverride(token, mock) {
85
+ this.overrides.set(token, mock);
86
+ return this;
87
+ }
88
+ withToolMock(toolClass) {
89
+ const mock = (0, tool_test_builder_1.createToolMock)();
90
+ this.providers.push({
91
+ provide: toolClass,
92
+ useValue: mock,
93
+ });
94
+ return this;
95
+ }
96
+ withToolOverride(toolClass) {
97
+ const mock = (0, tool_test_builder_1.createToolMock)();
98
+ this.overrides.set(toolClass, mock);
99
+ return this;
100
+ }
101
+ withExistingWorkflow(entity) {
102
+ this.workflowServiceMock = createWorkflowServiceMock(entity);
103
+ return this;
104
+ }
105
+ async compile() {
106
+ let builder = (0, create_testing_module_1.createTestingModule)({
107
+ imports: this.imports,
108
+ providers: this.providers,
109
+ });
110
+ builder = (0, core_module_mock_1.mockCoreModuleProviders)(builder);
111
+ builder = builder
112
+ .overrideProvider(core_1.WorkflowService)
113
+ .useValue(this.workflowServiceMock);
114
+ for (const [token, mock] of this.overrides) {
115
+ builder = builder.overrideProvider(token).useValue(mock);
116
+ }
117
+ const module = await builder.compile();
118
+ await module.init();
119
+ return module;
120
+ }
121
+ }
122
+ exports.WorkflowTestBuilder = WorkflowTestBuilder;
123
+ function createWorkflowTest() {
124
+ return new WorkflowTestBuilder();
125
+ }
126
+ //# sourceMappingURL=workflow-test-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-test-builder.js","sourceRoot":"","sources":["../../src/test-builder/workflow-test-builder.ts"],"names":[],"mappings":";;;AAmDA,8DAaC;AAiJD,gDAEC;AAjND,8CAG2B;AAC3B,0CAAkD;AAClD,yDAA6D;AAC7D,mEAA8D;AAC9D,2DAAqD;AAExC,QAAA,uBAAuB,GAAsC;IACxE,EAAE,EAAE,sCAAsC;IAC1C,SAAS,EAAE,EAAE;IACb,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,GAAG;IACV,QAAQ,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I,CAAC,CAAC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IAMD,oBAAoB,CAAC,MAA+B;QAClD,IAAI,CAAC,mBAAmB,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC;QAC7D,OAAO,IAAI,CAAC;IACd,CAAC;IAKD,KAAK,CAAC,OAAO;QACX,IAAI,OAAO,GAAG,IAAA,2CAAmB,EAAC;YAChC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC,CAAC;QAGH,OAAO,GAAG,IAAA,0CAAuB,EAAC,OAAO,CAAC,CAAC;QAG3C,OAAO,GAAG,OAAO;aACd,gBAAgB,CAAC,sBAAe,CAAC;aACjC,QAAQ,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAGtC,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YAC3C,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC3D,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QACvC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA7HD,kDA6HC;AAED,SAAgB,kBAAkB;IAChC,OAAO,IAAI,mBAAmB,EAAE,CAAC;AACnC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@loopstack/testing",
3
+ "displayName": "Loopstack Testing Utils",
4
+ "description": "Testing utilities for building tests for loopstack components",
5
+ "version": "0.15.2",
6
+ "author": {
7
+ "name": "Jakob Klippel",
8
+ "url": "https://www.linkedin.com/in/jakob-klippel/"
9
+ },
10
+ "license": "Apache-2.0",
11
+ "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "scripts": {
14
+ "build": "nest build",
15
+ "watch": "nest build --watch",
16
+ "prepare": "npm run build",
17
+ "compile": "tsc --noEmit",
18
+ "format": "prettier --write \"src/**/*.ts\"",
19
+ "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
20
+ },
21
+ "dependencies": {
22
+ "lodash": "^4.17.21"
23
+ },
24
+ "peerDependencies": {
25
+ "@loopstack/common": "^0.15.0",
26
+ "@loopstack/core": "^0.15.0",
27
+ "@nestjs/common": "^11.0.0",
28
+ "@nestjs/config": "^4.0.2",
29
+ "@nestjs/core": "^11.0.0",
30
+ "@nestjs/testing": "^11.0.0",
31
+ "@nestjs/typeorm": "^11.0.0",
32
+ "jest": "^29.0.0"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "@nestjs/config": {
36
+ "optional": true
37
+ },
38
+ "@nestjs/typeorm": {
39
+ "optional": true
40
+ },
41
+ "@loopstack/core": {
42
+ "optional": true
43
+ }
44
+ },
45
+ "devDependencies": {
46
+ "@loopstack/common": "^0.15.0",
47
+ "@loopstack/core": "^0.15.0",
48
+ "@nestjs/cli": "^11.0.5",
49
+ "@nestjs/common": "^11.1.9",
50
+ "@nestjs/config": "^4.0.2",
51
+ "@nestjs/core": "^11.1.9",
52
+ "@nestjs/testing": "^11.0.12",
53
+ "@nestjs/typeorm": "^11.0.0",
54
+ "@types/jest": "^29.5.14",
55
+ "@types/lodash": "^4.17.0",
56
+ "@types/node": "^22.13.10",
57
+ "jest": "^29.7.0",
58
+ "prettier": "^3.5.3",
59
+ "ts-jest": "^29.2.6",
60
+ "typescript": "^5.8.3"
61
+ }
62
+ }