-
Notifications
You must be signed in to change notification settings - Fork 9
Add Unit tests for milestone actions #425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 3 commits
c37f29e
6dfd767
22b9d44
96acb93
f695b04
3472f9e
cdd96c2
3a5a240
5e656dd
b6de4cd
9eb95c2
87ae1d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,10 @@ def self.run(params) | |
|
||
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token]) | ||
last_stone = github_helper.get_last_milestone(repository) | ||
|
||
UI.user_error!('No milestone found on the repository.') if last_stone.nil? | ||
UI.user_error!("Milestone #{last_stone[:title]} has no due date.") if last_stone[:due_on].nil? | ||
|
||
UI.message("Last detected milestone: #{last_stone[:title]} due on #{last_stone[:due_on]}.") | ||
milestone_duedate = last_stone[:due_on] | ||
milestone_duration = params[:milestone_duration] | ||
|
@@ -49,19 +53,19 @@ def self.available_options | |
env_name: 'GHHELPER_NEED_APPSTORE_SUBMISSION', | ||
description: 'True if the app needs to be submitted', | ||
optional: true, | ||
is_string: false, | ||
type: Boolean, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Self-Review: As the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great! It's even a small step towards addressing #278 that we opened a while ago about this 🙂 |
||
default_value: false), | ||
FastlaneCore::ConfigItem.new(key: :milestone_duration, | ||
env_name: 'GHHELPER_MILESTONE_DURATION', | ||
description: 'Milestone duration in number of days', | ||
optional: true, | ||
is_string: false, | ||
type: Integer, | ||
default_value: 14), | ||
FastlaneCore::ConfigItem.new(key: :number_of_days_from_code_freeze_to_release, | ||
env_name: 'GHHELPER_NUMBER_OF_DAYS_FROM_CODE_FREEZE_TO_RELEASE', | ||
description: 'Number of days from code freeze to release', | ||
optional: true, | ||
is_string: false, | ||
type: Integer, | ||
default_value: 14), | ||
Fastlane::Helper::GithubHelper.github_token_config_item, | ||
] | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,105 +1,86 @@ | ||||||||||||||||||||
require 'spec_helper' | ||||||||||||||||||||
|
||||||||||||||||||||
describe Fastlane::Actions::CloseMilestoneAction do | ||||||||||||||||||||
describe 'initialize' do | ||||||||||||||||||||
let(:test_token) { 'Test-GithubToken-1234' } | ||||||||||||||||||||
let(:mock_params) do | ||||||||||||||||||||
{ | ||||||||||||||||||||
repository: 'test-repository', | ||||||||||||||||||||
milestone: '10' | ||||||||||||||||||||
} | ||||||||||||||||||||
end | ||||||||||||||||||||
let(:client) do | ||||||||||||||||||||
instance_double( | ||||||||||||||||||||
Octokit::Client, | ||||||||||||||||||||
list_milestones: [{ title: '10.1' }], | ||||||||||||||||||||
update_milestone: nil, | ||||||||||||||||||||
user: instance_double('User', name: 'test'), | ||||||||||||||||||||
'auto_paginate=': nil | ||||||||||||||||||||
) | ||||||||||||||||||||
end | ||||||||||||||||||||
let(:test_repository) { 'test-repository' } | ||||||||||||||||||||
let(:test_token) { 'Test-GithubToken-1234' } | ||||||||||||||||||||
let(:test_milestone) do | ||||||||||||||||||||
{ title: '10.1', number: '1234' } | ||||||||||||||||||||
end | ||||||||||||||||||||
let(:client) do | ||||||||||||||||||||
instance_double( | ||||||||||||||||||||
Octokit::Client, | ||||||||||||||||||||
list_milestones: [test_milestone], | ||||||||||||||||||||
update_milestone: nil, | ||||||||||||||||||||
user: instance_double('User', name: 'test'), | ||||||||||||||||||||
'auto_paginate=': nil | ||||||||||||||||||||
) | ||||||||||||||||||||
end | ||||||||||||||||||||
|
||||||||||||||||||||
before do | ||||||||||||||||||||
ENV['GITHUB_TOKEN'] = nil | ||||||||||||||||||||
mock_params[:github_token] = nil | ||||||||||||||||||||
allow(Octokit::Client).to receive(:new).and_return(client) | ||||||||||||||||||||
end | ||||||||||||||||||||
before do | ||||||||||||||||||||
allow(Octokit::Client).to receive(:new).and_return(client) | ||||||||||||||||||||
end | ||||||||||||||||||||
|
||||||||||||||||||||
it 'properly passes the environment variable `GITHUB_TOKEN` all the way to Octokit::Client' do | ||||||||||||||||||||
ENV['GITHUB_TOKEN'] = test_token | ||||||||||||||||||||
expect(Octokit::Client).to receive(:new).with(access_token: test_token) | ||||||||||||||||||||
run_described_fastlane_action(mock_params) | ||||||||||||||||||||
end | ||||||||||||||||||||
it 'properly passes the environment variable `GITHUB_TOKEN` to Octokit::Client' do | ||||||||||||||||||||
ENV['GITHUB_TOKEN'] = test_token | ||||||||||||||||||||
expect(Octokit::Client).to receive(:new).with(access_token: test_token) | ||||||||||||||||||||
run_action_without_key(:github_token) | ||||||||||||||||||||
end | ||||||||||||||||||||
|
||||||||||||||||||||
it 'properly passes the parameter `:github_token` all the way to Octokit::Client' do | ||||||||||||||||||||
mock_params[:github_token] = test_token | ||||||||||||||||||||
expect(Octokit::Client).to receive(:new).with(access_token: test_token) | ||||||||||||||||||||
run_described_fastlane_action(mock_params) | ||||||||||||||||||||
end | ||||||||||||||||||||
it 'properly passes the parameter `:github_token` to Octokit::Client' do | ||||||||||||||||||||
expect(Octokit::Client).to receive(:new).with(access_token: test_token) | ||||||||||||||||||||
run_described_fastlane_action(default_params) | ||||||||||||||||||||
end | ||||||||||||||||||||
|
||||||||||||||||||||
it 'prioritizes `:github_token` parameter over `GITHUB_TOKEN` enviroment variable if both are present' do | ||||||||||||||||||||
ENV['GITHUB_TOKEN'] = 'Test-EnvGithubToken-1234' | ||||||||||||||||||||
mock_params[:github_token] = test_token | ||||||||||||||||||||
expect(Octokit::Client).to receive(:new).with(access_token: test_token) | ||||||||||||||||||||
run_described_fastlane_action(mock_params) | ||||||||||||||||||||
end | ||||||||||||||||||||
it 'prioritizes `:github_token` parameter over `GITHUB_TOKEN` environment variable if both are present' do | ||||||||||||||||||||
ENV['GITHUB_TOKEN'] = 'Test-EnvGithubToken-1234' | ||||||||||||||||||||
expect(Octokit::Client).to receive(:new).with(access_token: test_token) | ||||||||||||||||||||
run_described_fastlane_action(default_params) | ||||||||||||||||||||
end | ||||||||||||||||||||
|
||||||||||||||||||||
it 'prints an error if no `GITHUB_TOKEN` environment variable nor parameter `:github_token` is present' do | ||||||||||||||||||||
expect { run_described_fastlane_action(mock_params) }.to raise_error(FastlaneCore::Interface::FastlaneError) | ||||||||||||||||||||
end | ||||||||||||||||||||
it 'properly passes the repository and milestone to Octokit::Client to update the milestone as closed' do | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
expect(client).to receive(:update_milestone).with(test_repository, test_milestone[:number], state: 'closed') | ||||||||||||||||||||
run_described_fastlane_action(default_params) | ||||||||||||||||||||
end | ||||||||||||||||||||
|
||||||||||||||||||||
describe 'get_milestone' do | ||||||||||||||||||||
let(:test_repository) { 'test-repository' } | ||||||||||||||||||||
let(:test_milestone) { '10' } | ||||||||||||||||||||
let(:mock_params) do | ||||||||||||||||||||
{ | ||||||||||||||||||||
repository: test_repository, | ||||||||||||||||||||
milestone: test_milestone, | ||||||||||||||||||||
github_token: 'Test-GithubToken-1234' | ||||||||||||||||||||
} | ||||||||||||||||||||
end | ||||||||||||||||||||
let(:client) do | ||||||||||||||||||||
instance_double( | ||||||||||||||||||||
Octokit::Client, | ||||||||||||||||||||
list_milestones: [{ title: '10.1' }], | ||||||||||||||||||||
update_milestone: nil, | ||||||||||||||||||||
user: instance_double('User', name: 'test'), | ||||||||||||||||||||
'auto_paginate=': nil | ||||||||||||||||||||
) | ||||||||||||||||||||
end | ||||||||||||||||||||
it 'raises an error when the milestone is not found or does not exist' do | ||||||||||||||||||||
allow(client).to receive(:list_milestones).and_return([]) | ||||||||||||||||||||
expect { run_described_fastlane_action(default_params) }.to raise_error(FastlaneCore::Interface::FastlaneError, 'Milestone 10.1 not found.') | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||||||||||||||||||||
end | ||||||||||||||||||||
|
||||||||||||||||||||
it 'properly passes the repository all the way down to the Octokit::Client to list the milestones' do | ||||||||||||||||||||
allow(Octokit::Client).to receive(:new).and_return(client) | ||||||||||||||||||||
expect(client).to receive(:list_milestones).with(test_repository) | ||||||||||||||||||||
run_described_fastlane_action(mock_params) | ||||||||||||||||||||
describe 'Calling the Action validates input' do | ||||||||||||||||||||
it 'raises an error if no `GITHUB_TOKEN` environment variable nor parameter `:github_token` is present' do | ||||||||||||||||||||
ENV['GITHUB_TOKEN'] = nil | ||||||||||||||||||||
expect { run_action_without_key(:github_token) }.to raise_error(FastlaneCore::Interface::FastlaneError, "No value found for 'github_token'") | ||||||||||||||||||||
end | ||||||||||||||||||||
end | ||||||||||||||||||||
|
||||||||||||||||||||
describe 'update_milestone' do | ||||||||||||||||||||
let(:test_repository) { 'test-repository' } | ||||||||||||||||||||
let(:test_milestone_number) { '1234' } | ||||||||||||||||||||
let(:mock_params) do | ||||||||||||||||||||
{ | ||||||||||||||||||||
repository: test_repository, | ||||||||||||||||||||
milestone: '10', | ||||||||||||||||||||
github_token: 'Test-GithubToken-1234' | ||||||||||||||||||||
} | ||||||||||||||||||||
it 'raises an error if no `GHHELPER_REPOSITORY` environment variable nor parameter `:repository` is present' do | ||||||||||||||||||||
expect { run_action_without_key(:repository) }.to raise_error(FastlaneCore::Interface::FastlaneError, "No value found for 'repository'") | ||||||||||||||||||||
end | ||||||||||||||||||||
let(:client) do | ||||||||||||||||||||
instance_double( | ||||||||||||||||||||
Octokit::Client, | ||||||||||||||||||||
list_milestones: [{ title: '10.1', number: test_milestone_number }], | ||||||||||||||||||||
update_milestone: nil, | ||||||||||||||||||||
user: instance_double('User', name: 'test'), | ||||||||||||||||||||
'auto_paginate=': nil | ||||||||||||||||||||
) | ||||||||||||||||||||
|
||||||||||||||||||||
it 'raises an error if no `GHHELPER_MILESTONE` environment variable nor parameter `:milestone` is present' do | ||||||||||||||||||||
expect { run_action_without_key(:milestone) }.to raise_error(FastlaneCore::Interface::FastlaneError, "No value found for 'milestone'") | ||||||||||||||||||||
end | ||||||||||||||||||||
|
||||||||||||||||||||
it 'properly passes the parameters all the way down to Octokit::Client' do | ||||||||||||||||||||
allow(Octokit::Client).to receive(:new).and_return(client) | ||||||||||||||||||||
expect(client).to receive(:update_milestone).with(test_repository, test_milestone_number, { state: 'closed' }) | ||||||||||||||||||||
run_described_fastlane_action(mock_params) | ||||||||||||||||||||
it 'raises an error if `milestone:` parameter is passed as Integer' do | ||||||||||||||||||||
expect { run_action_with(:milestone, 10) }.to raise_error "'milestone' value must be a String! Found Integer instead." | ||||||||||||||||||||
end | ||||||||||||||||||||
end | ||||||||||||||||||||
|
||||||||||||||||||||
def run_action_without_key(key) | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||||||||||||||||
run_described_fastlane_action(default_params.except(key)) | ||||||||||||||||||||
end | ||||||||||||||||||||
|
||||||||||||||||||||
def run_action_with(key, value) | ||||||||||||||||||||
values = default_params | ||||||||||||||||||||
values[key] = value | ||||||||||||||||||||
run_described_fastlane_action(values) | ||||||||||||||||||||
end | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: why not make this more flexible by allowing it to take a
Suggested change
Should allow the call site to look like: run_action_with(milestone: '10') There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I see that you suggested that above, but forget to change it on the newest commit, sorry for that, Already change it 👍 |
||||||||||||||||||||
|
||||||||||||||||||||
def default_params | ||||||||||||||||||||
{ | ||||||||||||||||||||
repository: test_repository, | ||||||||||||||||||||
milestone: test_milestone[:title], | ||||||||||||||||||||
github_token: test_token | ||||||||||||||||||||
} | ||||||||||||||||||||
end | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, here it is! When I saw Any reason why this is a method here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That confused me a bit tbh 🤔. Because, If I put those in a I thought if I put the parameters again as a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||
end |
Uh oh!
There was an error while loading. Please reload this page.