Skip to content

Commit

Permalink
Added a log panel entry that displays the bot endpoint. (#2149)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyanziano authored May 19, 2020
1 parent 8441576 commit e164c01
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## Added
- [client] Added a log panel entry at the start of a conversation that displays the bot endpoint in PR [2149](https://github.com/microsoft/BotFramework-Emulator/pull/2149)

## v4.9.0 - 2020 - 05 - 11
## Added
Expand Down
76 changes: 76 additions & 0 deletions packages/app/main/src/server/restServer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license.
//
// Microsoft Bot Framework: http://botframework.com
//
// Bot Framework Emulator Github:
// https://github.com/Microsoft/BotFramwork-Emulator
//
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License:
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import { textItem, LogLevel } from '@bfemulator/sdk-shared';

import { EmulatorRestServer } from './restServer';

jest.mock('./routes/mountAllRoutes', () => ({
mountAllRoutes: jest.fn(),
}));

describe('restServer', () => {
let server: EmulatorRestServer;
const logService = {
logToChat: jest.fn(),
};
const emulatorUrl = 'http://localhost:52634';
const conversationId = 'convo1';
const mockConversation: any = {
botEndpoint: {
botUrl: 'http://localhost:3978/api/messages',
},
};

beforeEach(() => {
server = new EmulatorRestServer({ logService });
(server as any)._serverUrl = emulatorUrl;
server.state.conversations.conversations = {
[conversationId]: mockConversation,
};
logService.logToChat.mockClear();
});

it('should report the bot url and emulator url', () => {
server.report(conversationId);

expect(logService.logToChat).toBeCalledWith(
conversationId,
textItem(LogLevel.Debug, `Connecting to bot on ${mockConversation.botEndpoint.botUrl}`)
);
expect(logService.logToChat).toBeCalledWith(
conversationId,
textItem(LogLevel.Debug, `Emulator listening on ${emulatorUrl}`)
);
});
});
7 changes: 7 additions & 0 deletions packages/app/main/src/server/restServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ export class EmulatorRestServer {
}

public report(conversationId: string): void {
const conversation = this.state.conversations.conversationById(conversationId);
if (conversation && conversation.botEndpoint && conversation.botEndpoint.botUrl) {
this.options.logService.logToChat(
conversationId,
textItem(LogLevel.Debug, `Connecting to bot on ${conversation.botEndpoint.botUrl}`)
);
}
this.options.logService.logToChat(
conversationId,
textItem(LogLevel.Debug, `Emulator listening on ${this.serverUrl}`)
Expand Down

0 comments on commit e164c01

Please sign in to comment.