@@ -14,6 +14,7 @@ import type {
1414} from '../../../lib/command/api-organization-command.js'
1515import type { ChooseFunction } from '../../../lib/command/util/util-util.js'
1616import type { chooseSmartAppFn } from '../../../lib/command/util/smartapps-choose.js'
17+ import type { paidPlanRequiredHandler } from '../../../lib/command/util/smartapps-util.js'
1718import { buildArgvMock } from '../../test-lib/builder-mock.js'
1819
1920
@@ -35,6 +36,12 @@ jest.unstable_mockModule('../../../lib/command/util/smartapps-choose.js', () =>
3536 chooseSmartAppFn : chooseSmartAppFnMock ,
3637} ) )
3738
39+ const paidPlanRequiredHandlerMock = jest . fn < typeof paidPlanRequiredHandler > ( )
40+ . mockImplementation ( ( ) => { throw Error ( 'should exit' ) } )
41+ jest . unstable_mockModule ( '../../../lib/command/util/smartapps-util.js' , ( ) => ( {
42+ paidPlanRequiredHandler : paidPlanRequiredHandlerMock ,
43+ } ) )
44+
3845const consoleLogSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { /*no-op*/ } )
3946
4047
@@ -63,7 +70,7 @@ test('builder', () => {
6370 expect ( epilogMock ) . toHaveBeenCalledTimes ( 1 )
6471} )
6572
66- test ( 'handler' , async ( ) => {
73+ describe ( 'handler' , ( ) => {
6774 const apiAppsRegisterMock = jest . fn < typeof SmartAppsEndpoint . prototype . register > ( )
6875 const command = {
6976 client : {
@@ -72,19 +79,37 @@ test('handler', async () => {
7279 config : { headers : { 'X-ST-Organization' : 'organization-id' } } ,
7380 } ,
7481 } as unknown as APIOrganizationCommand < ArgumentsCamelCase < CommandArgs > >
75- apiOrganizationCommandMock . mockResolvedValueOnce ( command )
76- chooseSmartAppMock . mockResolvedValueOnce ( 'chosen-id' )
7782 const inputArgv = {
7883 profile : 'default' ,
7984 id : 'id-from-cmd-line' ,
8085 } as ArgumentsCamelCase < CommandArgs >
8186
82- await expect ( cmd . handler ( inputArgv ) ) . resolves . not . toThrow ( )
87+ beforeEach ( ( ) => {
88+ apiOrganizationCommandMock . mockResolvedValueOnce ( command )
89+ chooseSmartAppMock . mockResolvedValueOnce ( 'chosen-id' )
90+ } )
91+
92+ it ( 'sends confirmation request' , async ( ) => {
93+ apiAppsRegisterMock . mockResolvedValueOnce ( )
94+
95+ await expect ( cmd . handler ( inputArgv ) ) . resolves . not . toThrow ( )
96+
97+ expect ( apiOrganizationCommandMock ) . toHaveBeenCalledExactlyOnceWith ( inputArgv )
98+ expect ( chooseSmartAppFnMock )
99+ . toHaveBeenCalledExactlyOnceWith ( { appType : 'API_ONLY' , accountId : 'organization-id' } )
100+ expect ( chooseSmartAppMock ) . toHaveBeenCalledExactlyOnceWith ( command , 'id-from-cmd-line' )
101+ expect ( apiAppsRegisterMock ) . toHaveBeenCalledExactlyOnceWith ( 'chosen-id' )
102+ expect ( paidPlanRequiredHandlerMock ) . not . toHaveBeenCalled ( )
103+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Confirmation request sent' ) )
104+ } )
105+
106+ it ( 'uses paid plan required handler for errors confirming app' , async ( ) => {
107+ const error = { response : { status : 403 } }
108+ apiAppsRegisterMock . mockRejectedValueOnce ( error )
109+
110+ await expect ( cmd . handler ( inputArgv ) ) . rejects . toThrow ( 'should exit' )
83111
84- expect ( apiOrganizationCommandMock ) . toHaveBeenCalledExactlyOnceWith ( inputArgv )
85- expect ( chooseSmartAppFnMock )
86- . toHaveBeenCalledExactlyOnceWith ( { appType : 'API_ONLY' , accountId : 'organization-id' } )
87- expect ( chooseSmartAppMock ) . toHaveBeenCalledExactlyOnceWith ( command , 'id-from-cmd-line' )
88- expect ( apiAppsRegisterMock ) . toHaveBeenCalledExactlyOnceWith ( 'chosen-id' )
89- expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Confirmation request sent' ) )
112+ expect ( paidPlanRequiredHandlerMock ) . toHaveBeenCalledExactlyOnceWith ( error )
113+ expect ( consoleLogSpy ) . not . toHaveBeenCalled ( )
114+ } )
90115} )
0 commit comments