Skip to content

Commit 7efa847

Browse files
committed
feat: add buildEpilog to even more commands
1 parent 6c3e9d7 commit 7efa847

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+328
-147
lines changed

src/__tests__/commands/apps/delete.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ import type { ArgumentsCamelCase, Argv } from 'yargs'
55
import type { AppsEndpoint, SmartThingsClient } from '@smartthings/core-sdk'
66

77
import type { CommandArgs } from '../../../commands/apps/delete.js'
8+
import type { buildEpilog } from '../../../lib/help.js'
89
import type { APICommand, APICommandFlags } from '../../../lib/command/api-command.js'
910
import type { chooseApp } from '../../../lib/command/util/apps-util.js'
1011
import { apiCommandMocks } from '../../test-lib/api-command-mock.js'
1112
import { buildArgvMock } from '../../test-lib/builder-mock.js'
1213

1314

14-
const { apiCommandMock, apiCommandBuilderMock, apiDocsURLMock } = apiCommandMocks('../../..')
15+
const buildEpilogMock = jest.fn<typeof buildEpilog>()
16+
jest.unstable_mockModule('../../../lib/help.js', () => ({
17+
buildEpilog: buildEpilogMock,
18+
}))
19+
20+
const { apiCommandMock, apiCommandBuilderMock } = apiCommandMocks('../../..')
1521

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

4450
expect(positionalMock).toHaveBeenCalledTimes(1)
4551
expect(exampleMock).toHaveBeenCalledTimes(1)
46-
expect(apiDocsURLMock).toHaveBeenCalledTimes(1)
52+
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
4753
expect(epilogMock).toHaveBeenCalledTimes(1)
4854
})
4955

