Skip to content

Commit

Permalink
fix(app): do not set the user's Intercom name to "Unknown User"
Browse files Browse the repository at this point in the history
Fixes #6461
  • Loading branch information
mcous committed Sep 1, 2020
1 parent 8e446e1 commit 3c9e0f6
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 22 deletions.
11 changes: 11 additions & 0 deletions app-shell/src/config/__fixtures__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
ConfigV0,
ConfigV1,
ConfigV2,
ConfigV3,
} from '@opentrons/app/src/config/types'

export const MOCK_CONFIG_V0: ConfigV0 = {
Expand Down Expand Up @@ -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,
},
}
46 changes: 34 additions & 12 deletions app-shell/src/config/__tests__/migrate.test.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,50 @@
// @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', () => {
it('should migrate version 0 to latest', () => {
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: '[email protected]',
},
}
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)
})
})
33 changes: 27 additions & 6 deletions app-shell/src/config/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
ConfigV0,
ConfigV1,
ConfigV2,
ConfigV3,
} from '@opentrons/app/src/config/types'

// base config v0 defaults
Expand Down Expand Up @@ -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++) {
Expand Down
13 changes: 12 additions & 1 deletion app/src/config/schema-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigV2, 'support'>,
name: string | null,
email: string | null,
|}>,
|}>

export type Config = ConfigV3
3 changes: 1 addition & 2 deletions app/src/support/__tests__/profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('support profile tests', () => {
const CONFIG: SupportConfig = {
userId: 'some-user-id',
createdAt: 1234,
name: 'Some Name',
name: null,
email: null,
}

Expand All @@ -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,
})
})
Expand Down
1 change: 0 additions & 1 deletion app/src/support/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
Expand Down

0 comments on commit 3c9e0f6

Please sign in to comment.