Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curvy-yaks-strive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smartthings/cli": patch
---

add organization options back to edge commands that use them
29 changes: 19 additions & 10 deletions src/__tests__/commands/edge/channels/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import type { ArgumentsCamelCase, Argv } from 'yargs'
import { ChannelsEndpoint } from '@smartthings/core-sdk'

import type { CommandArgs } from '../../../../commands/edge/channels/delete.js'
import type { buildEpilog } from '../../../../lib/help.js'
import type { APICommand, APICommandFlags } from '../../../../lib/command/api-command.js'
import type { CLIConfig, resetManagedConfigKey } from '../../../../lib/cli-config.js'
import type { buildEpilog } from '../../../../lib/help.js'
import type {
apiOrganizationCommand,
apiOrganizationCommandBuilder,
APIOrganizationCommand,
APIOrganizationCommandFlags,
} from '../../../../lib/command/api-organization-command.js'
import type { chooseChannel } from '../../../../lib/command/util/edge/channels-choose.js'
import { apiCommandMocks } from '../../../test-lib/api-command-mock.js'
import { buildArgvMock } from '../../../test-lib/builder-mock.js'


Expand All @@ -23,7 +27,12 @@ jest.unstable_mockModule('../../../../lib/help.js', () => ({
buildEpilog: buildEpilogMock,
}))

const { apiCommandMock, apiCommandBuilderMock } = apiCommandMocks('../../../..')
const apiOrganizationCommandMock = jest.fn<typeof apiOrganizationCommand>()
const apiOrganizationCommandBuilderMock = jest.fn<typeof apiOrganizationCommandBuilder>()
jest.unstable_mockModule('../../../../lib/command/api-organization-command.js', () => ({
apiOrganizationCommand: apiOrganizationCommandMock,
apiOrganizationCommandBuilder: apiOrganizationCommandBuilderMock,
}))

