1+ import { beforeEach , vi } from "vitest" ;
2+ import {
3+ ActionSdk ,
4+ HerculesActionConfigurationDefinition ,
5+ HerculesDataType ,
6+ HerculesFlowType ,
7+ HerculesRegisterFunctionParameter
8+ } from "@code0-tech/hercules" ;
9+ import { SdkMockState } from "../index.test" ;
10+
11+ export const withSdkMock = async ( tests : ( state : SdkMockState ) => void ) => {
12+ const state = vi . hoisted ( ( ) => {
13+ const state : SdkMockState = {
14+ registeredFunctionDefinitions : [ ] as HerculesRegisterFunctionParameter [ ] ,
15+ dataTypes : [ ] as HerculesDataType [ ] ,
16+ flowTypes : [ ] as HerculesFlowType [ ] ,
17+ configDefinitions : [ ] as HerculesActionConfigurationDefinition [ ] ,
18+ } ;
19+ return state
20+ } )
21+
22+
23+ vi . mock ( "@code0-tech/hercules" , async ( importOriginal ) => {
24+ const actual = await importOriginal ( ) as any
25+ return {
26+ ...actual ,
27+ createSdk : ( config , configDefinitions ) => {
28+ state . configDefinitions = configDefinitions || null
29+
30+ const mockedActionSdk : ActionSdk = {
31+ config : config ,
32+ registerFunctionDefinitions : ( ...defs : HerculesRegisterFunctionParameter [ ] ) => {
33+ state . registeredFunctionDefinitions = defs ;
34+ return Promise . resolve ( ) ;
35+ } ,
36+
37+ registerConfigDefinitions : ( ...defs : HerculesActionConfigurationDefinition [ ] ) => {
38+ state . configDefinitions = defs ;
39+ return Promise . resolve ( ) ;
40+ } ,
41+
42+ registerDataTypes : ( ...types : HerculesDataType [ ] ) => {
43+ state . dataTypes = types ;
44+ return Promise . resolve ( ) ;
45+ } ,
46+
47+ registerFlowTypes : ( ...types : HerculesFlowType [ ] ) => {
48+ state . flowTypes = types ;
49+ return Promise . resolve ( ) ;
50+ } ,
51+ fullyConnected : ( ) => {
52+ return true
53+ } ,
54+ connect : vi . fn ( ( options ) => {
55+ return Promise . resolve ( [ ] ) ;
56+ } ) ,
57+ onError : vi . fn ( ) ,
58+ dispatchEvent : vi . fn ( ) ,
59+ getProjectActionConfigurations : vi . fn ( )
60+ }
61+ return mockedActionSdk
62+
63+ }
64+ }
65+
66+ } )
67+
68+
69+ beforeEach ( ( ) => {
70+ state . registeredFunctionDefinitions = null ;
71+ state . dataTypes = null ;
72+ state . flowTypes = null ;
73+ state . configDefinitions = null ;
74+ } ) ;
75+
76+ tests ( state ) ;
77+ }
0 commit comments