Skip to content

Commit b218ccc

Browse files
committed
GithubHelper: Fix Timezone changes unit tests
1 parent 0750081 commit b218ccc

File tree

2 files changed

+49
-44
lines changed

2 files changed

+49
-44
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ def get_last_milestone(repository)
8080
# @param [Integer] days_until_release Number of days from code freeze to release
8181
#
8282
def create_milestone(repository:, title:, due_date:, days_until_submission:, days_until_release:)
83-
UI.user_error!('days_until_release must be greater than zero.') if days_until_release <= 0
84-
UI.user_error!('days_until_submission must be greater than zero.') if days_until_submission <= 0
85-
UI.user_error!('days_until_release must be greather than days_until_submission') if days_until_submission >= days_until_release
83+
UI.user_error!('days_until_release must be greater than zero.') unless days_until_release > 0
84+
UI.user_error!('days_until_submission must be greater than zero.') unless days_until_submission > 0
85+
UI.user_error!('days_until_release must be greater or equal to days_until_submission.') unless days_until_release >= days_until_submission
8686

8787
submission_date = due_date.to_datetime.next_day(days_until_submission)
8888
release_date = due_date.to_datetime.next_day(days_until_release)

spec/github_helper_spec.rb

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -218,66 +218,71 @@ def get_milestone(milestone_name:)
218218
end
219219

220220
it 'computes the correct dates for standard period' do
221-
due_date = '2022-10-20T08:00:00Z'.to_time.utc
221+
due_date = '2022-12-02T08:00:00Z'.to_time.utc
222222
options = {
223-
due_on: '2022-10-20T12:00:00Z',
224-
description: "Code freeze: October 20, 2022\nApp Store submission: October 24, 2022\nRelease: October 27, 2022\n"
223+
due_on: '2022-12-02T12:00:00Z',
224+
description: "Code freeze: December 02, 2022\nApp Store submission: December 06, 2022\nRelease: December 09, 2022\n"
225225
}
226226

227227
expect(client).to receive(:create_milestone).with(test_repo, test_milestone_number, options)
228228
create_milestone(due_date: due_date, days_until_submission: 4, days_until_release: 7)
229229
end
230230

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
231+
it 'computes the correct dates when submission and release dates are in the same day' do
232+
due_date = '2022-12-02T08:00:00Z'.to_time.utc
235233
options = {
236-
due_on: '2022-06-19T12:00:00Z',
237-
description: "Code freeze: June 19, 2022\nApp Store submission: June 21, 2022\nRelease: June 22, 2022\n"
234+
due_on: '2022-12-02T12:00:00Z',
235+
description: "Code freeze: December 02, 2022\nApp Store submission: December 03, 2022\nRelease: December 03, 2022\n"
238236
}
239237

240238
expect(client).to receive(:create_milestone).with(test_repo, test_milestone_number, options)
241-
create_milestone(due_date: due_date, days_until_submission: 2, days_until_release: 3)
239+
create_milestone(due_date: due_date, days_until_submission: 1, days_until_release: 1)
242240
end
243241

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\nApp Store submission: June 20, 2022\nRelease: 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)
242+
it 'computes the correct dates when the due date is on the verge of a DST day change' do
243+
# DST starts on the last Sunday of March and ends on the last Sunday of October
244+
Time.use_zone('Europe/London') do
245+
due_date = Time.zone.parse('2022-03-27 23:00:00Z')
246+
options = {
247+
due_on: '2022-03-28T12:00:00Z',
248+
description: "Code freeze: March 28, 2022\nApp Store submission: March 30, 2022\nRelease: March 31, 2022\n"
249+
}
250+
251+
expect(client).to receive(:create_milestone).with(test_repo, test_milestone_number, options)
252+
create_milestone(due_date: due_date, days_until_submission: 2, days_until_release: 3)
253+
end
255254
end
256255

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.')
256+
it 'computes the correct dates when the due date is on DST but has no day change' do
257+
# DST starts on the last Sunday of March and ends on the last Sunday of October
258+
Time.use_zone('Europe/London') do
259+
due_date = Time.zone.parse('2022-03-26 23:00:00Z')
260+
options = {
261+
due_on: '2022-03-26T12:00:00Z',
262+
description: "Code freeze: March 26, 2022\nApp Store submission: March 28, 2022\nRelease: March 29, 2022\n"
263+
}
264+
265+
expect(client).to receive(:create_milestone).with(test_repo, test_milestone_number, options)
266+
create_milestone(due_date: due_date, days_until_submission: 2, days_until_release: 3)
262267
end
268+
end
263269

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
270+
it 'raises an error if days_until_submission is less than or equal zero' do
271+
due_date = '2022-10-20T08:00:00Z'.to_time.utc
272+
expect { create_milestone(due_date: due_date, days_until_submission: 0, days_until_release: 5) }
273+
.to raise_error(FastlaneCore::Interface::FastlaneError, 'days_until_submission must be greater than zero.')
274+
end
269275

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
276+
it 'raises an error if days_until_release is less than or equal zero' do
277+
due_date = '2022-10-20T08:00:00Z'.to_time.utc
278+
expect { create_milestone(due_date: due_date, days_until_submission: 12, days_until_release: -8) }
279+
.to raise_error(FastlaneCore::Interface::FastlaneError, 'days_until_release must be greater than zero.')
280+
end
275281

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
282+
it 'raises an error if days_until_submission is greater than days_until_release' do
283+
due_date = '2022-10-20T08:00:00Z'.to_time.utc
284+
expect { create_milestone(due_date: due_date, days_until_submission: 14, days_until_release: 3) }
285+
.to raise_error(FastlaneCore::Interface::FastlaneError, 'days_until_release must be greater or equal to days_until_submission.')
281286
end
282287

283288
def create_milestone(due_date:, days_until_submission:, days_until_release:)

0 commit comments

Comments
 (0)