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
10 changes: 8 additions & 2 deletions src/__tests__/commands/apps/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import type { ArgumentsCamelCase, Argv } from 'yargs'
import type { AppsEndpoint, SmartThingsClient } from '@smartthings/core-sdk'

import type { CommandArgs } from '../../../commands/apps/delete.js'
import type { buildEpilog } from '../../../lib/help.js'
import type { APICommand, APICommandFlags } from '../../../lib/command/api-command.js'
import type { chooseApp } from '../../../lib/command/util/apps-util.js'
import { apiCommandMocks } from '../../test-lib/api-command-mock.js'
import { buildArgvMock } from '../../test-lib/builder-mock.js'


const { apiCommandMock, apiCommandBuilderMock, apiDocsURLMock } = apiCommandMocks('../../..')
const buildEpilogMock = jest.fn<typeof buildEpilog>()
jest.unstable_mockModule('../../../lib/help.js', () => ({
buildEpilog: buildEpilogMock,
}))

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

const chooseAppMock = jest.fn<typeof chooseApp>()
jest.unstable_mockModule('../../../lib/command/util/apps-util.js', () => ({
Expand Down Expand Up @@ -43,7 +49,7 @@ test('builder', () => {

expect(positionalMock).toHaveBeenCalledTimes(1)
expect(exampleMock).toHaveBeenCalledTimes(1)
expect(apiDocsURLMock).toHaveBeenCalledTimes(1)
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
expect(epilogMock).toHaveBeenCalledTimes(1)
})

Expand Down
9 changes: 8 additions & 1 deletion src/__tests__/commands/capabilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { CapabilitiesEndpoint, Capability, OrganizationResponse, SmartThing

import type { CommandArgs } from '../../commands/capabilities.js'
import type { forAllOrganizations, WithOrganization } from '../../lib/api-helpers.js'
import type { buildEpilog } from '../../lib/help.js'
import type {
APIOrganizationCommand,
APIOrganizationCommandFlags,
Expand Down Expand Up @@ -40,6 +41,11 @@ jest.unstable_mockModule('../../lib/api-helpers.js', () => ({
forAllOrganizations: forAllOrganizationsMock,
}))

const buildEpilogMock = jest.fn<typeof buildEpilog>()
jest.unstable_mockModule('../../lib/help.js', () => ({
buildEpilog: buildEpilogMock,
}))

const apiOrganizationCommandMock = jest.fn<typeof apiOrganizationCommand>()
const apiOrganizationCommandBuilderMock = jest.fn<typeof apiOrganizationCommandBuilder>()
jest.unstable_mockModule('../../lib/command/api-organization-command.js', () => ({
Expand Down Expand Up @@ -116,8 +122,9 @@ test('builder', () => {
.toHaveBeenCalledExactlyOnceWith(capabilityIdOrIndexBuilderArgvMock)

expect(optionMock).toHaveBeenCalledTimes(2)
expect(epilogMock).toHaveBeenCalledTimes(1)
expect(exampleMock).toHaveBeenCalledTimes(1)
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
expect(epilogMock).toHaveBeenCalledTimes(1)
})

describe('handler', () => {
Expand Down
13 changes: 11 additions & 2 deletions src/__tests__/commands/devices/history.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import type { ArgumentsCamelCase, Argv } from 'yargs'
import type { DevicesEndpoint, HistoryEndpoint, DeviceActivity, Device, PaginatedList } from '@smartthings/core-sdk'

import type { CommandArgs } from '../../../commands/devices/history.js'
import type { CLIConfig } from '../../../lib/cli-config.js'
import type { buildEpilog } from '../../../lib/help.js'
import type { APICommand, APICommandFlags } from '../../../lib/command/api-command.js'
import { calculateOutputFormat, OutputFormatter, writeOutput } from '../../../lib/command/output.js'
import type { calculateOutputFormat, OutputFormatter, writeOutput } from '../../../lib/command/output.js'
import type {
buildOutputFormatter,
buildOutputFormatterBuilder,
Expand All @@ -22,9 +24,13 @@ import type {
import type { historyBuilder } from '../../../lib/command/util/history-builder.js'
import { apiCommandMocks } from '../../test-lib/api-command-mock.js'
import { buildArgvMock, buildArgvMockStub } from '../../test-lib/builder-mock.js'
import { CLIConfig } from '../../../lib/cli-config.js'


const buildEpilogMock = jest.fn<typeof buildEpilog>()
jest.unstable_mockModule('../../../lib/help.js', () => ({
buildEpilog: buildEpilogMock,
}))

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

const calculateOutputFormatMock = jest.fn<typeof calculateOutputFormat>()
Expand Down Expand Up @@ -76,6 +82,7 @@ test('builder', () => {
yargsMock: buildOutputFormatterBuilderArgvMock,
positionalMock,
exampleMock,
epilogMock,
argvMock,
} = buildArgvMock<APICommandFlags & BuildOutputFormatterFlags, CommandArgs>()

Expand All @@ -95,6 +102,8 @@ test('builder', () => {

expect(positionalMock).toHaveBeenCalledTimes(1)
expect(exampleMock).toHaveBeenCalledTimes(1)
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
expect(epilogMock).toHaveBeenCalledTimes(1)
})

describe('handler', () => {
Expand Down
11 changes: 10 additions & 1 deletion src/__tests__/commands/devices/preferences.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import type { ArgumentsCamelCase, Argv } from 'yargs'

import type { Device, DevicePreferenceResponse, DevicesEndpoint } from '@smartthings/core-sdk'

import type { CommandArgs } from '../../../commands/devices/preferences.js'
import type { buildEpilog } from '../../../lib/help.js'
import type { APICommand } from '../../../lib/command/api-command.js'
import type {
CustomCommonOutputProducer,
formatAndWriteItem,
formatAndWriteItemBuilder,
} from '../../../lib/command/format.js'
import type { CommandArgs } from '../../../commands/devices/preferences.js'
import type { BuildOutputFormatterFlags } from '../.././../lib/command/output-builder.js'
import type { SmartThingsCommandFlags } from '../../../lib/command/smartthings-command.js'
import type { ChooseFunction } from '../../../lib/command/util/util-util.js'
Expand All @@ -25,6 +26,11 @@ import {
} from '../../test-lib/table-mock.js'


const buildEpilogMock = jest.fn<typeof buildEpilog>()
jest.unstable_mockModule('../../../lib/help.js', () => ({
buildEpilog: buildEpilogMock,
}))

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

const chooseDeviceMock = jest.fn<ChooseFunction<Device>>()
Expand All @@ -49,6 +55,7 @@ test('builder', () => {
yargsMock: apiCommandBuilderArgvMock,
positionalMock,
exampleMock,
epilogMock,
argvMock,
} = buildArgvMock<SmartThingsCommandFlags, BuildOutputFormatterFlags>()

Expand All @@ -63,6 +70,8 @@ test('builder', () => {
expect(formatAndWriteItemBuilderMock).toHaveBeenCalledExactlyOnceWith(apiCommandBuilderArgvMock)
expect(positionalMock).toHaveBeenCalledOnce()
expect(exampleMock).toHaveBeenCalledOnce()
expect(buildEpilogMock).toHaveBeenCalledOnce()
expect(epilogMock).toHaveBeenCalledOnce()
})

const preferences: DevicePreferenceResponse = {
Expand Down
17 changes: 13 additions & 4 deletions src/__tests__/commands/edge/channels/invites.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ import { jest } from '@jest/globals'
import type { ArgumentsCamelCase, Argv } from 'yargs'

import type { CommandArgs } from '../../../../commands/edge/channels/invites.js'
import type { buildEpilog } from '../../../../lib/help.js'
import type { APICommand, APICommandFlags } from '../../../../lib/command/api-command.js'
import { outputItemOrList, outputItemOrListBuilder } from '../../../../lib/command/listing-io.js'
import type { edgeCommand, EdgeCommand } from '../../../../lib/command/edge-command.js'
import type { outputItemOrList, outputItemOrListBuilder } from '../../../../lib/command/listing-io.js'
import { listTableFieldDefinitions, tableFieldDefinitions } from '../../../../lib/command/util/edge-invites-table.js'
import type { buildListFunction } from '../../../../lib/command/util/edge-invites-util.js'
import type { Invitation, InvitesEndpoint } from '../../../../lib/edge/endpoints/invites.js'
import { apiCommandMocks } from '../../../test-lib/api-command-mock.js'
import { buildArgvMock, buildArgvMockStub } from '../../../test-lib/builder-mock.js'
import { Invitation, InvitesEndpoint } from '../../../../lib/edge/endpoints/invites.js'
import type { edgeCommand, EdgeCommand } from '../../../../lib/command/edge-command.js'
import { buildListFunction } from '../../../../lib/command/util/edge-invites-util.js'


const buildEpilogMock = jest.fn<typeof buildEpilog>()
jest.unstable_mockModule('../../../../lib/help.js', () => ({
buildEpilog: buildEpilogMock,
}))

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

const edgeCommandMock = jest.fn<typeof edgeCommand>()
Expand Down Expand Up @@ -43,6 +49,7 @@ test('builder', async () => {
positionalMock,
optionMock,
exampleMock,
epilogMock,
argvMock,
} = buildArgvMock<APICommandFlags, CommandArgs>()

Expand All @@ -58,6 +65,8 @@ test('builder', async () => {
expect(positionalMock).toHaveBeenCalledTimes(1)
expect(optionMock).toHaveBeenCalledTimes(1)
expect(exampleMock).toHaveBeenCalledTimes(1)
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
expect(epilogMock).toHaveBeenCalledTimes(1)
})

test('handler', async () => {
Expand Down
10 changes: 7 additions & 3 deletions src/__tests__/commands/edge/drivers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ import {
type listDrivers,
listTableFieldDefinitions,
} from '../../../lib/command/util/edge-drivers.js'
import { apiCommandMocks } from '../../test-lib/api-command-mock.js'
import type { buildEpilog } from '../../../lib/help.js'
import { buildArgvMock, buildArgvMockStub } from '../../test-lib/builder-mock.js'
import { tableGeneratorMock } from '../../test-lib/table-mock.js'


const { apiDocsURLMock } = apiCommandMocks('../../..')
const buildEpilogMock = jest.fn<typeof buildEpilog>()
jest.unstable_mockModule('../../../lib/help.js', () => ({ buildEpilog: buildEpilogMock }))


// buildEpilog is mocked; api-command mocks not required for this test post-migration

const apiOrganizationCommandMock = jest.fn<typeof apiOrganizationCommand>()
const apiOrganizationCommandBuilderMock = jest.fn<typeof apiOrganizationCommandBuilder>()
Expand Down Expand Up @@ -102,7 +106,7 @@ test('builder', () => {

expect(positionalMock).toHaveBeenCalledTimes(2)
expect(exampleMock).toHaveBeenCalledTimes(1)
expect(apiDocsURLMock).toHaveBeenCalledTimes(1)
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
expect(epilogMock).toHaveBeenCalledTimes(1)
})

Expand Down
16 changes: 11 additions & 5 deletions src/__tests__/commands/locations/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ import { ArgumentsCamelCase, Argv } from 'yargs'

import { Location, LocationCreate, LocationsEndpoint, SmartThingsClient } from '@smartthings/core-sdk'

import type { CommandArgs } from '../../../commands/locations/create.js'
import type { buildEpilog } from '../../../lib/help.js'
import { tableFieldDefinitions } from '../../../lib/command/util/locations-util.js'
import { APICommand, APICommandFlags } from '../../../lib/command/api-command.js'
import { inputAndOutputItem, inputAndOutputItemBuilder } from '../../../lib/command/input-and-output-item.js'
import { CommandArgs } from '../../../commands/locations/create.js'
import type { APICommand, APICommandFlags } from '../../../lib/command/api-command.js'
import type { inputAndOutputItem, inputAndOutputItemBuilder } from '../../../lib/command/input-and-output-item.js'
import { apiCommandMocks } from '../../test-lib/api-command-mock.js'
import { buildArgvMock, buildArgvMockStub } from '../../test-lib/builder-mock.js'


const { apiCommandMock, apiCommandBuilderMock, apiDocsURLMock } = apiCommandMocks('../../..')
const buildEpilogMock = jest.fn<typeof buildEpilog>()
jest.unstable_mockModule('../../../lib/help.js', () => ({
buildEpilog: buildEpilogMock,
}))

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

const inputAndOutputItemMock = jest.fn<typeof inputAndOutputItem>()
const inputAndOutputItemBuilderMock = jest.fn<typeof inputAndOutputItemBuilder>()
Expand Down Expand Up @@ -46,7 +52,7 @@ test('builder', () => {
expect(inputAndOutputItemBuilderMock).toHaveBeenCalledWith(apiCommandBuilderArgvMock)

expect(exampleMock).toHaveBeenCalledTimes(1)
expect(apiDocsURLMock).toHaveBeenCalledTimes(1)
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
expect(epilogMock).toHaveBeenCalledTimes(1)
})

Expand Down
10 changes: 8 additions & 2 deletions src/__tests__/commands/locations/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import type { ArgumentsCamelCase, Argv } from 'yargs'
import type { LocationsEndpoint, SmartThingsClient } from '@smartthings/core-sdk'

import type { CommandArgs } from '../../../commands/locations/delete.js'
import type { buildEpilog } from '../../../lib/help.js'
import type { APICommand, APICommandFlags } from '../../../lib/command/api-command.js'
import type { chooseLocation } from '../../../lib/command/util/locations-util.js'
import { apiCommandMocks } from '../../test-lib/api-command-mock.js'
import { buildArgvMock } from '../../test-lib/builder-mock.js'


const { apiCommandMock, apiCommandBuilderMock, apiDocsURLMock } = apiCommandMocks('../../..')
const buildEpilogMock = jest.fn<typeof buildEpilog>()
jest.unstable_mockModule('../../../lib/help.js', () => ({
buildEpilog: buildEpilogMock,
}))

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

const chooseLocationMock = jest.fn<typeof chooseLocation>()
jest.unstable_mockModule('../../../lib/command/util/locations-util.js', () => ({
Expand Down Expand Up @@ -43,7 +49,7 @@ test('builder', () => {

expect(positionalMock).toHaveBeenCalledTimes(1)
expect(exampleMock).toHaveBeenCalledTimes(1)
expect(apiDocsURLMock).toHaveBeenCalledTimes(1)
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
expect(epilogMock).toHaveBeenCalledTimes(1)
})

Expand Down
9 changes: 9 additions & 0 deletions src/__tests__/commands/locations/history.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { DeviceActivity, HistoryEndpoint, PaginatedList } from '@smartthing

import type { CommandArgs } from '../../../commands/devices/history.js'
import type { CLIConfig } from '../../../lib/cli-config.js'
import type { buildEpilog } from '../../../lib/help.js'
import type { APICommand, APICommandFlags } from '../../../lib/command/api-command.js'
import { calculateOutputFormat, OutputFormatter, writeOutput } from '../../../lib/command/output.js'
import type {
Expand All @@ -25,6 +26,11 @@ import { apiCommandMocks } from '../../test-lib/api-command-mock.js'
import { buildArgvMock, buildArgvMockStub } from '../../test-lib/builder-mock.js'


const buildEpilogMock = jest.fn<typeof buildEpilog>()
jest.unstable_mockModule('../../../lib/help.js', () => ({
buildEpilog: buildEpilogMock,
}))

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

const calculateOutputFormatMock = jest.fn<typeof calculateOutputFormat>()
Expand Down Expand Up @@ -76,6 +82,7 @@ test('builder', () => {
yargsMock: buildOutputFormatterBuilderArgvMock,
positionalMock,
exampleMock,
epilogMock,
argvMock,
} = buildArgvMock<APICommandFlags & BuildOutputFormatterFlags, CommandArgs>()

Expand All @@ -95,6 +102,8 @@ test('builder', () => {

expect(positionalMock).toHaveBeenCalledTimes(1)
expect(exampleMock).toHaveBeenCalledTimes(1)
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
expect(epilogMock).toHaveBeenCalledTimes(1)
})

describe('handler', () => {
Expand Down
12 changes: 9 additions & 3 deletions src/__tests__/commands/locations/rooms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@ import type { ArgumentsCamelCase, Argv } from 'yargs'
import type { Room, RoomsEndpoint } from '@smartthings/core-sdk'

import type { CommandArgs } from '../../../commands/locations/rooms.js'
import type { WithNamedLocation } from '../../../lib/api-helpers.js'
import type { buildEpilog } from '../../../lib/help.js'
import { fatalError } from '../../../lib/util.js'
import type { APICommand, APICommandFlags } from '../../../lib/command/api-command.js'
import type { WithNamedLocation } from '../../../lib/api-helpers.js'
import type { outputItemOrList, outputItemOrListBuilder } from '../../../lib/command/listing-io.js'
import { tableFieldDefinitions, tableFieldDefinitionsWithLocationName } from '../../../lib/command/util/rooms-table.js'
import type { getRoomsWithLocation } from '../../../lib/command/util/rooms-util.js'
import { apiCommandMocks } from '../../test-lib/api-command-mock.js'
import { buildArgvMock, buildArgvMockStub } from '../../test-lib/builder-mock.js'


const buildEpilogMock = jest.fn<typeof buildEpilog>()
jest.unstable_mockModule('../../../lib/help.js', () => ({
buildEpilog: buildEpilogMock,
}))

const fatalErrorMock = jest.fn<typeof fatalError>()
jest.unstable_mockModule('../../../lib/util.js', () => ({
fatalError: fatalErrorMock,
}))

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

const outputItemOrListMock = jest.fn<typeof outputItemOrList<Room & WithNamedLocation>>()
const outputItemOrListBuilderMock = jest.fn<typeof outputItemOrListBuilder>()
Expand Down Expand Up @@ -61,7 +67,7 @@ test('builder', async () => {
expect(positionalMock).toHaveBeenCalledTimes(1)
expect(optionMock).toHaveBeenCalledTimes(2)
expect(exampleMock).toHaveBeenCalledTimes(1)
expect(apiDocsURLMock).toHaveBeenCalledTimes(1)
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
expect(epilogMock).toHaveBeenCalledTimes(1)
})

Expand Down
9 changes: 7 additions & 2 deletions src/__tests__/commands/locations/rooms/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ArgumentsCamelCase, Argv } from 'yargs'
import type { Room, RoomRequest, RoomsEndpoint } from '@smartthings/core-sdk'

import type { CommandArgs } from '../../../../commands/locations/rooms/create.js'
import type { buildEpilog } from '../../../../lib/help.js'
import type { APICommand, APICommandFlags } from '../../../../lib/command/api-command.js'
import type {
inputAndOutputItem,
Expand All @@ -16,10 +17,14 @@ import { buildArgvMock, buildArgvMockStub } from '../../../test-lib/builder-mock
import { apiCommandMocks } from '../../../test-lib/api-command-mock.js'


const buildEpilogMock = jest.fn<typeof buildEpilog>()
jest.unstable_mockModule('../../../../lib/help.js', () => ({
buildEpilog: buildEpilogMock,
}))

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

const inputAndOutputItemMock =
Expand Down Expand Up @@ -62,7 +67,7 @@ test('builder', () => {
expect(positionalMock).toHaveBeenCalledTimes(0)
expect(optionMock).toHaveBeenCalledTimes(1)
expect(exampleMock).toHaveBeenCalledTimes(1)
expect(apiDocsURLMock).toHaveBeenCalledTimes(1)
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
expect(epilogMock).toHaveBeenCalledTimes(1)
})

Expand Down
Loading