@@ -88,6 +88,83 @@ func TestItDoesNotClosePRsIfNotConfirmed(t *testing.T) {
88
88
fakeGitHub .AssertCalledWith (t , [][]string {})
89
89
}
90
90
91
+ func TestItLogsUpdateDescriptionErrorsButContinuesToTryAll (t * testing.T ) {
92
+ fakeGitHub := github .NewAlwaysFailsFakeGitHub ()
93
+ gh = fakeGitHub
94
+
95
+ testsupport .PrepareTempCampaign (true , "org/repo1" , "org/repo2" )
96
+
97
+ out , err := runUpdateDescriptionCommandAuto ("README.md" )
98
+ assert .NoError (t , err )
99
+ assert .Contains (t , out , "Updating PR description in org/repo1" )
100
+ assert .Contains (t , out , "Updating PR description in org/repo2" )
101
+ assert .Contains (t , out , "turbolift update-prs completed with errors" )
102
+ assert .Contains (t , out , "2 errored" )
103
+
104
+ fakeGitHub .AssertCalledWith (t , [][]string {
105
+ {"work/org/repo1" , "PR title" , "PR body" },
106
+ {"work/org/repo2" , "PR title" , "PR body" },
107
+ })
108
+ }
109
+
110
+ func TestItUpdatesDescriptionsSuccessfully (t * testing.T ) {
111
+ fakeGitHub := github .NewAlwaysSucceedsFakeGitHub ()
112
+ gh = fakeGitHub
113
+
114
+ testsupport .PrepareTempCampaign (true , "org/repo1" , "org/repo2" )
115
+ testsupport .CreateOrUpdatePrDescriptionFile ("README.md" , "Updated PR title" , "Updated PR body" )
116
+
117
+ out , err := runUpdateDescriptionCommandAuto ("README.md" )
118
+ assert .NoError (t , err )
119
+ assert .Contains (t , out , "Updating PR description in org/repo1" )
120
+ assert .Contains (t , out , "Updating PR description in org/repo2" )
121
+ assert .Contains (t , out , "turbolift update-prs completed" )
122
+ assert .Contains (t , out , "2 OK, 0 skipped" )
123
+
124
+ fakeGitHub .AssertCalledWith (t , [][]string {
125
+ {"work/org/repo1" , "Updated PR title" , "Updated PR body" },
126
+ {"work/org/repo2" , "Updated PR title" , "Updated PR body" },
127
+ })
128
+ }
129
+
130
+ func TestItUpdatesDescriptionsFromAlternativeFile (t * testing.T ) {
131
+ fakeGitHub := github .NewAlwaysSucceedsFakeGitHub ()
132
+ gh = fakeGitHub
133
+
134
+ testsupport .PrepareTempCampaign (true , "org/repo1" , "org/repo2" )
135
+ testsupport .CreateOrUpdatePrDescriptionFile ("custom.md" , "custom PR title" , "custom PR body" )
136
+
137
+ out , err := runUpdateDescriptionCommandAuto ("custom.md" )
138
+ assert .NoError (t , err )
139
+ assert .Contains (t , out , "Updating PR description in org/repo1" )
140
+ assert .Contains (t , out , "Updating PR description in org/repo2" )
141
+ assert .Contains (t , out , "turbolift update-prs completed" )
142
+ assert .Contains (t , out , "2 OK, 0 skipped" )
143
+
144
+ fakeGitHub .AssertCalledWith (t , [][]string {
145
+ {"work/org/repo1" , "custom PR title" , "custom PR body" },
146
+ {"work/org/repo2" , "custom PR title" , "custom PR body" },
147
+ })
148
+ }
149
+
150
+ func TestItDoesNotUpdateDescriptionsIfNotConfirmed (t * testing.T ) {
151
+ fakeGitHub := github .NewAlwaysSucceedsFakeGitHub ()
152
+ gh = fakeGitHub
153
+ fakePrompt := prompt .NewFakePromptNo ()
154
+ p = fakePrompt
155
+
156
+ testsupport .PrepareTempCampaign (true , "org/repo1" , "org/repo2" )
157
+
158
+ out , err := runUpdateDescriptionCommandConfirm ()
159
+ assert .NoError (t , err )
160
+ assert .NotContains (t , out , "Updating PR description in org/repo1" )
161
+ assert .NotContains (t , out , "Updating PR description in org/repo2" )
162
+ assert .NotContains (t , out , "turbolift update-prs completed" )
163
+ assert .NotContains (t , out , "2 OK" )
164
+
165
+ fakeGitHub .AssertCalledWith (t , [][]string {})
166
+ }
167
+
91
168
func runCloseCommandAuto () (string , error ) {
92
169
cmd := NewUpdatePRsCmd ()
93
170
closeFlag = true
@@ -113,3 +190,30 @@ func runCloseCommandConfirm() (string, error) {
113
190
}
114
191
return outBuffer .String (), nil
115
192
}
193
+
194
+ func runUpdateDescriptionCommandAuto (descriptionFile string ) (string , error ) {
195
+ cmd := NewUpdatePRsCmd ()
196
+ updateDescriptionFlag = true
197
+ yesFlag = true
198
+ prDescriptionFile = descriptionFile
199
+ outBuffer := bytes .NewBufferString ("" )
200
+ cmd .SetOut (outBuffer )
201
+ err := cmd .Execute ()
202
+ if err != nil {
203
+ return outBuffer .String (), err
204
+ }
205
+ return outBuffer .String (), nil
206
+ }
207
+
208
+ func runUpdateDescriptionCommandConfirm () (string , error ) {
209
+ cmd := NewUpdatePRsCmd ()
210
+ updateDescriptionFlag = true
211
+ yesFlag = false
212
+ outBuffer := bytes .NewBufferString ("" )
213
+ cmd .SetOut (outBuffer )
214
+ err := cmd .Execute ()
215
+ if err != nil {
216
+ return outBuffer .String (), err
217
+ }
218
+ return outBuffer .String (), nil
219
+ }
0 commit comments