Skip to content

Commit 04a1e43

Browse files
committed
GithubHelperSpec: Fix Issues Pointed on PR Review
1 parent 738c6b0 commit 04a1e43

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
- Deprecate the use of `GHHELPER_ACCESS` in favor of `GITHUB_TOKEN` as the default environment variable to set the GitHub API token. [#420]
1010
- The `github_client:` parameter (aka `ConfigItem`) is now mandatory for all Fastlane actions that use the GitHub API. [#420]
11-
- The Fastlane action `CommentOnPrAction` has the parameter `access_key:` replaced by `github_token:`. [#420]
11+
- The Fastlane action `comment_on_pr` has the parameter `access_key:` replaced by `github_token:`. [#420]
1212

1313
### New Features
1414

spec/github_helper_spec.rb

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@
3939

4040
it 'fails if it does not find the right release on GitHub' do
4141
stub = stub_request(:get, content_url).to_return(status: [404, 'Not Found'])
42-
expect(described_class.download_file_from_tag(repository: test_repo, tag: test_tag, file_path: test_file, download_folder: './')).to be_nil
42+
donwloaded_file = described_class.download_file_from_tag(repository: test_repo, tag: test_tag, file_path: test_file, download_folder: './')
43+
expect(donwloaded_file).to be_nil
4344
expect(stub).to have_been_made.once
4445
end
4546

4647
it 'writes the raw content to a file' do
4748
stub = stub_request(:get, content_url).to_return(status: 200, body: 'my-test-content')
4849
Dir.mktmpdir('a8c-download-repo-file-') do |tmpdir|
4950
dst_file = File.join(tmpdir, 'test-file.xml')
50-
expect(described_class.download_file_from_tag(repository: test_repo, tag: test_tag, file_path: test_file, download_folder: tmpdir)).to eq(dst_file)
51+
donwloaded_file = described_class.download_file_from_tag(repository: test_repo, tag: test_tag, file_path: test_file, download_folder: tmpdir)
52+
expect(donwloaded_file).to eq(dst_file)
5153
expect(stub).to have_been_made.once
5254
expect(File.read(dst_file)).to eq('my-test-content')
5355
end
@@ -70,7 +72,8 @@
7072

7173
it 'returns correct milestone' do
7274
expect(client).to receive(:list_milestones)
73-
expect(described_class.get_last_milestone(repository: test_repo)).to eq(last_stone)
75+
last_milestone = described_class.get_last_milestone(repository: test_repo)
76+
expect(last_milestone).to eq(last_stone)
7477
end
7578

7679
def mock_milestone(title)
@@ -136,7 +139,7 @@ def mock_comment(body: '<!-- REUSE_ID: test-id --> Test', user_id: 1234)
136139

137140
describe 'get_milestone' do
138141
let(:test_repo) { 'repo-test/project-test' }
139-
let(:test_milestone) { [{ title: 'release/10.0' }, { title: 'release/10.1' }, { title: 'hotfix/10.2' }] }
142+
let(:test_milestones) { [{ title: '9.8' }, { title: '10.1' }, { title: '10.1.3 ❄️' }] }
140143
let(:client) do
141144
instance_double(
142145
Octokit::Client,
@@ -154,22 +157,26 @@ def mock_comment(body: '<!-- REUSE_ID: test-id --> Test', user_id: 1234)
154157
end
155158

156159
it 'returns nil when no milestone is returned from the api' do
157-
expect(described_class.get_milestone(test_repo, 'release')).to be_nil
160+
milestone = described_class.get_milestone(test_repo, '10')
161+
expect(milestone).to be_nil
158162
end
159163

160164
it 'returns nil when no milestone title starts with the searched term' do
161-
allow(client).to receive(:list_milestones).and_return(test_milestone)
162-
expect(described_class.get_milestone(test_repo, '10.0')).to be_nil
165+
allow(client).to receive(:list_milestones).and_return(test_milestones)
166+
milestone = described_class.get_milestone(test_repo, '8.5')
167+
expect(milestone).to be_nil
163168
end
164169

165170
it 'returns a milestone when the milestone title starts with search term' do
166-
allow(client).to receive(:list_milestones).and_return(test_milestone)
167-
expect(described_class.get_milestone(test_repo, 'hotfix')).to eq({ title: 'hotfix/10.2' })
171+
allow(client).to receive(:list_milestones).and_return(test_milestones)
172+
milestone = described_class.get_milestone(test_repo, '9')
173+
expect(milestone).to eq({ title: '9.8' })
168174
end
169175

170-
it 'returns the newest of milestones where the title matches with search term' do
171-
allow(client).to receive(:list_milestones).and_return(test_milestone)
172-
expect(described_class.get_milestone(test_repo, 'release')).to eq({ title: 'release/10.1' })
176+
it 'returns the milestone with the latest due date matching the search term when there are more than one' do
177+
allow(client).to receive(:list_milestones).and_return(test_milestones)
178+
milestone = described_class.get_milestone(test_repo, '10.1')
179+
expect(milestone).to eq({ title: '10.1.3 ❄️' })
173180
end
174181
end
175182

@@ -235,7 +242,7 @@ def create_milestone(need_submission:, milestone_duration:, days_code_freeze:)
235242
it 'has the correct options' do
236243
options = { body: test_description, draft: true, name: test_tag, prerelease: false, target_commitish: test_target }
237244
expect(client).to receive(:create_release).with(test_repo, test_tag, options)
238-
mockrelease
245+
create_release
239246
end
240247

241248
it 'upload the assets to the correct location' do
@@ -244,10 +251,10 @@ def create_milestone(need_submission:, milestone_duration:, days_code_freeze:)
244251

245252
allow(client).to receive(:create_release).and_return({ url: test_url })
246253
expect(client).to receive(:upload_asset).with(test_url, test_assets, { content_type: 'application/octet-stream' })
247-
mockrelease([test_assets])
254+
create_release(assets: [test_assets])
248255
end
249256

250-
def mockrelease(assets = [])
257+
def create_release(assets: [])
251258
described_class.create_release(
252259
repository: test_repo,
253260
version: test_tag,

0 commit comments

Comments
 (0)