20
20
21
21
describe '#run' do
22
22
context 'when build succeeds' do
23
- it 'reports inprogress, calls build action, and reports success' do
23
+ it 'reports inprogress, calls build action, and reports success with timing and path' do
24
+ # Mock the lane context to return an IPA path
25
+ allow ( Fastlane ::Actions ) . to receive ( :lane_context ) . and_return ( {
26
+ Fastlane ::Actions ::SharedValues ::IPA_OUTPUT_PATH => '/path/to/app.ipa'
27
+ } )
28
+
24
29
expect ( Fastlane ::Actions ::BuildIosAppAction ) . to receive ( :run )
25
30
. with ( hash_including ( workspace : 'Test.xcworkspace' , scheme : 'Test' , export_method : 'app-store' ) )
26
31
. and_return ( 'build_result' )
33
38
body : {
34
39
branch_name : 'crash-fix/instabug-crash-123' ,
35
40
status : 'inprogress' ,
36
- step : 'build_app'
41
+ step : 'build_app' ,
42
+ extras : { } ,
43
+ error_message : nil
37
44
} . to_json ,
38
45
headers : {
39
46
'Content-Type' => 'application/json' ,
43
50
) . once
44
51
45
52
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
53
+ . with { |req |
54
+ body = JSON . parse ( req . body )
55
+ body [ 'status' ] == 'success' &&
56
+ body [ 'branch_name' ] == 'crash-fix/instabug-crash-123' &&
57
+ body [ 'step' ] == 'build_app' &&
58
+ body [ 'extras' ] [ 'build_path' ] == '/path/to/app.ipa' &&
59
+ body [ 'extras' ] [ 'build_time' ] . kind_of? ( Integer )
60
+ } . once
61
+ end
62
+
63
+ it 'handles missing IPA path gracefully' do
64
+ # Mock empty lane context
65
+ allow ( Fastlane ::Actions ) . to receive ( :lane_context ) . and_return ( { } )
66
+
67
+ expect ( Fastlane ::Actions ::BuildIosAppAction ) . to receive ( :run )
68
+ . and_return ( 'build_result' )
69
+
70
+ result = described_class . run ( valid_params )
71
+
72
+ expect ( result ) . to eq ( 'build_result' )
73
+ expect ( WebMock ) . to have_requested ( :patch , api_endpoint )
74
+ . with { |req |
75
+ body = JSON . parse ( req . body )
76
+ body [ 'status' ] == 'success' &&
77
+ body [ 'branch_name' ] == 'crash-fix/instabug-crash-123' &&
78
+ body [ 'step' ] == 'build_app' &&
79
+ body [ 'extras' ] [ 'build_path' ] . nil? &&
80
+ body [ 'extras' ] [ 'build_time' ] . kind_of? ( Integer )
81
+ } . once
58
82
end
59
83
end
60
84
64
88
expect ( Fastlane ::Actions ::BuildIosAppAction ) . to receive ( :run )
65
89
. and_raise ( error )
66
90
67
- expect {
91
+ expect do
68
92
described_class . run ( valid_params )
69
- } . to raise_error ( StandardError , 'Build failed' )
93
+ end . to raise_error ( StandardError , 'Build failed' )
70
94
71
95
expect ( WebMock ) . to have_requested ( :patch , api_endpoint )
72
96
. with (
73
97
body : {
74
98
branch_name : 'crash-fix/instabug-crash-123' ,
75
99
status : 'failure' ,
76
- step : 'build_app'
100
+ step : 'build_app' ,
101
+ extras : { } ,
102
+ error_message : 'Build failed'
77
103
} . to_json
78
104
)
79
105
end
83
109
it 'raises user error' do
84
110
params = valid_params . merge ( branch_name : nil )
85
111
86
- expect {
112
+ expect do
87
113
described_class . run ( params )
88
- } . to raise_error ( FastlaneCore ::Interface ::FastlaneError , 'branch_name is required for Instabug reporting' )
114
+ end . to raise_error ( FastlaneCore ::Interface ::FastlaneError , 'branch_name is required for Instabug reporting' )
89
115
end
90
116
end
91
117
92
118
context 'when branch_name is empty' do
93
119
it 'raises user error' do
94
120
params = valid_params . merge ( branch_name : '' )
95
121
96
- expect {
122
+ expect do
97
123
described_class . run ( params )
98
- } . to raise_error ( FastlaneCore ::Interface ::FastlaneError , 'branch_name is required for Instabug reporting' )
124
+ end . to raise_error ( FastlaneCore ::Interface ::FastlaneError , 'branch_name is required for Instabug reporting' )
99
125
end
100
126
end
101
127
102
128
context 'when branch name does not match instabug pattern' do
103
129
it 'does not make API calls but still runs build' do
104
130
params = valid_params . merge ( branch_name : 'feature/new-feature' )
105
-
131
+
106
132
expect ( Fastlane ::Actions ::BuildIosAppAction ) . to receive ( :run )
107
133
. and_return ( 'build_result' )
108
134
129
155
expect ( described_class . category ) . to eq ( :building )
130
156
end
131
157
end
132
- end
158
+ end
0 commit comments