@@ -15,6 +15,18 @@ import {
15
15
import { CLIError } from '@oclif/core/lib/errors'
16
16
import stripAnsi from '../../helpers/strip-ansi'
17
17
import heredoc from 'tsheredoc'
18
+ import { ux } from '@oclif/core'
19
+ import * as sinon from 'sinon'
20
+
21
+ const stdOutputMockStart = ( ) => {
22
+ stderr . start ( )
23
+ stdout . start ( )
24
+ }
25
+
26
+ const stdOutputMockStop = ( ) => {
27
+ stderr . stop ( )
28
+ stdout . stop ( )
29
+ }
18
30
19
31
describe ( 'datacloud:disconnect' , function ( ) {
20
32
let api : nock . Scope
@@ -46,10 +58,13 @@ describe('datacloud:disconnect', function () {
46
58
api . done ( )
47
59
applinkApi . done ( )
48
60
nock . cleanAll ( )
61
+ sinon . restore ( )
49
62
} )
50
63
51
64
it ( 'shows the expected output after failing' , async function ( ) {
52
65
applinkApi
66
+ . get ( '/addons/01234567-89ab-cdef-0123-456789abcdef/connections/datacloud/myorg/data_action_targets' )
67
+ . reply ( 200 , [ ] )
53
68
. delete ( '/addons/01234567-89ab-cdef-0123-456789abcdef/connections/myorg' )
54
69
. reply ( 202 , connection5_disconnection_failed )
55
70
@@ -68,6 +83,8 @@ describe('datacloud:disconnect', function () {
68
83
69
84
it ( 'waits for DELETE /connections/orgName status to return "disconnecting" before ending the action successfully' , async function ( ) {
70
85
applinkApi
86
+ . get ( '/addons/01234567-89ab-cdef-0123-456789abcdef/connections/datacloud/myorg/data_action_targets' )
87
+ . reply ( 200 , [ ] )
71
88
. delete ( '/addons/01234567-89ab-cdef-0123-456789abcdef/connections/myorg' )
72
89
. reply ( 202 , connection5_disconnecting )
73
90
@@ -83,6 +100,8 @@ describe('datacloud:disconnect', function () {
83
100
84
101
it ( 'connection not found' , async function ( ) {
85
102
applinkApi
103
+ . get ( '/addons/01234567-89ab-cdef-0123-456789abcdef/connections/datacloud/myorg/data_action_targets' )
104
+ . reply ( 200 , [ ] )
86
105
. delete ( '/addons/01234567-89ab-cdef-0123-456789abcdef/connections/myorg' )
87
106
. replyWithError ( ConnectionError_record_not_found )
88
107
@@ -102,6 +121,9 @@ describe('datacloud:disconnect', function () {
102
121
} )
103
122
104
123
it ( 'errors when the wrong org name is passed to the confirm flag' , async function ( ) {
124
+ applinkApi
125
+ . get ( '/addons/01234567-89ab-cdef-0123-456789abcdef/connections/datacloud/myorg/data_action_targets' )
126
+ . reply ( 200 , [ ] )
105
127
try {
106
128
await runCommand ( Cmd , [
107
129
'myorg' ,
@@ -114,5 +136,58 @@ describe('datacloud:disconnect', function () {
114
136
expect ( oclif . exit ) . to . equal ( 1 )
115
137
}
116
138
} )
139
+
140
+ it ( 'prompts with DAT table when data action targets exist (no indent)' , async function ( ) {
141
+ applinkApi
142
+ . get ( '/addons/01234567-89ab-cdef-0123-456789abcdef/connections/datacloud/myorg/data_action_targets' )
143
+ . reply ( 200 , [
144
+ {
145
+ label : 'Target One' ,
146
+ api_name : 'TargetOne' ,
147
+ } ,
148
+ {
149
+ label : 'Target Two' ,
150
+ api_name : 'TargetTwo' ,
151
+ } ,
152
+ ] )
153
+ . delete ( '/addons/01234567-89ab-cdef-0123-456789abcdef/connections/myorg' )
154
+ . reply ( 202 , connection5_disconnecting )
155
+
156
+ sinon . stub ( ux , 'prompt' ) . resolves ( 'myorg' )
157
+ stdOutputMockStart ( )
158
+ await runCommand ( Cmd , [
159
+ 'myorg' ,
160
+ '--app=my-app' ,
161
+ ] )
162
+ stdOutputMockStop ( )
163
+
164
+ expect ( stderr . output ) . to . contain ( 'Destructive action' )
165
+ expect ( stderr . output ) . to . contain ( 'Data Action Target Name' )
166
+ expect ( stderr . output ) . to . contain ( 'Target One' )
167
+ expect ( stderr . output ) . to . contain ( 'Target Two' )
168
+ } )
169
+
170
+ it ( 'prompts without DAT table when no data action targets exist' , async function ( ) {
171
+ applinkApi
172
+ . delete ( '/addons/01234567-89ab-cdef-0123-456789abcdef/connections/myorg' )
173
+ . reply ( 202 , connection5_disconnecting )
174
+ . get ( '/addons/01234567-89ab-cdef-0123-456789abcdef/connections/datacloud/myorg/data_action_targets' )
175
+ . reply ( 200 , [ ] )
176
+
177
+ sinon . stub ( ux , 'prompt' ) . resolves ( 'myorg' )
178
+ stdOutputMockStart ( )
179
+ await runCommand ( Cmd , [
180
+ 'myorg' ,
181
+ '--app=my-app' ,
182
+ ] )
183
+ stdOutputMockStop ( )
184
+
185
+ console . log ( stderr . output )
186
+
187
+ expect ( stderr . output ) . to . contain ( 'Destructive action' )
188
+ expect ( stderr . output ) . to . contain ( 'This command disconnects the org myorg' )
189
+ expect ( stderr . output ) . to . not . contain ( 'data action targets' )
190
+ expect ( stderr . output ) . to . not . contain ( 'Data Action Target Name' )
191
+ } )
117
192
} )
118
193
} )
0 commit comments