const chooseChannelMock = jest.fn<typeof chooseChannel>().mockResolvedValue('chosen-channel-id')
jest.unstable_mockModule('../../../../lib/command/util/edge/channels-choose.js', () => ({
Expand All @@ -44,14 +53,14 @@ test('builder', () => {
exampleMock,
epilogMock,
argvMock,
} = buildArgvMock<APICommandFlags, CommandArgs>()
} = buildArgvMock<APIOrganizationCommandFlags, CommandArgs>()

apiCommandBuilderMock.mockReturnValue(argvMock)
apiOrganizationCommandBuilderMock.mockReturnValue(argvMock)

const builder = cmd.builder as (yargs: Argv<object>) => Argv<CommandArgs>
expect(builder(yargsMock)).toBe(argvMock)

expect(apiCommandBuilderMock).toHaveBeenCalledExactlyOnceWith(yargsMock)
expect(apiOrganizationCommandBuilderMock).toHaveBeenCalledExactlyOnceWith(yargsMock)

expect(positionalMock).toHaveBeenCalledTimes(1)
expect(optionMock).toHaveBeenCalledTimes(0)
Expand All @@ -74,12 +83,12 @@ test('handler', async () => {
},
},
cliConfig,
} as unknown as APICommand
apiCommandMock.mockResolvedValueOnce(command)
} as unknown as APIOrganizationCommand<ArgumentsCamelCase<CommandArgs>>
apiOrganizationCommandMock.mockResolvedValueOnce(command)

await expect(cmd.handler(inputArgv)).resolves.not.toThrow()

expect(apiCommandMock).toHaveBeenCalledExactlyOnceWith(inputArgv)
expect(apiOrganizationCommandMock).toHaveBeenCalledExactlyOnceWith(inputArgv)
expect(chooseChannelMock).toHaveBeenCalledExactlyOnceWith(
command,
'cmd-line-id',
Expand Down
27 changes: 18 additions & 9 deletions src/__tests__/commands/edge/channels/metainfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import type { CommandArgs } from '../../../../commands/edge/channels/metainfo.js
import { ChannelsEndpoint, DriverChannelDetails, EdgeDriver } from '@smartthings/core-sdk'

import type { buildEpilog } from '../../../../lib/help.js'
import type { APICommand, APICommandFlags } from '../../../../lib/command/api-command.js'
import type {
apiOrganizationCommand,
apiOrganizationCommandBuilder,
APIOrganizationCommand,
APIOrganizationCommandFlags,
} from '../../../../lib/command/api-organization-command.js'
import type { CustomCommonOutputProducer } from '../../../../lib/command/format.js'
import type { outputItemOrList, outputItemOrListBuilder } from '../../../../lib/command/listing-io.js'
import { type buildTableOutput, listTableFieldDefinitions } from '../../../../lib/command/util/edge-drivers.js'
import type { chooseChannel } from '../../../../lib/command/util/edge/channels-choose.js'
import { apiCommandMocks } from '../../../test-lib/api-command-mock.js'
import { buildArgvMock, buildArgvMockStub } from '../../../test-lib/builder-mock.js'
import { tableGeneratorMock } from '../../../test-lib/table-mock.js'

Expand All @@ -22,7 +26,12 @@ jest.unstable_mockModule('../../../../lib/help.js', () => ({
buildEpilog: buildEpilogMock,
}))

const { apiCommandMock, apiCommandBuilderMock } = apiCommandMocks('../../../..')
const apiOrganizationCommandMock = jest.fn<typeof apiOrganizationCommand>()
const apiOrganizationCommandBuilderMock = jest.fn<typeof apiOrganizationCommandBuilder>()
jest.unstable_mockModule('../../../../lib/command/api-organization-command.js', () => ({
apiOrganizationCommand: apiOrganizationCommandMock,
apiOrganizationCommandBuilder: apiOrganizationCommandBuilderMock,
}))

const outputItemOrListMock = jest.fn<typeof outputItemOrList<EdgeDriver>>()
const outputItemOrListBuilderMock = jest.fn<typeof outputItemOrListBuilder>()
Expand Down Expand Up @@ -55,16 +64,16 @@ test('builder', async () => {
exampleMock,
epilogMock,
argvMock,
} = buildArgvMock<APICommandFlags, CommandArgs>()
} = buildArgvMock<APIOrganizationCommandFlags, CommandArgs>()

apiCommandBuilderMock.mockReturnValue(apiCommandBuilderArgvMock)
apiOrganizationCommandBuilderMock.mockReturnValue(apiCommandBuilderArgvMock)
outputItemOrListBuilderMock.mockReturnValue(argvMock)

const builder = cmd.builder as (yargs: Argv<object>) => Argv<CommandArgs>

expect(builder(yargsMock)).toBe(argvMock)

expect(apiCommandBuilderMock).toHaveBeenCalledExactlyOnceWith(yargsMock)
expect(apiOrganizationCommandBuilderMock).toHaveBeenCalledExactlyOnceWith(yargsMock)
expect(outputItemOrListBuilderMock).toHaveBeenCalledExactlyOnceWith(apiCommandBuilderArgvMock)
expect(positionalMock).toHaveBeenCalledTimes(1)
expect(optionMock).toHaveBeenCalledTimes(1)
Expand Down Expand Up @@ -92,14 +101,14 @@ describe('handler', () => {
},
},
tableGenerator: tableGeneratorMock,
} as unknown as APICommand
apiCommandMock.mockResolvedValue(command)
} as unknown as APIOrganizationCommand<ArgumentsCamelCase<CommandArgs>>
apiOrganizationCommandMock.mockResolvedValue(command)

