Skip to content

Commit 2b6414d

Browse files
committed
Adding Specs to cover the stores upload actions
1 parent de565fb commit 2b6414d

File tree

5 files changed

+267
-2
lines changed

5 files changed

+267
-2
lines changed

.rspec

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
--require spec_helper
22
--color
33
--format d
4-
--format RspecJunitFormatter
5-
--out test-results/rspec/rspec.xml

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
source('https://rubygems.org')
22

3+
gem 'webmock'
34
gemspec
45

56
plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
require 'spec_helper'
2+
3+
describe Fastlane::Actions::InstabugUploadToAppStoreAction do
4+
let(:valid_params) do
5+
{
6+
branch_name: 'crash-fix/instabug-crash-123',
7+
instabug_api_key: 'test-api-key',
8+
ipa: 'test.ipa',
9+
skip_screenshots: true
10+
}
11+
end
12+
13+
let(:api_endpoint) { 'https://api.instabug.com/api/web/public/agent_fastlane/status' }
14+
15+
before do
16+
stub_request(:patch, api_endpoint)
17+
.to_return(status: 200, body: '{}', headers: {})
18+
end
19+
20+
describe '#run' do
21+
context 'when upload succeeds' do
22+
it 'reports inprogress, calls upload action, and reports success' do
23+
expect(Fastlane::Actions::UploadToAppStoreAction).to receive(:run)
24+
.with(hash_including(ipa: 'test.ipa', skip_screenshots: true))
25+
.and_return('upload_result')
26+
27+
result = described_class.run(valid_params)
28+
29+
expect(result).to eq('upload_result')
30+
expect(WebMock).to have_requested(:patch, api_endpoint)
31+
.with(
32+
body: {
33+
branch_name: 'crash-fix/instabug-crash-123',
34+
status: 'inprogress',
35+
step: 'upload_to_the_store'
36+
}.to_json,
37+
headers: {
38+
'Content-Type' => 'application/json',
39+
'Authorization' => 'Bearer test-api-key',
40+
'User-Agent' => 'fastlane-plugin-instabug-stores-upload'
41+
}
42+
).once
43+
44+
expect(WebMock).to have_requested(:patch, api_endpoint)
45+
.with(
46+
body: {
47+
branch_name: 'crash-fix/instabug-crash-123',
48+
status: 'success',
49+
step: 'upload_to_the_store'
50+
}.to_json,
51+
headers: {
52+
'Content-Type' => 'application/json',
53+
'Authorization' => 'Bearer test-api-key',
54+
'User-Agent' => 'fastlane-plugin-instabug-stores-upload'
55+
}
56+
).once
57+
end
58+
end
59+
60+
context 'when upload fails' do
61+
it 'reports failure and re-raises the error' do
62+
error = StandardError.new('Upload failed')
63+
expect(Fastlane::Actions::UploadToAppStoreAction).to receive(:run)
64+
.and_raise(error)
65+
66+
expect {
67+
described_class.run(valid_params)
68+
}.to raise_error(StandardError, 'Upload failed')
69+
70+
expect(WebMock).to have_requested(:patch, api_endpoint)
71+
.with(
72+
body: {
73+
branch_name: 'crash-fix/instabug-crash-123',
74+
status: 'failure',
75+
step: 'upload_to_the_store'
76+
}.to_json
77+
)
78+
end
79+
end
80+
81+
context 'when branch_name is missing' do
82+
it 'raises user error' do
83+
params = valid_params.merge(branch_name: nil)
84+
85+
expect {
86+
described_class.run(params)
87+
}.to raise_error(FastlaneCore::Interface::FastlaneError, 'branch_name is required for Instabug reporting')
88+
end
89+
end
90+
91+
context 'when branch_name is empty' do
92+
it 'raises user error' do
93+
params = valid_params.merge(branch_name: '')
94+
95+
expect {
96+
described_class.run(params)
97+
}.to raise_error(FastlaneCore::Interface::FastlaneError, 'branch_name is required for Instabug reporting')
98+
end
99+
end
100+
101+
context 'when branch name does not match instabug pattern' do
102+
it 'does not make API calls but still runs upload' do
103+
params = valid_params.merge(branch_name: 'feature/new-feature')
104+
105+
expect(Fastlane::Actions::UploadToAppStoreAction).to receive(:run)
106+
.and_return('upload_result')
107+
108+
result = described_class.run(params)
109+
110+
expect(result).to eq('upload_result')
111+
expect(WebMock).not_to have_requested(:patch, api_endpoint)
112+
end
113+
end
114+
end
115+
116+
describe 'metadata' do
117+
it 'has correct description' do
118+
expect(described_class.description).to eq('Upload to App Store with Instabug metadata reporting')
119+
end
120+
121+
it 'supports iOS and Mac platforms' do
122+
expect(described_class.is_supported?(:ios)).to be true
123+
expect(described_class.is_supported?(:mac)).to be true
124+
expect(described_class.is_supported?(:android)).to be false
125+
end
126+
127+
it 'has correct category' do
128+
expect(described_class.category).to eq(:app_store_connect)
129+
end
130+
end
131+
end
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
require 'spec_helper'
2+
3+
describe Fastlane::Actions::InstabugUploadToPlayStoreAction do
4+
let(:valid_params) do
5+
{
6+
branch_name: 'crash-fix/instabug-crash-456',
7+
instabug_api_key: 'test-api-key',
8+
package_name: 'com.example.app',
9+
aab: 'test.aab',
10+
track: 'internal'
11+
}
12+
end
13+
14+
let(:api_endpoint) { 'https://api.instabug.com/api/web/public/agent_fastlane/status' }
15+
16+
before do
17+
stub_request(:patch, api_endpoint)
18+
.to_return(status: 200, body: '{}', headers: {})
19+
end
20+
21+
describe '#run' do
22+
context 'when upload succeeds' do
23+
it 'reports inprogress, calls upload action, and reports success' do
24+
expect(Fastlane::Actions::UploadToPlayStoreAction).to receive(:run)
25+
.with(hash_including(package_name: 'com.example.app', aab: 'test.aab', track: 'internal'))
26+
.and_return('upload_result')
27+
28+
result = described_class.run(valid_params)
29+
30+
expect(result).to eq('upload_result')
31+
expect(WebMock).to have_requested(:patch, api_endpoint)
32+
.with(
33+
body: {
34+
branch_name: 'crash-fix/instabug-crash-456',
35+
status: 'inprogress',
36+
step: 'upload_to_the_store'
37+
}.to_json,
38+
headers: {
39+
'Content-Type' => 'application/json',
40+
'Authorization' => 'Bearer test-api-key',
41+
'User-Agent' => 'fastlane-plugin-instabug-stores-upload'
42+
}
43+
).once
44+
45+
expect(WebMock).to have_requested(:patch, api_endpoint)
46+
.with(
47+
body: {
48+
branch_name: 'crash-fix/instabug-crash-456',
49+
status: 'success',
50+
step: 'upload_to_the_store'
51+
}.to_json,
52+
headers: {
53+
'Content-Type' => 'application/json',
54+
'Authorization' => 'Bearer test-api-key',
55+
'User-Agent' => 'fastlane-plugin-instabug-stores-upload'
56+
}
57+
).once
58+
end
59+
end
60+
61+
context 'when upload fails' do
62+
it 'reports failure and re-raises the error' do
63+
error = StandardError.new('Upload failed')
64+
expect(Fastlane::Actions::UploadToPlayStoreAction).to receive(:run)
65+
.and_raise(error)
66+
67+
expect {
68+
described_class.run(valid_params)
69+
}.to raise_error(StandardError, 'Upload failed')
70+
71+
expect(WebMock).to have_requested(:patch, api_endpoint)
72+
.with(
73+
body: {
74+
branch_name: 'crash-fix/instabug-crash-456',
75+
status: 'failure',
76+
step: 'upload_to_the_store'
77+
}.to_json
78+
)
79+
end
80+
end
81+
82+
context 'when branch_name is missing' do
83+
it 'raises user error' do
84+
params = valid_params.merge(branch_name: nil)
85+
86+
expect {
87+
described_class.run(params)
88+
}.to raise_error(FastlaneCore::Interface::FastlaneError, 'branch_name is required for Instabug reporting')
89+
end
90+
end
91+
92+
context 'when branch_name is empty' do
93+
it 'raises user error' do
94+
params = valid_params.merge(branch_name: '')
95+
96+
expect {
97+
described_class.run(params)
98+
}.to raise_error(FastlaneCore::Interface::FastlaneError, 'branch_name is required for Instabug reporting')
99+
end
100+
end
101+
102+
context 'when branch name does not match instabug pattern' do
103+
it 'does not make API calls but still runs upload' do
104+
params = valid_params.merge(branch_name: 'feature/new-feature')
105+
106+
expect(Fastlane::Actions::UploadToPlayStoreAction).to receive(:run)
107+
.and_return('upload_result')
108+
109+
result = described_class.run(params)
110+
111+
expect(result).to eq('upload_result')
112+
expect(WebMock).not_to have_requested(:patch, api_endpoint)
113+
end
114+
end
115+
end
116+
117+
describe 'metadata' do
118+
it 'has correct description' do
119+
expect(described_class.description).to eq('Upload to Play Store with Instabug metadata reporting')
120+
end
121+
122+
it 'supports Android platform only' do
123+
expect(described_class.is_supported?(:android)).to be true
124+
expect(described_class.is_supported?(:ios)).to be false
125+
expect(described_class.is_supported?(:mac)).to be false
126+
end
127+
128+
it 'has correct category' do
129+
expect(described_class.category).to eq(:google_play_console)
130+
end
131+
end
132+
end

spec/spec_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ module SpecHelper
1111

1212
require 'fastlane' # to import the Action super class
1313
require 'fastlane/plugin/instabug_stores_upload' # import the actual plugin
14+
require 'webmock/rspec'
1415

1516
Fastlane.load_actions # load other actions (in case your plugin calls other actions or shared values)
17+
18+
WebMock.disable_net_connect!(allow_localhost: true)

0 commit comments

Comments
 (0)