From ee52ca1f166af04a8fe620b9ca7ef3a6651442fd Mon Sep 17 00:00:00 2001 From: Tony Anziano Date: Wed, 29 Jan 2020 14:22:33 -0800 Subject: [PATCH] Fixed tests and addressed PR comments. --- .../app/client/src/state/sagas/botSagas.ts | 12 ++++++---- .../sagas/frameworkSettingsSagas.spec.ts | 24 +++++++++---------- .../client/src/utils/getSettingsDelta.spec.ts | 6 +++-- .../app/client/src/utils/getSettingsDelta.ts | 7 ++++++ .../src/telemetry/telemetryService.spec.ts | 4 ++-- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/packages/app/client/src/state/sagas/botSagas.ts b/packages/app/client/src/state/sagas/botSagas.ts index cbce39693..467c35006 100644 --- a/packages/app/client/src/state/sagas/botSagas.ts +++ b/packages/app/client/src/state/sagas/botSagas.ts @@ -162,10 +162,12 @@ export class BotSagas { // telemetry if (!action.payload.isFromBotFile) { - BotSagas.commandService.remoteCall(SharedConstants.Commands.Telemetry.TrackEvent, 'bot_open', { - numOfServices: 0, - source: 'url', - }); + BotSagas.commandService + .remoteCall(SharedConstants.Commands.Telemetry.TrackEvent, 'bot_open', { + numOfServices: 0, + source: 'url', + }) + .catch(_ => void 0); } BotSagas.commandService .remoteCall(SharedConstants.Commands.Telemetry.TrackEvent, 'livechat_open', { @@ -173,7 +175,7 @@ export class BotSagas { isGov: action.payload.channelService === 'azureusgovernment', isRemote: !isLocalHostUrl(action.payload.endpoint), }) - .catch(); + .catch(_ => void 0); } } diff --git a/packages/app/client/src/state/sagas/frameworkSettingsSagas.spec.ts b/packages/app/client/src/state/sagas/frameworkSettingsSagas.spec.ts index 90483ae2d..99c693974 100644 --- a/packages/app/client/src/state/sagas/frameworkSettingsSagas.spec.ts +++ b/packages/app/client/src/state/sagas/frameworkSettingsSagas.spec.ts @@ -106,8 +106,8 @@ describe('The frameworkSettingsSagas', () => { }); it('should register the expected generators', () => { - const it = frameworkSettingsSagas(); - expect(it.next().value).toEqual( + const gen = frameworkSettingsSagas(); + expect(gen.next().value).toEqual( takeEvery(FrameworkActionType.SAVE_FRAMEWORK_SETTINGS, FrameworkSettingsSagas.saveFrameworkSettings) ); }); @@ -127,16 +127,16 @@ describe('The frameworkSettingsSagas', () => { userGUID: 'some-user-id', ngrokPath: 'some/different/path/to/ngrok', }; - const it = FrameworkSettingsSagas.saveFrameworkSettings(saveFrameworkSettingsAction(updatedSettings)); + const gen = FrameworkSettingsSagas.saveFrameworkSettings(saveFrameworkSettingsAction(updatedSettings)); // selector to get the active document from the state - const selector = it.next().value; + const selector = gen.next().value; expect(selector).toEqual(select(activeDocumentSelector)); const value = selector.SELECT.selector(mockStore.getState()); // put the dirty state to false - expect(it.next(value).value).toEqual(put(EditorActions.setDirtyFlag(value.documentId, false))); - expect(it.next().value).toEqual(put(setFrameworkSettings(updatedSettings))); - expect(it.next().value).toEqual(select(getFrameworkSettings)); - expect(it.next(currentSettings).value).toEqual( + expect(gen.next(value).value).toEqual(put(EditorActions.setDirtyFlag(value.documentId, false))); + expect(gen.next().value).toEqual(put(setFrameworkSettings(updatedSettings))); + expect(gen.next().value).toEqual(select(getFrameworkSettings)); + expect(gen.next(currentSettings).value).toEqual( call( [commandService, commandService.remoteCall], SharedConstants.Commands.Telemetry.TrackEvent, @@ -149,16 +149,16 @@ describe('The frameworkSettingsSagas', () => { } ) ); - expect(it.next().done).toBe(true); + expect(gen.next().done).toBe(true); }); it('should send a notification when saving the settings fails', () => { - const it = FrameworkSettingsSagas.saveFrameworkSettings(saveFrameworkSettingsAction({})); - it.next(); + const gen = FrameworkSettingsSagas.saveFrameworkSettings(saveFrameworkSettingsAction({})); + gen.next(); const errMsg = `Error while saving emulator settings: oh noes!`; const notification = newNotification(errMsg); notification.timestamp = jasmine.any(Number) as any; notification.id = jasmine.any(String) as any; - expect(it.throw('oh noes!').value).toEqual(put(beginAdd(notification))); + expect(gen.throw('oh noes!').value).toEqual(put(beginAdd(notification))); }); }); diff --git a/packages/app/client/src/utils/getSettingsDelta.spec.ts b/packages/app/client/src/utils/getSettingsDelta.spec.ts index f08d3976a..1abbec891 100644 --- a/packages/app/client/src/utils/getSettingsDelta.spec.ts +++ b/packages/app/client/src/utils/getSettingsDelta.spec.ts @@ -34,23 +34,25 @@ describe('getSettingsDelta', () => { it('should return an object containing the delta between 2 settings objects', () => { const currentSettings: Partial = { autoUpdate: true, + locale: 'en-us', use10Tokens: true, usePrereleases: true, userGUID: 'some-id', }; const updatedSettings: Partial = { autoUpdate: true, + runNgrokAtStartup: true, use10Tokens: false, usePrereleases: false, userGUID: 'some-other-id', - runNgrokAtStartup: true, }; expect(getSettingsDelta(currentSettings, updatedSettings)).toEqual({ + locale: undefined, + runNgrokAtStartup: true, use10Tokens: false, usePrereleases: false, userGUID: 'some-other-id', - runNgrokAtStartup: true, }); }); diff --git a/packages/app/client/src/utils/getSettingsDelta.ts b/packages/app/client/src/utils/getSettingsDelta.ts index 490d84e9d..3459d687e 100644 --- a/packages/app/client/src/utils/getSettingsDelta.ts +++ b/packages/app/client/src/utils/getSettingsDelta.ts @@ -38,6 +38,7 @@ export function getSettingsDelta( updatedSettings: FrameworkSettings ): Partial { const delta: Partial = {}; + // get delta for keys present in updated settings for (const key in updatedSettings) { const prevVal = prevSettings[key]; const updatedVal = updatedSettings[key]; @@ -45,5 +46,11 @@ export function getSettingsDelta( delta[key] = updatedVal; } } + // get delta for any keys that were deleted from updated settings + for (const key in prevSettings) { + if (!Object.prototype.hasOwnProperty.call(updatedSettings, key)) { + delta[key] = undefined; + } + } return Object.keys(delta).length ? delta : undefined; } diff --git a/packages/app/main/src/telemetry/telemetryService.spec.ts b/packages/app/main/src/telemetry/telemetryService.spec.ts index 2349a60b8..70cc477ee 100644 --- a/packages/app/main/src/telemetry/telemetryService.spec.ts +++ b/packages/app/main/src/telemetry/telemetryService.spec.ts @@ -125,7 +125,7 @@ describe('TelemetryService', () => { }); it('should track events', () => { - Object.assign(global, { __JEST_ENV__: false }); + global['__JEST_ENV__'] = false; const mockStartup = jest.fn(() => null); (TelemetryService as any).startup = mockStartup; const mockAutoCollect = jest.fn(() => mockAppInsights); @@ -148,6 +148,6 @@ describe('TelemetryService', () => { toolName: 'bf-emulator', }, }); - Object.assign(global, { __JEST_ENV__: true }); + global['__JEST_ENV__'] = true; }); });