From 3c9e0f6518c462635437e5a7fb36992a2cc6c4fb Mon Sep 17 00:00:00 2001 From: Mike Cousins Date: Tue, 1 Sep 2020 14:16:19 -0400 Subject: [PATCH] fix(app): do not set the user's Intercom name to "Unknown User" Fixes #6461 --- app-shell/src/config/__fixtures__/index.js | 11 +++++ .../src/config/__tests__/migrate.test.js | 46 ++++++++++++++----- app-shell/src/config/migrate.js | 33 ++++++++++--- app/src/config/schema-types.js | 13 +++++- app/src/support/__tests__/profile.test.js | 3 +- app/src/support/profile.js | 1 - 6 files changed, 85 insertions(+), 22 deletions(-) diff --git a/app-shell/src/config/__fixtures__/index.js b/app-shell/src/config/__fixtures__/index.js index b07b3715cfe..46f190e23e2 100644 --- a/app-shell/src/config/__fixtures__/index.js +++ b/app-shell/src/config/__fixtures__/index.js @@ -4,6 +4,7 @@ import type { ConfigV0, ConfigV1, ConfigV2, + ConfigV3, } from '@opentrons/app/src/config/types' export const MOCK_CONFIG_V0: ConfigV0 = { @@ -79,3 +80,13 @@ export const MOCK_CONFIG_V2: ConfigV2 = { useTrashSurfaceForTipCal: null, }, } + +export const MOCK_CONFIG_V3: ConfigV3 = { + ...MOCK_CONFIG_V2, + version: 3, + support: { + ...MOCK_CONFIG_V2.support, + name: null, + email: null, + }, +} diff --git a/app-shell/src/config/__tests__/migrate.test.js b/app-shell/src/config/__tests__/migrate.test.js index 4046f52041c..bd0bc43fd80 100644 --- a/app-shell/src/config/__tests__/migrate.test.js +++ b/app-shell/src/config/__tests__/migrate.test.js @@ -1,6 +1,11 @@ // @flow // config migration tests -import { MOCK_CONFIG_V0, MOCK_CONFIG_V2 } from '../__fixtures__' +import { + MOCK_CONFIG_V0, + MOCK_CONFIG_V1, + MOCK_CONFIG_V2, + MOCK_CONFIG_V3, +} from '../__fixtures__' import { migrate } from '../migrate' describe('config migration', () => { @@ -8,21 +13,38 @@ describe('config migration', () => { const v0Config = MOCK_CONFIG_V0 const result = migrate(v0Config) - expect(result.version).toBe(2) - expect(result).toEqual(MOCK_CONFIG_V2) + expect(result.version).toBe(3) + expect(result).toEqual(MOCK_CONFIG_V3) }) - it('should keep version 2 unchanged', () => { - const v2Config = { - ...MOCK_CONFIG_V2, - calibration: { - ...MOCK_CONFIG_V2.calibration, - useTrashSurfaceForTipCal: true, + it('should migrate version 1 to latest', () => { + const v1Config = MOCK_CONFIG_V1 + const result = migrate(v1Config) + + expect(result.version).toBe(3) + expect(result).toEqual(MOCK_CONFIG_V3) + }) + + it('should migrate version 2 to latest', () => { + const v2Config = MOCK_CONFIG_V2 + const result = migrate(v2Config) + + expect(result.version).toBe(3) + expect(result).toEqual(MOCK_CONFIG_V3) + }) + + it('should keep version 3 unchanged', () => { + const v3Config = { + ...MOCK_CONFIG_V3, + support: { + ...MOCK_CONFIG_V3.support, + name: 'Known Kname', + email: 'hello@example.com', }, } - const result = migrate(v2Config) + const result = migrate(v3Config) - expect(result.version).toBe(2) - expect(result).toEqual(v2Config) + expect(result.version).toBe(3) + expect(result).toEqual(v3Config) }) }) diff --git a/app-shell/src/config/migrate.js b/app-shell/src/config/migrate.js index c734ad20a10..d1545f1d115 100644 --- a/app-shell/src/config/migrate.js +++ b/app-shell/src/config/migrate.js @@ -11,6 +11,7 @@ import type { ConfigV0, ConfigV1, ConfigV2, + ConfigV3, } from '@opentrons/app/src/config/types' // base config v0 defaults @@ -112,16 +113,36 @@ const toVersion2 = (prevConfig: ConfigV1): ConfigV2 => { return nextConfig } -const MIGRATIONS: [(ConfigV0) => ConfigV1, (ConfigV1) => ConfigV2] = [ - toVersion1, - toVersion2, -] +// config version 3 migration and defaults +const toVersion3 = (prevConfig: ConfigV2): ConfigV3 => { + const nextConfig = { + ...prevConfig, + version: 3, + support: { + ...prevConfig.support, + // name and email were never changed by the app, and its default values + // were causing problems. Null them out for future implementations + name: null, + email: null, + }, + } + + return nextConfig +} + +const MIGRATIONS: [ + (ConfigV0) => ConfigV1, + (ConfigV1) => ConfigV2, + (ConfigV2) => ConfigV3 +] = [toVersion1, toVersion2, toVersion3] export const DEFAULTS: Config = migrate(DEFAULTS_V0) -export function migrate(prevConfig: ConfigV0 | ConfigV1 | ConfigV2): Config { +export function migrate( + prevConfig: ConfigV0 | ConfigV1 | ConfigV2 | ConfigV3 +): Config { const prevVersion = prevConfig.version - let result: ConfigV0 | ConfigV1 | ConfigV2 = prevConfig + let result: ConfigV0 | ConfigV1 | ConfigV2 | ConfigV3 = prevConfig // loop through the migrations, skipping any migrations that are unnecessary for (let i = prevVersion; i < MIGRATIONS.length; i++) { diff --git a/app/src/config/schema-types.js b/app/src/config/schema-types.js index c629be91304..673ee2bda2b 100644 --- a/app/src/config/schema-types.js +++ b/app/src/config/schema-types.js @@ -104,4 +104,15 @@ export type ConfigV2 = $ReadOnly<{| |}>, |}> -export type Config = ConfigV2 +// v3 config changes default values but does not change schema +export type ConfigV3 = $ReadOnly<{| + ...ConfigV2, + version: 3, + support: $ReadOnly<{| + ...$PropertyType, + name: string | null, + email: string | null, + |}>, +|}> + +export type Config = ConfigV3 diff --git a/app/src/support/__tests__/profile.test.js b/app/src/support/__tests__/profile.test.js index 47e55a1cd5a..e29c58f1cc1 100644 --- a/app/src/support/__tests__/profile.test.js +++ b/app/src/support/__tests__/profile.test.js @@ -22,7 +22,7 @@ describe('support profile tests', () => { const CONFIG: SupportConfig = { userId: 'some-user-id', createdAt: 1234, - name: 'Some Name', + name: null, email: null, } @@ -40,7 +40,6 @@ describe('support profile tests', () => { expect(bootIntercom).toHaveBeenCalledWith({ app_id: 'some-intercom-app-id', created_at: 1234, - name: 'Some Name', 'App Version': version, }) }) diff --git a/app/src/support/profile.js b/app/src/support/profile.js index f3a2efbfc3b..27363289405 100644 --- a/app/src/support/profile.js +++ b/app/src/support/profile.js @@ -26,7 +26,6 @@ export function initializeProfile(config: SupportConfig): void { bootIntercom({ app_id: getIntercomAppId(), created_at: config.createdAt, - name: config.name, [Constants.PROFILE_APP_VERSION]: appVersion, }) }