Skip to content

Commit

Permalink
feat(app): add userInfo to redux config (#15797)
Browse files Browse the repository at this point in the history
Closes EXEC-628

In the (near) future, apps will stake ownership in error recovery and perhaps later on, protocol runs. A basis for staking ownership requires some sort of unique identification, which we can do via UUIDs. Let's have clients generate their own UUID that's persisted in the electron config file.
  • Loading branch information
mjhuff authored Jul 25, 2024
1 parent 86d75bd commit d8f8023
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 47 deletions.
12 changes: 12 additions & 0 deletions app-shell-odd/src/config/__fixtures__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
ConfigV21,
ConfigV22,
ConfigV23,
ConfigV24,
} from '@opentrons/app/src/redux/config/types'

const PKG_VERSION: string = _PKG_VERSION_
Expand Down Expand Up @@ -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',
},
}
47 changes: 32 additions & 15 deletions app-shell-odd/src/config/__tests__/migrate.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -13,102 +15,117 @@ 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', () => {
const v13Config = MOCK_CONFIG_V13
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', () => {
const v14Config = MOCK_CONFIG_V14
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', () => {
const v15Config = MOCK_CONFIG_V15
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', () => {
const v16Config = MOCK_CONFIG_V16
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', () => {
const v17Config = MOCK_CONFIG_V17
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', () => {
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 migration 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(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)
})
})
17 changes: 16 additions & 1 deletion app-shell-odd/src/config/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
ConfigV21,
ConfigV22,
ConfigV23,
ConfigV24,
} from '@opentrons/app/src/redux/config/types'
// format
// base config v12 defaults
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -238,6 +251,7 @@ const MIGRATIONS: [
toVersion21,
toVersion22,
toVersion23,
toVersion24,
]

export const DEFAULTS: Config = migrate(DEFAULTS_V12)
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions app-shell/src/__fixtures__/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
ConfigV21,
ConfigV22,
ConfigV23,
ConfigV24,
} from '@opentrons/app/src/redux/config/types'

export const MOCK_CONFIG_V0: ConfigV0 = {
Expand Down Expand Up @@ -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',
},
}
Loading

0 comments on commit d8f8023

Please sign in to comment.