Skip to content

Commit b8efe22

Browse files
committed
refactor: convert edge:channels:unassign command to yargs
1 parent 8411788 commit b8efe22

11 files changed

Lines changed: 182 additions & 313 deletions

File tree

packages/edge/src/commands/edge/channels/unassign.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/__tests__/commands/edge/channels/delete.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ test('handler', async () => {
7474
await expect(cmd.handler(inputArgv)).resolves.not.toThrow()
7575

7676
expect(apiCommandMock).toHaveBeenCalledExactlyOnceWith(inputArgv)
77-
expect(chooseChannelMock).toHaveBeenCalledExactlyOnceWith(command, 'Choose a channel to delete.', 'cmd-line-id')
77+
expect(chooseChannelMock).toHaveBeenCalledExactlyOnceWith(
78+
command,
79+
'cmd-line-id',
80+
{ promptMessage: 'Choose a channel to delete.' },
81+
)
7882
expect(apiChannelsDeleteMock).toHaveBeenCalledExactlyOnceWith('chosen-channel-id')
7983
expect(resetManagedConfigKeyMock).toHaveBeenCalledExactlyOnceWith(cliConfig, 'defaultChannel', expect.any(Function))
8084
expect(consoleLogSpy).toHaveBeenCalledWith('Channel chosen-channel-id deleted.')

src/__tests__/commands/edge/channels/drivers.test.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import type { ArgumentsCamelCase, Argv } from 'yargs'
55
import type { CommandArgs } from '../../../../commands/edge/channels/drivers.js'
66
import type { APICommand, APICommandFlags } from '../../../../lib/command/api-command.js'
77
import type { outputList, outputListBuilder } from '../../../../lib/command/output-list.js'
8-
import type { DriverChannelDetailsWithName, listAssignedDriversWithNames } from '../../../../lib/command/util/edge-drivers.js'
9-
import type { chooseChannel } from '../../../../lib/command/util/edge/channels-choose.js'
8+
import type {
9+
DriverChannelDetailsWithName,
10+
listAssignedDriversWithNames,
11+
} from '../../../../lib/command/util/edge-drivers.js'
12+
import type { ChooseFunction } from '../../../../lib/command/util/util-util.js'
13+
import type { ChannelChoice, chooseChannelFn } from '../../../../lib/command/util/edge/channels-choose.js'
1014
import { apiCommandMocks } from '../../../test-lib/api-command-mock.js'
1115
import { buildArgvMock, buildArgvMockStub } from '../../../test-lib/builder-mock.js'
1216

@@ -25,9 +29,10 @@ jest.unstable_mockModule('../../../../lib/command/util/edge-drivers.js', () => (
2529
listAssignedDriversWithNames: listAssignedDriversWithNamesMock,
2630
}))
2731

28-
const chooseChannelMock = jest.fn<typeof chooseChannel>()
32+
const chooseChannelMock = jest.fn<ChooseFunction<ChannelChoice>>()
33+
const chooseChannelFnMock = jest.fn<typeof chooseChannelFn>().mockReturnValue(chooseChannelMock)
2934
jest.unstable_mockModule('../../../../lib/command/util/edge/channels-choose.js', () => ({
30-
chooseChannel: chooseChannelMock,
35+
chooseChannelFn: chooseChannelFnMock,
3136
}))
3237

3338

@@ -74,11 +79,11 @@ test('handler', async () => {
7479
await expect(cmd.handler(inputArgv)).resolves.not.toThrow()
7580

7681
expect(apiCommandMock).toHaveBeenCalledExactlyOnceWith(inputArgv)
82+
expect(chooseChannelFnMock).toHaveBeenCalledExactlyOnceWith({ includeReadOnly: true })
7783
expect(chooseChannelMock).toHaveBeenCalledExactlyOnceWith(
7884
command,
79-
'Select a channel.',
8085
'cmd-line-id',
81-
{ allowIndex: true, includeReadOnly: true, useConfigDefault: true },
86+
{ allowIndex: true, useConfigDefault: true },
8287
)
8388
expect(outputListMock).toHaveBeenCalledExactlyOnceWith(
8489
command,

0 commit comments

Comments
 (0)