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
0 commit comments