Skip to content

Commit a475122

Browse files
committed
Add specs for InstabugBuildAndroidAppAction and InstabugBuildIosAppAction with metadata reporting
1 parent a8d21ea commit a475122

File tree

2 files changed

+267
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)