@@ -217,31 +217,77 @@ def get_milestone(milestone_name:)
217
217
allow ( Octokit ::Client ) . to receive ( :new ) . and_return ( client )
218
218
end
219
219
220
- it 'has the correct dates to code freeze without submission' do
221
- comment = "Code freeze: October 22, 2022\n App Store submission: November 15, 2022\n Release: October 25, 2022\n "
222
- options = { due_on : '2022-10-22T12:00:00Z' , description : comment }
220
+ it 'computes the correct dates for standard period' do
221
+ due_date = '2022-10-20T08:00:00Z' . to_time . utc
222
+ options = {
223
+ due_on : '2022-10-20T12:00:00Z' ,
224
+ description : "Code freeze: October 20, 2022\n App Store submission: October 24, 2022\n Release: October 27, 2022\n "
225
+ }
223
226
224
227
expect ( client ) . to receive ( :create_milestone ) . with ( test_repo , test_milestone_number , options )
225
- create_milestone ( need_submission : false , milestone_duration : 24 , days_code_freeze : 3 )
228
+ create_milestone ( due_date : due_date , days_until_submission : 4 , days_until_release : 7 )
226
229
end
227
230
228
- it 'has the correct dates to code freeze with submission' do
229
- comment = "Code freeze: October 22, 2022\n App Store submission: October 22, 2022\n Release: October 25, 2022\n "
230
- options = { due_on : '2022-10-22T12:00:00Z' , description : comment }
231
+ it 'computes the correct dates when the due date is on the verge of a DST day change' do
232
+ # The PST to PDT (DST) change is made on the second Sunday in March and finishes on the first Sunday in November
233
+ Time . zone = 'Pacific Time (US & Canada)'
234
+ due_date = '2022-06-18T23:00:00Z' . to_time
235
+ options = {
236
+ due_on : '2022-06-19T12:00:00Z' ,
237
+ description : "Code freeze: June 19, 2022\n App Store submission: June 21, 2022\n Release: June 22, 2022\n "
238
+ }
231
239
232
240
expect ( client ) . to receive ( :create_milestone ) . with ( test_repo , test_milestone_number , options )
233
- create_milestone ( need_submission : true , milestone_duration : 19 , days_code_freeze : 3 )
241
+ create_milestone ( due_date : due_date , days_until_submission : 2 , days_until_release : 3 )
234
242
end
235
243
236
- def create_milestone ( need_submission :, milestone_duration :, days_code_freeze :)
237
- days_until_submission = need_submission ? ( days_code_freeze - 3 ) : milestone_duration
244
+ it 'computes the correct dates when the due date is on DST but has no day change' do
245
+ # The PST to PDT (DST) change is made on the second Sunday in March and finishes on the first Sunday in November
246
+ Time . zone = 'Pacific Time (US & Canada)'
247
+ due_date = '2022-06-18T22:00:00Z' . to_time
248
+ options = {
249
+ due_on : '2022-06-18T12:00:00Z' ,
250
+ description : "Code freeze: June 18, 2022\n App Store submission: June 20, 2022\n Release: June 21, 2022\n "
251
+ }
252
+
253
+ expect ( client ) . to receive ( :create_milestone ) . with ( test_repo , test_milestone_number , options )
254
+ create_milestone ( due_date : due_date , days_until_submission : 2 , days_until_release : 3 )
255
+ end
256
+
257
+ context 'with input validation' do
258
+ it 'raises an error if days_until_submission is less than or equal zero' do
259
+ due_date = '2022-10-20T08:00:00Z' . to_time . utc
260
+ expect { create_milestone ( due_date : due_date , days_until_submission : 0 , days_until_release : 5 ) }
261
+ . to raise_error ( FastlaneCore ::Interface ::FastlaneError , 'days_until_submission must be greater than zero.' )
262
+ end
263
+
264
+ it 'raises an error if days_until_release is less than or equal zero' do
265
+ due_date = '2022-10-20T08:00:00Z' . to_time . utc
266
+ expect { create_milestone ( due_date : due_date , days_until_submission : 12 , days_until_release : -8 ) }
267
+ . to raise_error ( FastlaneCore ::Interface ::FastlaneError , 'days_until_release must be greater than zero.' )
268
+ end
269
+
270
+ it 'raises an error if submission date is after the release date' do
271
+ due_date = '2022-10-20T08:00:00Z' . to_time . utc
272
+ expect { create_milestone ( due_date : due_date , days_until_submission : 14 , days_until_release : 3 ) }
273
+ . to raise_error ( FastlaneCore ::Interface ::FastlaneError , 'days_until_release must be greather than days_until_submission' )
274
+ end
275
+
276
+ it 'raises an error if submission date is equal to release date' do
277
+ due_date = '2022-10-20T08:00:00Z' . to_time . utc
278
+ expect { create_milestone ( due_date : due_date , days_until_submission : 1 , days_until_release : 1 ) }
279
+ . to raise_error ( FastlaneCore ::Interface ::FastlaneError , 'days_until_release must be greather than days_until_submission' )
280
+ end
281
+ end
282
+
283
+ def create_milestone ( due_date :, days_until_submission :, days_until_release :)
238
284
helper = described_class . new ( github_token : 'Fake-GitHubToken-123' )
239
285
helper . create_milestone (
240
286
repository : test_repo ,
241
287
title : test_milestone_number ,
242
- due_date : test_milestone_duedate . to_time . utc ,
288
+ due_date : due_date ,
243
289
days_until_submission : days_until_submission ,
244
- days_until_release : days_code_freeze
290
+ days_until_release : days_until_release
245
291
)
246
292
end
247
293
end
0 commit comments