@@ -2,14 +2,23 @@ import { expect } from 'chai';
22import { Request } from 'express' ;
33import { ineeda } from 'ineeda' ;
44import { spy } from 'sinon' ;
5+ import { Repository } from 'typeorm' ;
56
67import { Bot } from '../../src/Bot' ;
7- import { INJECT_BOT } from '../../src/BotService' ;
8+ import { INJECT_BOT , INJECT_STORAGE } from '../../src/BotService' ;
89import { User } from '../../src/entity/auth/User' ;
10+ import { Command } from '../../src/entity/Command' ;
11+ import { Message } from '../../src/entity/Message' ;
912import { GraphSchema } from '../../src/schema/graph' ;
13+ import { Storage } from '../../src/storage' ;
1014import { describeLeaks , itLeaks } from '../helpers/async' ;
1115import { createService , createServiceContainer } from '../helpers/container' ;
1216
17+ const TEST_SCHEMA = {
18+ kind : 'graph-schema' ,
19+ name : 'test-schema' ,
20+ } ;
21+
1322describeLeaks ( 'graph schema' , async ( ) => {
1423 itLeaks ( 'should execute commands' , async ( ) => {
1524 const { container } = await createServiceContainer ( ) ;
@@ -22,10 +31,7 @@ describeLeaks('graph schema', async () => {
2231 filters : [ ] ,
2332 strict : false ,
2433 } ,
25- metadata : {
26- kind : 'graph-schema' ,
27- name : 'test-schema' ,
28- } ,
34+ metadata : TEST_SCHEMA ,
2935 } ) ;
3036 await graph . executeCommands ( {
3137 commands : [ ] ,
@@ -46,10 +52,7 @@ describeLeaks('graph schema', async () => {
4652 filters : [ ] ,
4753 strict : false ,
4854 } ,
49- metadata : {
50- kind : 'graph-schema' ,
51- name : 'test-schema' ,
52- } ,
55+ metadata : TEST_SCHEMA ,
5356 } ) ;
5457 await graph . sendMessages ( {
5558 messages : [ ] ,
@@ -58,8 +61,67 @@ describeLeaks('graph schema', async () => {
5861 } ) ) ;
5962 expect ( sendMessage ) . to . have . callCount ( 1 ) ;
6063 } ) ;
61- itLeaks ( 'should get past commands' ) ;
62- itLeaks ( 'should get past messages' ) ;
64+
65+ itLeaks ( 'should get past commands' , async ( ) => {
66+ const { container } = await createServiceContainer ( ) ;
67+ const sendMessage = spy ( ) ;
68+ const graph = await createService ( container , GraphSchema , {
69+ [ INJECT_BOT ] : ineeda < Bot > ( {
70+ sendMessage,
71+ } ) ,
72+ [ INJECT_STORAGE ] : ineeda < Storage > ( {
73+ getRepository : ( ) => {
74+ return ineeda < Repository < Command > > ( {
75+ async findOne ( id : string ) {
76+ return ineeda . instanceof ( Command ) ;
77+ }
78+ } ) ;
79+ } ,
80+ } ) ,
81+ data : {
82+ filters : [ ] ,
83+ strict : false ,
84+ } ,
85+ metadata : TEST_SCHEMA ,
86+ } ) ;
87+ const command = await graph . getCommand ( {
88+ id : '0' ,
89+ } , ineeda < Request > ( {
90+ user : ineeda < User > ( ) ,
91+ } ) ) ;
92+ expect ( Command . isCommand ( command ) ) . to . equal ( true ) ;
93+ } ) ;
94+
95+ itLeaks ( 'should get past messages' , async ( ) => {
96+ const { container } = await createServiceContainer ( ) ;
97+ const sendMessage = spy ( ) ;
98+ const graph = await createService ( container , GraphSchema , {
99+ [ INJECT_BOT ] : ineeda < Bot > ( {
100+ sendMessage,
101+ } ) ,
102+ [ INJECT_STORAGE ] : ineeda < Storage > ( {
103+ getRepository : ( ) => {
104+ return ineeda < Repository < Message > > ( {
105+ async findOne ( id : string ) {
106+ return ineeda . instanceof ( Message ) ;
107+ }
108+ } ) ;
109+ } ,
110+ } ) ,
111+ data : {
112+ filters : [ ] ,
113+ strict : false ,
114+ } ,
115+ metadata : TEST_SCHEMA ,
116+ } ) ;
117+ const message = await graph . getMessage ( {
118+ id : '0' ,
119+ } , ineeda < Request > ( {
120+ user : ineeda < User > ( ) ,
121+ } ) ) ;
122+ expect ( Message . isMessage ( message ) ) . to . equal ( true ) ;
123+ } ) ;
124+
63125 itLeaks ( 'should get existing services' ) ;
64126 itLeaks ( 'should get a single service' ) ;
65127} ) ;
0 commit comments