@@ -4,12 +4,16 @@ import { LogLevel } from 'noicejs';
44import { Registry } from 'prom-client' ;
55import { spy } from 'sinon' ;
66
7- import { INJECT_METRICS , INJECT_SCHEMA } from '../src/BaseService' ;
7+ import { INJECT_LOGGER , INJECT_METRICS , INJECT_SCHEMA } from '../src/BaseService' ;
88import { Bot , BotData } from '../src/Bot' ;
9+ import { Command , CommandVerb } from '../src/entity/Command' ;
910import { BotModule } from '../src/module/BotModule' ;
11+ import { EntityModule } from '../src/module/EntityModule' ;
12+ import { MigrationModule } from '../src/module/MigrationModule' ;
1013import { ServiceModule } from '../src/module/ServiceModule' ;
1114import { Schema } from '../src/schema' ;
1215import { ServiceEvent } from '../src/Service' ;
16+ import { defer } from '../src/utils/Async' ;
1317import { describeLeaks , itLeaks } from './helpers/async' ;
1418import { createContainer } from './helpers/container' ;
1519import { getTestLogger } from './helpers/logger' ;
@@ -36,17 +40,17 @@ const TEST_CONFIG: BotData = {
3640 parsers : [ ] ,
3741 process : {
3842 pid : {
39- file : '.. /out/isolex .pid' ,
43+ file : './out/test .pid' ,
4044 } ,
4145 } ,
4246 services : {
4347 timeout : 1000 ,
4448 } ,
4549 storage : {
4650 data : {
47- migrate : false ,
51+ migrate : true ,
4852 orm : {
49- database : '' ,
53+ database : './out/test.db ' ,
5054 type : 'sqlite' ,
5155 } ,
5256 } ,
@@ -97,4 +101,57 @@ describeLeaks('bot service', async () => {
97101 } ) ;
98102 expect ( bot . isConnected ) . to . equal ( false ) ;
99103 } ) ;
104+
105+ xit ( 'should execute commands' , async ( ) => {
106+ const { container } = await createContainer ( new BotModule ( {
107+ logger : getTestLogger ( ) ,
108+ } ) , new ServiceModule ( {
109+ timeout : 1000 ,
110+ } ) , new EntityModule ( ) , new MigrationModule ( ) ) ;
111+ const bot = await container . create ( Bot , {
112+ [ INJECT_LOGGER ] : getTestLogger ( true ) ,
113+ [ INJECT_SCHEMA ] : new Schema ( ) ,
114+ data : TEST_CONFIG ,
115+ metadata : {
116+ kind : 'bot' ,
117+ name : 'test-bot' ,
118+ } ,
119+ } ) ;
120+ await bot . start ( ) ;
121+ const results = await bot . executeCommand ( new Command ( {
122+ data : { } ,
123+ labels : { } ,
124+ noun : 'test' ,
125+ verb : CommandVerb . Create ,
126+ } ) ) ;
127+ await defer ( 50 ) ;
128+ await bot . stop ( ) ;
129+ expect ( results . length ) . to . equal ( 0 ) ;
130+ } ) ;
131+
132+ xit ( 'should send messages' , async ( ) => {
133+ const { container } = await createContainer ( new BotModule ( {
134+ logger : getTestLogger ( ) ,
135+ } ) , new ServiceModule ( {
136+ timeout : 1000 ,
137+ } ) , new EntityModule ( ) , new MigrationModule ( ) ) ;
138+ const bot = await container . create ( Bot , {
139+ [ INJECT_SCHEMA ] : new Schema ( ) ,
140+ data : TEST_CONFIG ,
141+ metadata : {
142+ kind : 'bot' ,
143+ name : 'test-bot' ,
144+ } ,
145+ } ) ;
146+ await bot . start ( ) ;
147+ const results = await bot . sendMessage ( /* new Message({
148+ body: 'test',
149+ labels: {},
150+ reactions: [],
151+ type: TYPE_TEXT,
152+ }) */ ) ;
153+ await defer ( 50 ) ;
154+ await bot . stop ( ) ;
155+ expect ( results . length ) . to . equal ( 0 ) ;
156+ } ) ;
100157} ) ;
0 commit comments