Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a log panel entry that displays the bot endpoint. #2149

Merged
merged 1 commit into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added a log panel entry that displays the bot endpoint.
  • Loading branch information
tonyanziano committed May 19, 2020
commit 3f0af8710ef4ed4d20f5ec5549f6324d60dc33fa
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