Skip to content

Commit

Permalink
Fixed issue where userId was out of sync between bot and user.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyanziano committed Mar 14, 2019
1 parent ccfe83c commit b1c7f4c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Fixed
- [client] Use correct casing for user id prop for web chat in PR [#1374](https://github.com/Microsoft/BotFramework-Emulator/pull/1374)
- [luis / qnamaker] Addressed npm security vulnerabilities in luis & qnamaker extensions in PR [#1371](https://github.com/Microsoft/BotFramework-Emulator/pull/1371)
- [main] Fixed issue where current user id was out of sync between client and main in PR [#1378](https://github.com/Microsoft/BotFramework-Emulator/pull/1378)

## Removed
- [telemetry] Disabled telemetry and the ability to opt-in to collect usage data in PR [#1375](https://github.com/Microsoft/BotFramework-Emulator/pull/1375)
Expand Down
14 changes: 13 additions & 1 deletion packages/app/main/src/commands/emulatorCommands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ import { newBot, newEndpoint, SharedConstants } from '@bfemulator/app-shared';
import { Conversation } from '@bfemulator/emulator-core';

import * as store from '../botData/store';
import { getStore as getSettingsStore } from '../settingsData/store';
import { emulator } from '../emulator';
import * as utils from '../utils';
import * as botHelpers from '../botHelpers';
import { bot } from '../botData/reducers/bot';
import * as BotActions from '../botData/actions/botActions';
import { TelemetryService } from '../telemetry';
import { mainWindow } from '../main';
import { setCurrentUser } from '../settingsData/actions/userActions';

import { registerCommands } from './emulatorCommands';

Expand Down Expand Up @@ -129,10 +131,14 @@ jest.mock('../emulator', () => ({
},
}));

let mockCallsMade = [];
jest.mock('../main', () => ({
mainWindow: {
commandService: {
call: async () => true,
call: async (commandName, ...args) => {
mockCallsMade.push({ commandName, args });
return Promise.resolve(true);
},
remoteCall: async () => true,
},
browserWindow: {},
Expand Down Expand Up @@ -388,6 +394,7 @@ describe('The emulatorCommands', () => {
mockUsers = { users: {} };
mockTrackEvent = jest.fn(() => Promise.resolve());
TelemetryService.trackEvent = mockTrackEvent;
mockCallsMade = [];
});

beforeAll(() => {
Expand Down Expand Up @@ -480,11 +487,16 @@ describe('The emulatorCommands', () => {
});

it('should set current user', async () => {
const dispatchSpy = jest.spyOn(getSettingsStore(), 'dispatch');
await mockCommandRegistry.getCommand(SharedConstants.Commands.Emulator.SetCurrentUser).handler('userId123');

expect(mockUsers.currentUserId).toBe('userId123');
expect(mockUsers.users.userId123).toEqual({
id: 'userId123',
name: 'User',
});
expect(dispatchSpy).toHaveBeenCalledWith(setCurrentUser({ id: 'userId123', name: 'User' }));
expect(mockCallsMade).toHaveLength(1);
expect(mockCallsMade[0].commandName).toBe(SharedConstants.Commands.Settings.PushClientAwareSettings);
});
});
12 changes: 9 additions & 3 deletions packages/app/main/src/commands/emulatorCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ import { getStore } from '../botData/store';
import { getActiveBot, getBotInfoByPath, patchBotsJson, toSavableBot } from '../botHelpers';
import { emulator } from '../emulator';
import { mainWindow } from '../main';
import { getStore as getSettingsStore } from '../settingsData/store';
import { dispatch, getStore as getSettingsStore } from '../settingsData/store';
import { parseActivitiesFromChatFile, showSaveDialog, writeFile } from '../utils';
import { cleanupId as cleanupActivityChannelAccountId, CustomActivity } from '../utils/conversation';
import { botProjectFileWatcher } from '../watchers';
import { TelemetryService } from '../telemetry';
import { setCurrentUser } from '../settingsData/actions/userActions';

/** Registers emulator (actual conversation emulation logic) commands */
export function registerCommands(commandRegistry: CommandRegistryImpl) {
Expand Down Expand Up @@ -217,11 +218,16 @@ export function registerCommands(commandRegistry: CommandRegistryImpl) {

// ---------------------------------------------------------------------------
// Sets the current user id (in memory)
commandRegistry.registerCommand(Commands.SetCurrentUser, (userId: string) => {
commandRegistry.registerCommand(Commands.SetCurrentUser, async (userId: string) => {
const { facilities } = emulator.framework.server.botEmulator;
const { users } = facilities;
const user = { id: userId, name: 'User' };
users.currentUserId = userId;
users.users[userId] = { id: userId, name: 'User' };
users.users[userId] = user;
facilities.users = users;

// update the settings state on both main and client
dispatch(setCurrentUser(user));
await mainWindow.commandService.call(SharedConstants.Commands.Settings.PushClientAwareSettings);
});
}

0 comments on commit b1c7f4c

Please sign in to comment.