const baseInputArgv = { profile: 'default' } as ArgumentsCamelCase<CommandArgs>
it('prompts for a channel and lists metadata', async () => {
await expect(cmd.handler(baseInputArgv)).resolves.not.toThrow()

expect(apiCommandMock).toHaveBeenCalledExactlyOnceWith(baseInputArgv)
expect(apiOrganizationCommandMock).toHaveBeenCalledExactlyOnceWith(baseInputArgv)
expect(chooseChannelMock).toHaveBeenCalledExactlyOnceWith(
command,
undefined,
Expand Down
27 changes: 18 additions & 9 deletions src/__tests__/commands/edge/drivers/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import type { DriversEndpoint } from '@smartthings/core-sdk'

import type { CommandArgs } from '../../../../commands/edge/drivers/delete.js'
import type { buildEpilog } from '../../../../lib/help.js'
import type { APICommand, APICommandFlags } from '../../../../lib/command/api-command.js'
import type {
APIOrganizationCommand,
apiOrganizationCommand,
apiOrganizationCommandBuilder,
APIOrganizationCommandFlags,
} from '../../../../lib/command/api-organization-command.js'
import type { chooseDriver } from '../../../../lib/command/util/drivers-choose.js'
import { apiCommandMocks } from '../../../test-lib/api-command-mock.js'
import { buildArgvMock } from '../../../test-lib/builder-mock.js'


Expand All @@ -17,7 +21,12 @@ jest.unstable_mockModule('../../../../lib/help.js', () => ({
buildEpilog: buildEpilogMock,
}))

const { apiCommandMock, apiCommandBuilderMock } = apiCommandMocks('../../../..')
const apiOrganizationCommandMock = jest.fn<typeof apiOrganizationCommand>()
const apiOrganizationCommandBuilderMock = jest.fn<typeof apiOrganizationCommandBuilder>()
jest.unstable_mockModule('../../../../lib/command/api-organization-command.js', () => ({
apiOrganizationCommand: apiOrganizationCommandMock,
apiOrganizationCommandBuilder: apiOrganizationCommandBuilderMock,
}))

const chooseDriverMock = jest.fn<typeof chooseDriver>().mockResolvedValue('chosen-driver-id')
jest.unstable_mockModule('../../../../lib/command/util/drivers-choose.js', () => ({
Expand All @@ -38,14 +47,14 @@ test('builder', () => {
exampleMock,
epilogMock,
argvMock,
} = buildArgvMock<APICommandFlags, CommandArgs>()
} = buildArgvMock<APIOrganizationCommandFlags, CommandArgs>()

apiCommandBuilderMock.mockReturnValue(argvMock)
apiOrganizationCommandBuilderMock.mockReturnValue(argvMock)

const builder = cmd.builder as (yargs: Argv<object>) => Argv<CommandArgs>
expect(builder(yargsMock)).toBe(argvMock)

expect(apiCommandBuilderMock).toHaveBeenCalledExactlyOnceWith(yargsMock)
expect(apiOrganizationCommandBuilderMock).toHaveBeenCalledExactlyOnceWith(yargsMock)

expect(positionalMock).toHaveBeenCalledTimes(1)
expect(optionMock).toHaveBeenCalledTimes(0)
Expand All @@ -62,8 +71,8 @@ test('handler', async () => {
delete: apiDriversDeleteMock,
},
},
} as unknown as APICommand
apiCommandMock.mockResolvedValue(command)
} as unknown as APIOrganizationCommand<ArgumentsCamelCase<CommandArgs>>
apiOrganizationCommandMock.mockResolvedValue(command)

const inputArgv = {
profile: 'default',
Expand All @@ -72,7 +81,7 @@ test('handler', async () => {

await expect(cmd.handler(inputArgv)).resolves.not.toThrow()

expect(apiCommandMock).toHaveBeenCalledExactlyOnceWith(inputArgv)
expect(apiOrganizationCommandMock).toHaveBeenCalledExactlyOnceWith(inputArgv)
expect(chooseDriverMock)
.toHaveBeenCalledExactlyOnceWith(command, 'cmd-line-id', { promptMessage: 'Select a driver to delete.' })
expect(apiDriversDeleteMock).toHaveBeenCalledExactlyOnceWith('chosen-driver-id')
Expand Down
31 changes: 19 additions & 12 deletions src/__tests__/commands/edge/drivers/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ import type { CommandArgs } from '../../../../commands/edge/drivers/package.js'
import type { buildEpilog } from '../../../../lib/help.js'
import type { CLIConfig } from '../../../../lib/cli-config.js'
import type { fatalError } from '../../../../lib/util.js'
import type { APICommand } from '../../../../lib/command/api-command.js'
import type { outputItem, outputItemBuilder } from '../../../../lib/command/output-item.js'
import type { SmartThingsCommandFlags } from '../../../../lib/command/smartthings-command.js'
import type {
apiOrganizationCommand,
apiOrganizationCommandBuilder,
APIOrganizationCommand,
} from '../../../../lib/command/api-organization-command.js'
import type { outputItem, outputItemBuilder, OutputItemFlags } from '../../../../lib/command/output-item.js'
import type {
buildTestFileMatchers,
processConfigFile,
Expand All @@ -32,7 +35,6 @@ import type {
} from '../../../../lib/command/util/edge-driver-package.js'
import type { chooseHub } from '../../../../lib/command/util/hubs-choose.js'
import type { chooseChannel } from '../../../../lib/command/util/edge/channels-choose.js'
import { apiCommandMocks } from '../../../test-lib/api-command-mock.js'
import { buildArgvMock, buildArgvMockStub } from '../../../test-lib/builder-mock.js'


Expand All @@ -46,6 +48,13 @@ jest.unstable_mockModule('../../../../lib/util.js', () => ({
fatalError: fatalErrorMock,
}))

const apiOrganizationCommandMock = jest.fn<typeof apiOrganizationCommand>()
const apiOrganizationCommandBuilderMock = jest.fn<typeof apiOrganizationCommandBuilder>()
jest.unstable_mockModule('../../../../lib/command/api-organization-command.js', () => ({
apiOrganizationCommand: apiOrganizationCommandMock,
apiOrganizationCommandBuilder: apiOrganizationCommandBuilderMock,
}))

const createWriteStreamMock = jest.fn<typeof createWriteStream>()
jest.unstable_mockModule('node:fs', () => ({
createWriteStream: createWriteStreamMock,
Expand Down Expand Up @@ -73,8 +82,6 @@ jest.unstable_mockModule('jszip', () => ({
default: JSZipMock,
}))

const { apiCommandMock, apiCommandBuilderMock } = apiCommandMocks('../../../..')

const outputItemMock = jest.fn<typeof outputItem>()
const outputItemBuilderMock = jest.fn<typeof outputItemBuilder>()
jest.unstable_mockModule('../../../../lib/command/output-item.js', () => ({
Expand Down Expand Up @@ -129,16 +136,16 @@ test('builder', () => {
exampleMock,
epilogMock,
argvMock,
} = buildArgvMock<SmartThingsCommandFlags, CommandArgs>()
} = buildArgvMock<OutputItemFlags, CommandArgs>()

apiCommandBuilderMock.mockReturnValue(apiCommandBuilderArgvMock)
apiOrganizationCommandBuilderMock.mockReturnValue(apiCommandBuilderArgvMock)
outputItemBuilderMock.mockReturnValue(argvMock)

const builder = cmd.builder as (yargs: Argv<object>) => Argv<CommandArgs>

expect(builder(yargsMock)).toBe(argvMock)

expect(apiCommandBuilderMock).toHaveBeenCalledExactlyOnceWith(yargsMock)
expect(apiOrganizationCommandBuilderMock).toHaveBeenCalledExactlyOnceWith(yargsMock)
expect(outputItemBuilderMock).toHaveBeenCalledExactlyOnceWith(apiCommandBuilderArgvMock)
expect(positionalMock).toHaveBeenCalledTimes(1)
expect(optionMock).toHaveBeenCalledTimes(6)
Expand Down Expand Up @@ -167,8 +174,8 @@ describe('handler', () => {
cliConfig: {
stringArrayConfigValue: stringArrayConfigValueMock,
},
} as unknown as APICommand<ArgumentsCamelCase<CommandArgs>>
apiCommandMock.mockResolvedValue(command)
} as unknown as APIOrganizationCommand<ArgumentsCamelCase<CommandArgs>>
apiOrganizationCommandMock.mockResolvedValue(command)

const driver = { driverId: 'driver-id', version: 'driver version' } as EdgeDriver
apiDriversUploadMock.mockResolvedValue(driver)
Expand All @@ -179,7 +186,7 @@ describe('handler', () => {

await expect(cmd.handler(inputArgv)).resolves.not.toThrow()

expect(apiCommandMock).toHaveBeenCalledExactlyOnceWith(inputArgv)
expect(apiOrganizationCommandMock).toHaveBeenCalledExactlyOnceWith(inputArgv)
expect(readFileMock).toHaveBeenCalledExactlyOnceWith('driver.zip')
expect(outputItemMock).toHaveBeenCalledExactlyOnceWith(
command,
Expand Down
12 changes: 8 additions & 4 deletions src/commands/edge/channels/assign.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { type ArgumentsCamelCase, type Argv, type CommandModule } from 'yargs'

import { buildEpilog } from '../../../lib/help.js'
import { apiCommand, apiCommandBuilder, type APICommandFlags } from '../../../lib/command/api-command.js'
import {
apiOrganizationCommand,
apiOrganizationCommandBuilder,
type APIOrganizationCommandFlags,
} from '../../../lib/command/api-organization-command.js'
import { chooseChannel } from '../../../lib/command/util/edge/channels-choose.js'
import { chooseDriver } from '../../../lib/command/util/drivers-choose.js'


export type CommandArgs =
& APICommandFlags
& APIOrganizationCommandFlags
& {
driverId?: string
driverVersion?: string
Expand All @@ -19,7 +23,7 @@ const command = 'edge:channels:assign [driver-id] [driver-version]'
const describe = 'assign a driver to a channel'

const builder = (yargs: Argv): Argv<CommandArgs> =>
apiCommandBuilder(yargs)
apiOrganizationCommandBuilder(yargs)
.positional('driver-id', { describe: 'driver id', type: 'string' })
.positional('driver-version', { describe: 'driver version', type: 'string' })
.option('channel', { alias: 'C', describe: 'channel to assigned to', type: 'string' })
Expand All @@ -43,7 +47,7 @@ const builder = (yargs: Argv): Argv<CommandArgs> =>


const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
const command = await apiCommand(argv)
const command = await apiOrganizationCommand(argv)

const channelId = await chooseChannel(
command,
Expand Down
14 changes: 9 additions & 5 deletions src/commands/edge/channels/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ import { type ArgumentsCamelCase, type Argv, type CommandModule } from 'yargs'
import { type Channel, type ChannelCreate } from '@smartthings/core-sdk'

import { buildEpilog } from '../../../lib/help.js'
import { type TableFieldDefinition } from '../../../lib/table-generator.js'
import { stringInput } from '../../../lib/user-query.js'
import { urlValidate } from '../../../lib/validate-util.js'
import { apiCommand, apiCommandBuilder, type APICommandFlags } from '../../../lib/command/api-command.js'
import {
apiOrganizationCommand,
apiOrganizationCommandBuilder,
type APIOrganizationCommandFlags,
} from '../../../lib/command/api-organization-command.js'
import {
inputAndOutputItem,
inputAndOutputItemBuilder,
type InputAndOutputItemFlags,
} from '../../../lib/command/input-and-output-item.js'
import { type TableFieldDefinition } from '../../../lib/table-generator.js'
import { userInputProcessor } from '../../../lib/command/input-processor.js'


export type CommandArgs =
& APICommandFlags
& APIOrganizationCommandFlags
& InputAndOutputItemFlags

const command = 'edge:channels:create'
Expand All @@ -27,7 +31,7 @@ const tableFieldDefinitions: TableFieldDefinition<Channel>[] = ['channelId', 'na
'type', 'termsOfServiceUrl', 'createdDate', 'lastModifiedDate']

const builder = (yargs: Argv): Argv<CommandArgs> =>
inputAndOutputItemBuilder(apiCommandBuilder(yargs))
inputAndOutputItemBuilder(apiOrganizationCommandBuilder(yargs))
.example([
[
'$0 edge:channels:create',
Expand All @@ -41,7 +45,7 @@ const builder = (yargs: Argv): Argv<CommandArgs> =>
.epilog(buildEpilog({ command, apiDocs: 'createChannel' }))

const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => {
const command = await apiCommand(argv)
const command = await apiOrganizationCommand(argv)

const getInputFromUser = async (): Promise<ChannelCreate> => {
const name = await stringInput('Channel name:')
Expand Down
Loading