diff --git a/app-shell-odd/src/config/__fixtures__/index.ts b/app-shell-odd/src/config/__fixtures__/index.ts index 5365d1cb075..d670234ebbc 100644 --- a/app-shell-odd/src/config/__fixtures__/index.ts +++ b/app-shell-odd/src/config/__fixtures__/index.ts @@ -11,6 +11,7 @@ import type { ConfigV21, ConfigV22, ConfigV23, + ConfigV24, } from '@opentrons/app/src/redux/config/types' const PKG_VERSION: string = _PKG_VERSION_ @@ -159,3 +160,14 @@ export const MOCK_CONFIG_V23: ConfigV23 = { hasDismissedQuickTransferIntro: false, }, } + +export const MOCK_CONFIG_V24: ConfigV24 = { + ...(() => { + const { support, ...rest } = MOCK_CONFIG_V23 + return rest + })(), + version: 24, + userInfo: { + userId: 'MOCK_UUIDv4', + }, +} diff --git a/app-shell-odd/src/config/__tests__/migrate.test.ts b/app-shell-odd/src/config/__tests__/migrate.test.ts index 1ef817da3be..dcc8eb03708 100644 --- a/app-shell-odd/src/config/__tests__/migrate.test.ts +++ b/app-shell-odd/src/config/__tests__/migrate.test.ts @@ -1,5 +1,7 @@ // config migration tests -import { describe, it, expect } from 'vitest' +import { describe, it, expect, beforeEach, vi } from 'vitest' +import uuid from 'uuid/v4' + import { MOCK_CONFIG_V12, MOCK_CONFIG_V13, @@ -13,18 +15,26 @@ import { MOCK_CONFIG_V21, MOCK_CONFIG_V22, MOCK_CONFIG_V23, + MOCK_CONFIG_V24, } from '../__fixtures__' import { migrate } from '../migrate' -const NEWEST_VERSION = 23 +vi.mock('uuid/v4') + +const NEWEST_VERSION = 24 +const NEWEST_MOCK_CONFIG = MOCK_CONFIG_V24 describe('config migration', () => { + beforeEach(() => { + vi.mocked(uuid).mockReturnValue('MOCK_UUIDv4') + }) + it('should migrate version 12 to latest', () => { const v12Config = MOCK_CONFIG_V12 const result = migrate(v12Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 13 to latest', () => { @@ -32,7 +42,7 @@ describe('config migration', () => { const result = migrate(v13Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 14 to latest', () => { @@ -40,7 +50,7 @@ describe('config migration', () => { const result = migrate(v14Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 15 to latest', () => { @@ -48,7 +58,7 @@ describe('config migration', () => { const result = migrate(v15Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 16 to latest', () => { @@ -56,7 +66,7 @@ describe('config migration', () => { const result = migrate(v16Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 17 to latest', () => { @@ -64,7 +74,7 @@ describe('config migration', () => { const result = migrate(v17Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migration version 18 to latest', () => { @@ -72,7 +82,7 @@ describe('config migration', () => { const result = migrate(v18Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migration version 19 to latest', () => { @@ -80,7 +90,7 @@ describe('config migration', () => { const result = migrate(v19Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migration version 20 to latest', () => { @@ -88,27 +98,34 @@ describe('config migration', () => { const result = migrate(v20Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migration version 21 to latest', () => { const v21Config = MOCK_CONFIG_V21 const result = migrate(v21Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migration version 22 to latest', () => { const v22Config = MOCK_CONFIG_V22 const result = migrate(v22Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) - it('should keep version 23', () => { + it('should migrate version 23 to latest', () => { const v23Config = MOCK_CONFIG_V23 const result = migrate(v23Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(v23Config) + expect(result).toEqual(NEWEST_MOCK_CONFIG) + }) + it('should keep version 24', () => { + const v24Config = MOCK_CONFIG_V24 + const result = migrate(v24Config) + + expect(result.version).toBe(NEWEST_VERSION) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) }) diff --git a/app-shell-odd/src/config/migrate.ts b/app-shell-odd/src/config/migrate.ts index c6d667a8fc3..d1e9103d430 100644 --- a/app-shell-odd/src/config/migrate.ts +++ b/app-shell-odd/src/config/migrate.ts @@ -16,6 +16,7 @@ import type { ConfigV21, ConfigV22, ConfigV23, + ConfigV24, } from '@opentrons/app/src/redux/config/types' // format // base config v12 defaults @@ -214,6 +215,17 @@ const toVersion23 = (prevConfig: ConfigV22): ConfigV23 => { return nextConfig } +const toVersion24 = (prevConfig: ConfigV23): ConfigV24 => { + const { support, ...rest } = prevConfig + return { + ...rest, + version: 24 as const, + userInfo: { + userId: uuid(), + }, + } +} + const MIGRATIONS: [ (prevConfig: ConfigV12) => ConfigV13, (prevConfig: ConfigV13) => ConfigV14, @@ -225,7 +237,8 @@ const MIGRATIONS: [ (prevConfig: ConfigV19) => ConfigV20, (prevConfig: ConfigV20) => ConfigV21, (prevConfig: ConfigV21) => ConfigV22, - (prevConfig: ConfigV22) => ConfigV23 + (prevConfig: ConfigV22) => ConfigV23, + (prevConfig: ConfigV23) => ConfigV24 ] = [ toVersion13, toVersion14, @@ -238,6 +251,7 @@ const MIGRATIONS: [ toVersion21, toVersion22, toVersion23, + toVersion24, ] export const DEFAULTS: Config = migrate(DEFAULTS_V12) @@ -256,6 +270,7 @@ export function migrate( | ConfigV21 | ConfigV22 | ConfigV23 + | ConfigV24 ): Config { let result = prevConfig // loop through the migrations, skipping any migrations that are unnecessary diff --git a/app-shell/src/__fixtures__/config.ts b/app-shell/src/__fixtures__/config.ts index c118630c09d..23ef4f56f90 100644 --- a/app-shell/src/__fixtures__/config.ts +++ b/app-shell/src/__fixtures__/config.ts @@ -23,6 +23,7 @@ import type { ConfigV21, ConfigV22, ConfigV23, + ConfigV24, } from '@opentrons/app/src/redux/config/types' export const MOCK_CONFIG_V0: ConfigV0 = { @@ -290,3 +291,14 @@ export const MOCK_CONFIG_V23: ConfigV23 = { hasDismissedQuickTransferIntro: false, }, } + +export const MOCK_CONFIG_V24: ConfigV24 = { + ...(() => { + const { support, ...rest } = MOCK_CONFIG_V23 + return rest + })(), + version: 24, + userInfo: { + userId: 'MOCK_UUIDv4', + }, +} diff --git a/app-shell/src/config/__tests__/migrate.test.ts b/app-shell/src/config/__tests__/migrate.test.ts index d95109d8661..dee16e0dae4 100644 --- a/app-shell/src/config/__tests__/migrate.test.ts +++ b/app-shell/src/config/__tests__/migrate.test.ts @@ -1,5 +1,7 @@ // config migration tests -import { describe, it, expect } from 'vitest' +import { describe, it, expect, beforeEach, vi } from 'vitest' +import uuid from 'uuid/v4' + import { MOCK_CONFIG_V0, MOCK_CONFIG_V1, @@ -25,18 +27,26 @@ import { MOCK_CONFIG_V21, MOCK_CONFIG_V22, MOCK_CONFIG_V23, + MOCK_CONFIG_V24, } from '../../__fixtures__' import { migrate } from '../migrate' -const NEWEST_VERSION = 23 +vi.mock('uuid/v4') + +const NEWEST_VERSION = 24 +const NEWEST_MOCK_CONFIG = MOCK_CONFIG_V24 describe('config migration', () => { + beforeEach(() => { + vi.mocked(uuid).mockReturnValue('MOCK_UUIDv4') + }) + it('should migrate version 0 to latest', () => { const v0Config = MOCK_CONFIG_V0 const result = migrate(v0Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 1 to latest', () => { @@ -44,7 +54,7 @@ describe('config migration', () => { const result = migrate(v1Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 2 to latest', () => { @@ -52,7 +62,7 @@ describe('config migration', () => { const result = migrate(v2Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 3 to latest', () => { @@ -60,7 +70,7 @@ describe('config migration', () => { const result = migrate(v3Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 4 to latest', () => { @@ -68,7 +78,7 @@ describe('config migration', () => { const result = migrate(v4Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 5 to latest', () => { @@ -76,7 +86,7 @@ describe('config migration', () => { const result = migrate(v5Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 6 to latest', () => { @@ -84,7 +94,7 @@ describe('config migration', () => { const result = migrate(v6Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 7 to latest', () => { @@ -92,7 +102,7 @@ describe('config migration', () => { const result = migrate(v7Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 8 to latest', () => { @@ -100,7 +110,7 @@ describe('config migration', () => { const result = migrate(v8Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 9 to latest', () => { @@ -108,7 +118,7 @@ describe('config migration', () => { const result = migrate(v9Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 10 to latest', () => { @@ -116,7 +126,7 @@ describe('config migration', () => { const result = migrate(v10Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 11 to latest', () => { @@ -124,7 +134,7 @@ describe('config migration', () => { const result = migrate(v11Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 12 to latest', () => { @@ -132,7 +142,7 @@ describe('config migration', () => { const result = migrate(v12Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 13 to latest', () => { @@ -140,7 +150,7 @@ describe('config migration', () => { const result = migrate(v13Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 14 to latest', () => { @@ -148,7 +158,7 @@ describe('config migration', () => { const result = migrate(v14Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 15 to latest', () => { @@ -156,7 +166,7 @@ describe('config migration', () => { const result = migrate(v15Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 16 to latest', () => { @@ -164,7 +174,7 @@ describe('config migration', () => { const result = migrate(v16Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 17 to latest', () => { @@ -172,48 +182,55 @@ describe('config migration', () => { const result = migrate(v17Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migrate version 18 to latest', () => { const v18Config = MOCK_CONFIG_V18 const result = migrate(v18Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should keep migrate version 19 to latest', () => { const v19Config = MOCK_CONFIG_V19 const result = migrate(v19Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migration version 20 to latest', () => { const v20Config = MOCK_CONFIG_V20 const result = migrate(v20Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migration version 21 to latest', () => { const v21Config = MOCK_CONFIG_V21 const result = migrate(v21Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) it('should migration version 22 to latest', () => { const v22Config = MOCK_CONFIG_V22 const result = migrate(v22Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) - it('should keep version 23', () => { + it('should migrate version 23 to latest', () => { const v23Config = MOCK_CONFIG_V23 const result = migrate(v23Config) expect(result.version).toBe(NEWEST_VERSION) - expect(result).toEqual(MOCK_CONFIG_V23) + expect(result).toEqual(NEWEST_MOCK_CONFIG) + }) + it('should keep version 24', () => { + const v24Config = MOCK_CONFIG_V24 + const result = migrate(v24Config) + + expect(result.version).toBe(NEWEST_VERSION) + expect(result).toEqual(NEWEST_MOCK_CONFIG) }) }) diff --git a/app-shell/src/config/migrate.ts b/app-shell/src/config/migrate.ts index d9c4b063213..fa9ed4a91dd 100644 --- a/app-shell/src/config/migrate.ts +++ b/app-shell/src/config/migrate.ts @@ -27,6 +27,7 @@ import type { ConfigV21, ConfigV22, ConfigV23, + ConfigV24, } from '@opentrons/app/src/redux/config/types' // format // base config v0 defaults @@ -418,6 +419,17 @@ const toVersion23 = (prevConfig: ConfigV22): ConfigV23 => { return nextConfig } +const toVersion24 = (prevConfig: ConfigV23): ConfigV24 => { + const { support, ...rest } = prevConfig + return { + ...rest, + version: 24 as const, + userInfo: { + userId: uuid(), + }, + } +} + const MIGRATIONS: [ (prevConfig: ConfigV0) => ConfigV1, (prevConfig: ConfigV1) => ConfigV2, @@ -441,7 +453,8 @@ const MIGRATIONS: [ (prevConfig: ConfigV19) => ConfigV20, (prevConfig: ConfigV20) => ConfigV21, (prevConfig: ConfigV21) => ConfigV22, - (prevConfig: ConfigV22) => ConfigV23 + (prevConfig: ConfigV22) => ConfigV23, + (prevConfig: ConfigV23) => ConfigV24 ] = [ toVersion1, toVersion2, @@ -466,6 +479,7 @@ const MIGRATIONS: [ toVersion21, toVersion22, toVersion23, + toVersion24, ] export const DEFAULTS: Config = migrate(DEFAULTS_V0) @@ -496,6 +510,7 @@ export function migrate( | ConfigV21 | ConfigV22 | ConfigV23 + | ConfigV24 ): Config { const prevVersion = prevConfig.version let result = prevConfig diff --git a/app/src/organisms/Devices/RobotOverview.tsx b/app/src/organisms/Devices/RobotOverview.tsx index 85ae49581cb..1e84891d524 100644 --- a/app/src/organisms/Devices/RobotOverview.tsx +++ b/app/src/organisms/Devices/RobotOverview.tsx @@ -66,7 +66,7 @@ export function RobotOverview({ const isRobotViewable = useIsRobotViewable(robot?.name ?? '') const { lightsOn, toggleLights } = useLights() - const userId = useSelector(getConfig)?.support?.userId ?? 'Opentrons-user' + const userId = useSelector(getConfig)?.userInfo?.userId ?? 'Opentrons-user' const addresses = useSelector((state: State) => getRobotAddressesByName(state, robot?.name ?? '') diff --git a/app/src/organisms/Devices/__tests__/RobotOverview.test.tsx b/app/src/organisms/Devices/__tests__/RobotOverview.test.tsx index 66f6d18b7d0..6aaa236d49c 100644 --- a/app/src/organisms/Devices/__tests__/RobotOverview.test.tsx +++ b/app/src/organisms/Devices/__tests__/RobotOverview.test.tsx @@ -151,7 +151,7 @@ describe('RobotOverview', () => { .calledWith(MOCK_STATE, mockConnectableRobot.name) .thenReturn([]) vi.mocked(getConfig).mockReturnValue({ - support: { userId: 'opentrons-robot-user' }, + userInfo: { userId: 'opentrons-robot-user' }, } as Config) when(useAuthorization) .calledWith({ diff --git a/app/src/redux/config/__tests__/selectors.test.ts b/app/src/redux/config/__tests__/selectors.test.ts index 3ba6c0ea6cf..18262108c0a 100644 --- a/app/src/redux/config/__tests__/selectors.test.ts +++ b/app/src/redux/config/__tests__/selectors.test.ts @@ -282,4 +282,20 @@ describe('shell selectors', () => { expect(Selectors.getApplyHistoricOffsets(state)).toEqual(true) }) }) + + describe('getUserId', () => { + it('should return userId if it exists in config', () => { + const state: State = { + config: { + userInfo: { userId: 'test-user-id' }, + }, + } as any + expect(Selectors.getUserId(state)).toEqual('test-user-id') + }) + + it('should return an empty string if config is null', () => { + const state: State = { config: null } as any + expect(Selectors.getUserId(state)).toEqual('') + }) + }) }) diff --git a/app/src/redux/config/schema-types.ts b/app/src/redux/config/schema-types.ts index ae554217e11..ae83dbabe7e 100644 --- a/app/src/redux/config/schema-types.ts +++ b/app/src/redux/config/schema-types.ts @@ -268,4 +268,11 @@ export type ConfigV23 = Omit & { } } -export type Config = ConfigV23 +export type ConfigV24 = Omit & { + version: 24 + userInfo: { + userId: string + } +} + +export type Config = ConfigV24 diff --git a/app/src/redux/config/selectors.ts b/app/src/redux/config/selectors.ts index f7de3783290..76749e0a869 100644 --- a/app/src/redux/config/selectors.ts +++ b/app/src/redux/config/selectors.ts @@ -145,3 +145,8 @@ export const getOnDeviceDisplaySettings: ( unfinishedUnboxingFlowRoute: '/welcome', } }) + +export const getUserId: (state: State) => string = createSelector( + getConfig, + config => config?.userInfo.userId ?? '' +)