Skip to content

Commit f0bf577

Browse files
committed
additional unit test for inspection of a Teams Team
1 parent a78a69f commit f0bf577

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

libraries/botbuilder/tests/inspectionMiddleware.test.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,88 @@ describe('InspectionMiddleware', function() {
206206

207207
// verify that all our expectations have been met
208208

209+
assert(inboundExpectation.isDone(), 'The expectation of a trace message for the inbound activity was not met');
210+
assert(outboundExpectation.isDone(), 'The expectation of a trace message for the outbound activity was not met');
211+
assert(stateExpectation.isDone(), 'The expectation of a trace message for the bot state was not met');
212+
});
213+
it('should replicate activity data to listening emulator following open and attach within Teams Team', async function() {
214+
215+
// set up our expectations in nock - each corresponds to a trace message we expect to receive in the emulator
216+
217+
const inboundExpectation = nock('https://test.com')
218+
.post('/v3/conversations/Convo1/activities', activity => activity.type === 'trace'
219+
&& activity.value.text == 'hi')
220+
.reply(200, { id: 'test' });
221+
222+
const outboundExpectation = nock('https://test.com')
223+
.post('/v3/conversations/Convo1/activities', activity => activity.type === 'trace'
224+
&& activity.value.text == 'echo: hi')
225+
.reply(200, { id: 'test' });
226+
227+
const stateExpectation = nock('https://test.com')
228+
.post('/v3/conversations/Convo1/activities', activity => activity.type === 'trace'
229+
&& activity.value.userState && activity.value.userState.x.property == 'hello'
230+
&& activity.value.conversationState && activity.value.conversationState.y.property == 'world')
231+
.reply(200, { id: 'test' });
232+
233+
// create the various storage and middleware objects we will be using
234+
235+
var storage = new MemoryStorage();
236+
var inspectionState = new InspectionState(storage);
237+
var userState = new UserState(storage);
238+
var conversationState = new ConversationState(storage);
239+
var inspectionMiddleware = new InspectionMiddleware(inspectionState, userState, conversationState);
240+
241+
// the emulator sends an /INSPECT open command - we can use another adapter here
242+
243+
var openActivity = MessageFactory.text('/INSPECT open');
244+
245+
const inspectionAdapter = new TestAdapter(async (turnContext) => {
246+
await inspectionMiddleware.processCommand(turnContext);
247+
}, null, true);
248+
249+
await inspectionAdapter.receiveActivity(openActivity);
250+
251+
var inspectionOpenResultActivity = inspectionAdapter.activityBuffer[0];
252+
var attachCommand = inspectionOpenResultActivity.value;
253+
254+
// the logic of teh bot including replying with a message and updating user and conversation state
255+
256+
var x = userState.createProperty('x');
257+
var y = conversationState.createProperty('y');
258+
259+
var applicationAdapter = new TestAdapter(async (turnContext) => {
260+
261+
await turnContext.sendActivity(MessageFactory.text(`echo: ${ turnContext.activity.text }`));
262+
263+
(await x.get(turnContext, { property: '' })).property = 'hello';
264+
(await y.get(turnContext, { property: '' })).property = 'world';
265+
266+
await userState.saveChanges(turnContext);
267+
await conversationState.saveChanges(turnContext);
268+
269+
}, null, true);
270+
271+
// IMPORTANT add the InspectionMiddleware to the adapter that is running our bot
272+
273+
applicationAdapter.use(inspectionMiddleware);
274+
275+
var attachActivity = MessageFactory.text(attachCommand);
276+
attachActivity.channelData = { team: { id: 'team-id' } };
277+
278+
await applicationAdapter.receiveActivity(attachActivity);
279+
280+
// the attach command response is a informational message
281+
282+
var hiActivity = MessageFactory.text('hi');
283+
hiActivity.channelData = { team: { id: 'team-id' } };
284+
285+
await applicationAdapter.receiveActivity(hiActivity);
286+
287+
// trace activities should be sent to the emulator using the connector and the conversation reference
288+
289+
// verify that all our expectations have been met
290+
209291
assert(inboundExpectation.isDone(), 'The expectation of a trace message for the inbound activity was not met');
210292
assert(outboundExpectation.isDone(), 'The expectation of a trace message for the outbound activity was not met');
211293
assert(stateExpectation.isDone(), 'The expectation of a trace message for the bot state was not met');

0 commit comments

Comments
 (0)