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
7 changes: 6 additions & 1 deletion src/__tests__/commands/apps/oauth/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
SmartThingsClient,
} from '@smartthings/core-sdk'

import type { itemInputHelpText } from '../../../../lib/help.js'
import type { APICommand, APICommandFlags } from '../../../../lib/command/api-command.js'
import type {
inputAndOutputItem,
Expand All @@ -24,11 +25,15 @@ import { apiCommandMocks } from '../../../test-lib/api-command-mock.js'
import { buildInputDefMock } from '../../../test-lib/input-type-mock.js'


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

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

const inputAndOutputItemMock =
Expand Down
7 changes: 6 additions & 1 deletion src/__tests__/commands/apps/oauth/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
SmartThingsClient,
} from '@smartthings/core-sdk'

import type { itemInputHelpText } from '../../../../lib/help.js'
import type { APICommand, APICommandFlags } from '../../../../lib/command/api-command.js'
import type {
inputAndOutputItem,
Expand All @@ -25,11 +26,15 @@ import { apiCommandMocks } from '../../../test-lib/api-command-mock.js'
import { buildInputDefMock } from '../../../test-lib/input-type-mock.js'


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

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

const inputAndOutputItemMock =
Expand Down
32 changes: 8 additions & 24 deletions src/__tests__/lib/command/api-command.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { jest } from '@jest/globals'

import { osLocale } from 'os-locale'
import type { osLocale } from 'os-locale'

import {
import type {
Authenticator,
Logger,
RESTClientConfig,
SmartThingsClient,
WarningFromHeader,
} from '@smartthings/core-sdk'

import {
import type {
SmartThingsCommand,
SmartThingsCommandFlags,
smartThingsCommand,
smartThingsCommandBuilder,
} from '../../../lib/command/smartthings-command.js'
import { newBearerTokenAuthenticator, newSmartThingsClient } from '../../../lib/command/util/st-client-wrapper.js'
import { coreSDKLoggerFromLog4JSLogger } from '../../../lib/log-utils.js'
import { defaultClientIdProvider, loginAuthenticator } from '../../../lib/login-authenticator.js'
import { TableGenerator } from '../../../lib/table-generator.js'
import type { newBearerTokenAuthenticator, newSmartThingsClient } from '../../../lib/command/util/st-client-wrapper.js'
import type { coreSDKLoggerFromLog4JSLogger } from '../../../lib/log-utils.js'
import { defaultClientIdProvider, type loginAuthenticator } from '../../../lib/login-authenticator.js'
import type { TableGenerator } from '../../../lib/table-generator.js'
import { buildArgvMock } from '../../test-lib/builder-mock.js'
import { CLIConfig } from '../../../lib/cli-config.js'
import type { CLIConfig } from '../../../lib/cli-config.js'


const { errorMock, loggerMock } = await import('../../test-lib/logger-mock.js')
Expand Down Expand Up @@ -92,7 +92,6 @@ const {
apiCommand,
apiCommandBuilder,
apiDocsURL,
itemInputHelpText,
userAgent,
} = await import('../../../lib/command/api-command.js')

Expand All @@ -112,21 +111,6 @@ describe('apiDocsURL', () => {
})
})

describe('itemInputHelpText', () => {
it('works with external URLs', () => {
expect(itemInputHelpText('https://adafruit.com', 'https://digikey.com'))
.toBe('More information can be found at:\n' +
' https://adafruit.com\n' +
' https://digikey.com')
})

it('builds URLs like `apiDocsURL`', () => {
expect(itemInputHelpText('getDevice'))
.toBe('More information can be found at:\n' +
' https://developer.smartthings.com/docs/api/public/#operation/getDevice')
})
})

test('apiCommandBuilder', () => {
const { optionMock, argvMock } = buildArgvMock<SmartThingsCommandFlags>()
smartThingsCommandBuilderMock.mockReturnValueOnce(argvMock)
Expand Down
5 changes: 0 additions & 5 deletions src/__tests__/test-lib/api-command-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,27 @@ import {
type APICommandFlags,
type apiCommand,
type apiDocsURL,
type itemInputHelpText,
} from '../../lib/command/api-command.js'
import { buildArgvMockStub, type BuilderFunctionMock } from './builder-mock.js'


export const apiCommandMocks = <T extends APICommandFlags = APICommandFlags>(prefix: string): {
apiDocsURLMock: jest.Mock<typeof apiDocsURL>
itemInputHelpTextMock: jest.Mock<typeof itemInputHelpText>
apiCommandMock: jest.Mock<typeof apiCommand>
apiCommandBuilderMock: BuilderFunctionMock<Argv<T>>
} => {
const apiDocsURLMock = jest.fn<typeof apiDocsURL>()
const itemInputHelpTextMock = jest.fn<typeof itemInputHelpText>()
const apiCommandBuilderMock = buildArgvMockStub<T>()
const apiCommandMock = jest.fn<typeof apiCommand>()
jest.unstable_mockModule(`${prefix}/lib/command/api-command.js`, () => ({
userAgent,
apiDocsURL: apiDocsURLMock,
itemInputHelpText: itemInputHelpTextMock,
apiCommandBuilder: apiCommandBuilderMock,
apiCommand: apiCommandMock,
}))

return {
apiDocsURLMock,
itemInputHelpTextMock,
apiCommandBuilderMock,
apiCommandMock,
}
Expand Down
10 changes: 5 additions & 5 deletions src/commands/apps/oauth/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { type ArgumentsCamelCase, type Argv, type CommandModule } from 'yargs'

import type { GenerateAppOAuthRequest, GenerateAppOAuthResponse } from '@smartthings/core-sdk'

import { TableFieldDefinition } from '../../../lib/table-generator.js'
import { itemInputHelpText } from '../../../lib/help.js'
import { type TableFieldDefinition } from '../../../lib/table-generator.js'
import {
apiCommand,
apiCommandBuilder,
APICommandFlags,
type APICommandFlags,
apiDocsURL,
itemInputHelpText,
} from '../../../lib/command/api-command.js'
import {
inputAndOutputItem,
inputAndOutputItemBuilder,
InputAndOutputItemConfig,
InputAndOutputItemFlags,
type InputAndOutputItemConfig,
type InputAndOutputItemFlags,
} from '../../../lib/command/input-and-output-item.js'
import { inputProcessor } from '../../../lib/command/input-processor.js'
import { chooseApp } from '../../../lib/command/util/apps-util.js'
Expand Down
2 changes: 1 addition & 1 deletion src/commands/apps/oauth/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { type ArgumentsCamelCase, type Argv, type CommandModule } from 'yargs'

import { AppOAuthRequest } from '@smartthings/core-sdk'

import { itemInputHelpText } from '../../../lib/help.js'
import {
apiCommand,
apiCommandBuilder,
APICommandFlags,
apiDocsURL,
itemInputHelpText,
} from '../../../lib/command/api-command.js'
import {
inputAndOutputItem,
Expand Down
4 changes: 0 additions & 4 deletions src/lib/command/api-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ const toURL = (nameOrURL: string): string => nameOrURL.startsWith('http')

export const apiDocsURL = (...names: string[]): string => 'For API information, see:\n ' +
names.map(name => toURL(name)).join('\n ')


export const itemInputHelpText = (...namesOrURLs: string[]): string => 'More information can be found at:\n ' +
namesOrURLs.map(nameOrURL => toURL(nameOrURL)).join('\n ')
// TODO: END REMOVE

export type APICommandFlags = SmartThingsCommandFlags & {
Expand Down