@@ -112,6 +112,100 @@ describe('InspectionMiddleware', function() {
112
112
113
113
// verify that all our expectations have been met
114
114
115
+ assert ( inboundExpectation . isDone ( ) , 'The expectation of a trace message for the inbound activity was not met' ) ;
116
+ assert ( outboundExpectation . isDone ( ) , 'The expectation of a trace message for the outbound activity was not met' ) ;
117
+ assert ( stateExpectation . isDone ( ) , 'The expectation of a trace message for the bot state was not met' ) ;
118
+ } ) ;
119
+ it ( 'should replicate activity data to listening emulator following open and attach with at mention' , async function ( ) {
120
+
121
+ // set up our expectations in nock - each corresponds to a trace message we expect to receive in the emulator
122
+
123
+ const inboundExpectation = nock ( 'https://test.com' )
124
+ . post ( '/v3/conversations/Convo1/activities' , activity => activity . type === 'trace'
125
+ && activity . value . text == 'hi' )
126
+ . reply ( 200 , { id : 'test' } ) ;
127
+
128
+ const outboundExpectation = nock ( 'https://test.com' )
129
+ . post ( '/v3/conversations/Convo1/activities' , activity => activity . type === 'trace'
130
+ && activity . value . text == 'echo: hi' )
131
+ . reply ( 200 , { id : 'test' } ) ;
132
+
133
+ const stateExpectation = nock ( 'https://test.com' )
134
+ . post ( '/v3/conversations/Convo1/activities' , activity => activity . type === 'trace'
135
+ && activity . value . userState && activity . value . userState . x . property == 'hello'
136
+ && activity . value . conversationState && activity . value . conversationState . y . property == 'world' )
137
+ . reply ( 200 , { id : 'test' } ) ;
138
+
139
+ // create the various storage and middleware objects we will be using
140
+
141
+ var storage = new MemoryStorage ( ) ;
142
+ var inspectionState = new InspectionState ( storage ) ;
143
+ var userState = new UserState ( storage ) ;
144
+ var conversationState = new ConversationState ( storage ) ;
145
+ var inspectionMiddleware = new InspectionMiddleware ( inspectionState , userState , conversationState ) ;
146
+
147
+ // the emulator sends an /INSPECT open command - we can use another adapter here
148
+
149
+ var openActivity = MessageFactory . text ( '/INSPECT open' ) ;
150
+
151
+ const inspectionAdapter = new TestAdapter ( async ( turnContext ) => {
152
+ await inspectionMiddleware . processCommand ( turnContext ) ;
153
+ } , null , true ) ;
154
+
155
+ await inspectionAdapter . receiveActivity ( openActivity ) ;
156
+
157
+ var inspectionOpenResultActivity = inspectionAdapter . activityBuffer [ 0 ] ;
158
+
159
+ var recipientId = 'bot' ;
160
+ var attachCommand = `<at>${ recipientId } </at> ${ inspectionOpenResultActivity . value } ` ;
161
+
162
+ // the logic of the bot including replying with a message and updating user and conversation state
163
+
164
+ var x = userState . createProperty ( 'x' ) ;
165
+ var y = conversationState . createProperty ( 'y' ) ;
166
+
167
+ var applicationAdapter = new TestAdapter ( async ( turnContext ) => {
168
+
169
+ await turnContext . sendActivity ( MessageFactory . text ( `echo: ${ turnContext . activity . text } ` ) ) ;
170
+
171
+ ( await x . get ( turnContext , { property : '' } ) ) . property = 'hello' ;
172
+ ( await y . get ( turnContext , { property : '' } ) ) . property = 'world' ;
173
+
174
+ await userState . saveChanges ( turnContext ) ;
175
+ await conversationState . saveChanges ( turnContext ) ;
176
+
177
+ } , null , true ) ;
178
+
179
+ // IMPORTANT add the InspectionMiddleware to the adapter that is running our bot
180
+
181
+ applicationAdapter . use ( inspectionMiddleware ) ;
182
+
183
+ var attachActivity = {
184
+ type : 'message' ,
185
+ text : attachCommand ,
186
+ recipient : { id : recipientId } ,
187
+ entities : [
188
+ {
189
+ type : 'mention' ,
190
+ text : `<at>${ recipientId } </at>` ,
191
+ mentioned : {
192
+ name : 'Bot' ,
193
+ id : recipientId
194
+ }
195
+ }
196
+ ]
197
+ } ;
198
+
199
+ await applicationAdapter . receiveActivity ( attachActivity ) ;
200
+
201
+ // the attach command response is a informational message
202
+
203
+ await applicationAdapter . receiveActivity ( MessageFactory . text ( 'hi' ) ) ;
204
+
205
+ // trace activities should be sent to the emulator using the connector and the conversation reference
206
+
207
+ // verify that all our expectations have been met
208
+
115
209
assert ( inboundExpectation . isDone ( ) , 'The expectation of a trace message for the inbound activity was not met' ) ;
116
210
assert ( outboundExpectation . isDone ( ) , 'The expectation of a trace message for the outbound activity was not met' ) ;
117
211
assert ( stateExpectation . isDone ( ) , 'The expectation of a trace message for the bot state was not met' ) ;
0 commit comments