src/__tests__/commands/capabilities.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { CapabilitiesEndpoint, Capability, OrganizationResponse, SmartThing
66

77
import type { CommandArgs } from '../../commands/capabilities.js'
88
import type { forAllOrganizations, WithOrganization } from '../../lib/api-helpers.js'
9+
import type { buildEpilog } from '../../lib/help.js'
910
import type {
1011
APIOrganizationCommand,
1112
APIOrganizationCommandFlags,
@@ -40,6 +41,11 @@ jest.unstable_mockModule('../../lib/api-helpers.js', () => ({
4041
forAllOrganizations: forAllOrganizationsMock,
4142
}))
4243

44+
const buildEpilogMock = jest.fn<typeof buildEpilog>()
45+
jest.unstable_mockModule('../../lib/help.js', () => ({
46+
buildEpilog: buildEpilogMock,
47+
}))
48+
4349
const apiOrganizationCommandMock = jest.fn<typeof apiOrganizationCommand>()
4450
const apiOrganizationCommandBuilderMock = jest.fn<typeof apiOrganizationCommandBuilder>()
4551
jest.unstable_mockModule('../../lib/command/api-organization-command.js', () => ({
@@ -116,8 +122,9 @@ test('builder', () => {
116122
.toHaveBeenCalledExactlyOnceWith(capabilityIdOrIndexBuilderArgvMock)
117123

118124
expect(optionMock).toHaveBeenCalledTimes(2)
119-
expect(epilogMock).toHaveBeenCalledTimes(1)
120125
expect(exampleMock).toHaveBeenCalledTimes(1)
126+
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
127+
expect(epilogMock).toHaveBeenCalledTimes(1)
121128
})
122129

123130
describe('handler', () => {

src/__tests__/commands/devices/history.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import type { ArgumentsCamelCase, Argv } from 'yargs'
55
import type { DevicesEndpoint, HistoryEndpoint, DeviceActivity, Device, PaginatedList } from '@smartthings/core-sdk'
66

77
import type { CommandArgs } from '../../../commands/devices/history.js'
8+
import type { CLIConfig } from '../../../lib/cli-config.js'
9+
import type { buildEpilog } from '../../../lib/help.js'
810
import type { APICommand, APICommandFlags } from '../../../lib/command/api-command.js'
9-
import { calculateOutputFormat, OutputFormatter, writeOutput } from '../../../lib/command/output.js'
11+
import type { calculateOutputFormat, OutputFormatter, writeOutput } from '../../../lib/command/output.js'
1012
import type {
1113
buildOutputFormatter,
1214
buildOutputFormatterBuilder,
@@ -22,9 +24,13 @@ import type {
2224
import type { historyBuilder } from '../../../lib/command/util/history-builder.js'
2325
import { apiCommandMocks } from '../../test-lib/api-command-mock.js'
2426
import { buildArgvMock, buildArgvMockStub } from '../../test-lib/builder-mock.js'
25-
import { CLIConfig } from '../../../lib/cli-config.js'
2627

2728

29+
const buildEpilogMock = jest.fn<typeof buildEpilog>()
30+
jest.unstable_mockModule('../../../lib/help.js', () => ({
31+
buildEpilog: buildEpilogMock,
32+
}))
33+
2834
const { apiCommandBuilderMock, apiCommandMock } = apiCommandMocks('../../..')
2935

3036
const calculateOutputFormatMock = jest.fn<typeof calculateOutputFormat>()
@@ -76,6 +82,7 @@ test('builder', () => {
7682
yargsMock: buildOutputFormatterBuilderArgvMock,
7783
positionalMock,
7884
exampleMock,
85+
epilogMock,
7986
argvMock,
8087
} = buildArgvMock<APICommandFlags & BuildOutputFormatterFlags, CommandArgs>()
8188

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

96103
expect(positionalMock).toHaveBeenCalledTimes(1)
97104
expect(exampleMock).toHaveBeenCalledTimes(1)
105+
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
106+
expect(epilogMock).toHaveBeenCalledTimes(1)
98107
})
99108

100109
describe('handler', () => {

src/__tests__/commands/devices/preferences.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import type { ArgumentsCamelCase, Argv } from 'yargs'
44

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

7+
import type { CommandArgs } from '../../../commands/devices/preferences.js'
8+
import type { buildEpilog } from '../../../lib/help.js'
79
import type { APICommand } from '../../../lib/command/api-command.js'
810
import type {
911
CustomCommonOutputProducer,
1012
formatAndWriteItem,
1113
formatAndWriteItemBuilder,
1214
} from '../../../lib/command/format.js'
13-
import type { CommandArgs } from '../../../commands/devices/preferences.js'
1415
import type { BuildOutputFormatterFlags } from '../.././../lib/command/output-builder.js'
1516
import type { SmartThingsCommandFlags } from '../../../lib/command/smartthings-command.js'
1617
import type { ChooseFunction } from '../../../lib/command/util/util-util.js'
@@ -25,6 +26,11 @@ import {
2526
} from '../../test-lib/table-mock.js'
2627

2728

29+
const buildEpilogMock = jest.fn<typeof buildEpilog>()
30+
jest.unstable_mockModule('../../../lib/help.js', () => ({
31+
buildEpilog: buildEpilogMock,
32+
}))
33+
2834
const { apiCommandMock, apiCommandBuilderMock } = apiCommandMocks('../../..')
2935

3036
const chooseDeviceMock = jest.fn<ChooseFunction<Device>>()
@@ -49,6 +55,7 @@ test('builder', () => {
4955
yargsMock: apiCommandBuilderArgvMock,
5056
positionalMock,
5157
exampleMock,
58+
epilogMock,
5259
argvMock,
5360
} = buildArgvMock<SmartThingsCommandFlags, BuildOutputFormatterFlags>()
5461

@@ -63,6 +70,8 @@ test('builder', () => {
6370
expect(formatAndWriteItemBuilderMock).toHaveBeenCalledExactlyOnceWith(apiCommandBuilderArgvMock)
6471
expect(positionalMock).toHaveBeenCalledOnce()
6572
expect(exampleMock).toHaveBeenCalledOnce()
73+
expect(buildEpilogMock).toHaveBeenCalledOnce()
74+
expect(epilogMock).toHaveBeenCalledOnce()
6675
})
6776

6877
const preferences: DevicePreferenceResponse = {

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@ import { jest } from '@jest/globals'
33
import type { ArgumentsCamelCase, Argv } from 'yargs'
44

55
import type { CommandArgs } from '../../../../commands/edge/channels/invites.js'
6+
import type { buildEpilog } from '../../../../lib/help.js'
67
import type { APICommand, APICommandFlags } from '../../../../lib/command/api-command.js'
7-
import { outputItemOrList, outputItemOrListBuilder } from '../../../../lib/command/listing-io.js'
8+
import type { edgeCommand, EdgeCommand } from '../../../../lib/command/edge-command.js'
9+
import type { outputItemOrList, outputItemOrListBuilder } from '../../../../lib/command/listing-io.js'
810
import { listTableFieldDefinitions, tableFieldDefinitions } from '../../../../lib/command/util/edge-invites-table.js'
11+
import type { buildListFunction } from '../../../../lib/command/util/edge-invites-util.js'
12+
import type { Invitation, InvitesEndpoint } from '../../../../lib/edge/endpoints/invites.js'
913
import { apiCommandMocks } from '../../../test-lib/api-command-mock.js'
1014
import { buildArgvMock, buildArgvMockStub } from '../../../test-lib/builder-mock.js'
11-
import { Invitation, InvitesEndpoint } from '../../../../lib/edge/endpoints/invites.js'
12-
import type { edgeCommand, EdgeCommand } from '../../../../lib/command/edge-command.js'
13-
import { buildListFunction } from '../../../../lib/command/util/edge-invites-util.js'
1415

1516

17+
const buildEpilogMock = jest.fn<typeof buildEpilog>()
18+
jest.unstable_mockModule('../../../../lib/help.js', () => ({
19+
buildEpilog: buildEpilogMock,
20+
}))
21+
1622
const { apiCommandMock, apiCommandBuilderMock } = apiCommandMocks('../../../..')
1723

1824
const edgeCommandMock = jest.fn<typeof edgeCommand>()
@@ -43,6 +49,7 @@ test('builder', async () => {
4349
positionalMock,
4450
optionMock,
4551
exampleMock,
52+
epilogMock,
4653
argvMock,
4754
} = buildArgvMock<APICommandFlags, CommandArgs>()
4855

@@ -58,6 +65,8 @@ test('builder', async () => {
5865
expect(positionalMock).toHaveBeenCalledTimes(1)
5966
expect(optionMock).toHaveBeenCalledTimes(1)
6067
expect(exampleMock).toHaveBeenCalledTimes(1)
68+
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
69+
expect(epilogMock).toHaveBeenCalledTimes(1)
6170
})
6271

6372
test('handler', async () => {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ import {
2828
type listDrivers,
2929
listTableFieldDefinitions,
3030
} from '../../../lib/command/util/edge-drivers.js'
31-
import { apiCommandMocks } from '../../test-lib/api-command-mock.js'
31+
import type { buildEpilog } from '../../../lib/help.js'
3232
import { buildArgvMock, buildArgvMockStub } from '../../test-lib/builder-mock.js'
3333
import { tableGeneratorMock } from '../../test-lib/table-mock.js'
3434

3535

36-
const { apiDocsURLMock } = apiCommandMocks('../../..')
36+
const buildEpilogMock = jest.fn<typeof buildEpilog>()
37+
jest.unstable_mockModule('../../../lib/help.js', () => ({ buildEpilog: buildEpilogMock }))
38+
39+
40+
// buildEpilog is mocked; api-command mocks not required for this test post-migration
3741

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

103107
expect(positionalMock).toHaveBeenCalledTimes(2)
104108
expect(exampleMock).toHaveBeenCalledTimes(1)
105-
expect(apiDocsURLMock).toHaveBeenCalledTimes(1)
109+
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
106110
expect(epilogMock).toHaveBeenCalledTimes(1)
107111
})
108112

src/__tests__/commands/locations/create.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ import { ArgumentsCamelCase, Argv } from 'yargs'
44

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

7+
import type { CommandArgs } from '../../../commands/locations/create.js'
8+
import type { buildEpilog } from '../../../lib/help.js'
79
import { tableFieldDefinitions } from '../../../lib/command/util/locations-util.js'
8-
import { APICommand, APICommandFlags } from '../../../lib/command/api-command.js'
9-
import { inputAndOutputItem, inputAndOutputItemBuilder } from '../../../lib/command/input-and-output-item.js'
10-
import { CommandArgs } from '../../../commands/locations/create.js'
10+
import type { APICommand, APICommandFlags } from '../../../lib/command/api-command.js'
11+
import type { inputAndOutputItem, inputAndOutputItemBuilder } from '../../../lib/command/input-and-output-item.js'
1112
import { apiCommandMocks } from '../../test-lib/api-command-mock.js'
1213
import { buildArgvMock, buildArgvMockStub } from '../../test-lib/builder-mock.js'
1314

1415

15-
const { apiCommandMock, apiCommandBuilderMock, apiDocsURLMock } = apiCommandMocks('../../..')
16+
const buildEpilogMock = jest.fn<typeof buildEpilog>()
17+
jest.unstable_mockModule('../../../lib/help.js', () => ({
18+
buildEpilog: buildEpilogMock,
19+
}))
20+
21+
const { apiCommandMock, apiCommandBuilderMock } = apiCommandMocks('../../..')
1622

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

4854
expect(exampleMock).toHaveBeenCalledTimes(1)
49-
expect(apiDocsURLMock).toHaveBeenCalledTimes(1)
55+
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
5056
expect(epilogMock).toHaveBeenCalledTimes(1)
5157
})
5258

src/__tests__/commands/locations/delete.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ import type { ArgumentsCamelCase, Argv } from 'yargs'
55
import type { LocationsEndpoint, SmartThingsClient } from '@smartthings/core-sdk'
66

77
import type { CommandArgs } from '../../../commands/locations/delete.js'
8+
import type { buildEpilog } from '../../../lib/help.js'
89
import type { APICommand, APICommandFlags } from '../../../lib/command/api-command.js'
910
import type { chooseLocation } from '../../../lib/command/util/locations-util.js'
1011
import { apiCommandMocks } from '../../test-lib/api-command-mock.js'
1112
import { buildArgvMock } from '../../test-lib/builder-mock.js'
1213

1314

14-
const { apiCommandMock, apiCommandBuilderMock, apiDocsURLMock } = apiCommandMocks('../../..')
15+
const buildEpilogMock = jest.fn<typeof buildEpilog>()
16+
jest.unstable_mockModule('../../../lib/help.js', () => ({
17+
buildEpilog: buildEpilogMock,
18+
}))
19+
20+
const { apiCommandMock, apiCommandBuilderMock } = apiCommandMocks('../../..')
1521

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

4450
expect(positionalMock).toHaveBeenCalledTimes(1)
4551
expect(exampleMock).toHaveBeenCalledTimes(1)
46-
expect(apiDocsURLMock).toHaveBeenCalledTimes(1)
52+
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
4753
expect(epilogMock).toHaveBeenCalledTimes(1)
4854
})
4955

src/__tests__/commands/locations/history.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { DeviceActivity, HistoryEndpoint, PaginatedList } from '@smartthing
66

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

2728

29+
const buildEpilogMock = jest.fn<typeof buildEpilog>()
30+
jest.unstable_mockModule('../../../lib/help.js', () => ({
31+
buildEpilog: buildEpilogMock,
32+
}))
33+
2834
const { apiCommandBuilderMock, apiCommandMock } = apiCommandMocks('../../..')
2935

3036
const calculateOutputFormatMock = jest.fn<typeof calculateOutputFormat>()
@@ -76,6 +82,7 @@ test('builder', () => {
7682
yargsMock: buildOutputFormatterBuilderArgvMock,
7783
positionalMock,
7884
exampleMock,
85+
epilogMock,
7986
argvMock,
8087
} = buildArgvMock<APICommandFlags & BuildOutputFormatterFlags, CommandArgs>()
8188

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

96103
expect(positionalMock).toHaveBeenCalledTimes(1)
97104
expect(exampleMock).toHaveBeenCalledTimes(1)
105+
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
106+
expect(epilogMock).toHaveBeenCalledTimes(1)
98107
})
99108

100109
describe('handler', () => {

src/__tests__/commands/locations/rooms.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,28 @@ import type { ArgumentsCamelCase, Argv } from 'yargs'
55
import type { Room, RoomsEndpoint } from '@smartthings/core-sdk'
66

77
import type { CommandArgs } from '../../../commands/locations/rooms.js'
8+
import type { WithNamedLocation } from '../../../lib/api-helpers.js'
9+
import type { buildEpilog } from '../../../lib/help.js'
810
import { fatalError } from '../../../lib/util.js'
911
import type { APICommand, APICommandFlags } from '../../../lib/command/api-command.js'
10-
import type { WithNamedLocation } from '../../../lib/api-helpers.js'
1112
import type { outputItemOrList, outputItemOrListBuilder } from '../../../lib/command/listing-io.js'
1213
import { tableFieldDefinitions, tableFieldDefinitionsWithLocationName } from '../../../lib/command/util/rooms-table.js'
1314
import type { getRoomsWithLocation } from '../../../lib/command/util/rooms-util.js'
1415
import { apiCommandMocks } from '../../test-lib/api-command-mock.js'
1516
import { buildArgvMock, buildArgvMockStub } from '../../test-lib/builder-mock.js'
1617

1718

19+
const buildEpilogMock = jest.fn<typeof buildEpilog>()
20+
jest.unstable_mockModule('../../../lib/help.js', () => ({
21+
buildEpilog: buildEpilogMock,
22+
}))
23+
1824
const fatalErrorMock = jest.fn<typeof fatalError>()
1925
jest.unstable_mockModule('../../../lib/util.js', () => ({
2026
fatalError: fatalErrorMock,
2127
}))
2228

23-
const { apiCommandMock, apiCommandBuilderMock, apiDocsURLMock } = apiCommandMocks('../../..')
29+
const { apiCommandMock, apiCommandBuilderMock } = apiCommandMocks('../../..')
2430

2531
const outputItemOrListMock = jest.fn<typeof outputItemOrList<Room & WithNamedLocation>>()
2632
const outputItemOrListBuilderMock = jest.fn<typeof outputItemOrListBuilder>()
@@ -61,7 +67,7 @@ test('builder', async () => {
6167
expect(positionalMock).toHaveBeenCalledTimes(1)
6268
expect(optionMock).toHaveBeenCalledTimes(2)
6369
expect(exampleMock).toHaveBeenCalledTimes(1)
64-
expect(apiDocsURLMock).toHaveBeenCalledTimes(1)
70+
expect(buildEpilogMock).toHaveBeenCalledTimes(1)
6571
expect(epilogMock).toHaveBeenCalledTimes(1)
6672
})
6773

0 commit comments

Comments
 (0)