diff --git a/CHANGELOG.md b/CHANGELOG.md index e5c2527bf..e36d97933 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/packages/app/main/src/commands/emulatorCommands.spec.ts b/packages/app/main/src/commands/emulatorCommands.spec.ts index 7b005ba00..c719277cf 100644 --- a/packages/app/main/src/commands/emulatorCommands.spec.ts +++ b/packages/app/main/src/commands/emulatorCommands.spec.ts @@ -42,6 +42,7 @@ 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'; @@ -49,6 +50,7 @@ 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'; @@ -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: {}, @@ -388,6 +394,7 @@ describe('The emulatorCommands', () => { mockUsers = { users: {} }; mockTrackEvent = jest.fn(() => Promise.resolve()); TelemetryService.trackEvent = mockTrackEvent; + mockCallsMade = []; }); beforeAll(() => { @@ -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); }); }); diff --git a/packages/app/main/src/commands/emulatorCommands.ts b/packages/app/main/src/commands/emulatorCommands.ts index 09e750281..cc8ec65b8 100644 --- a/packages/app/main/src/commands/emulatorCommands.ts +++ b/packages/app/main/src/commands/emulatorCommands.ts @@ -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) { @@ -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); }); }