@@ -27,35 +27,60 @@ def initialize
2727 event = SampleEvent . new
2828
2929 res_body = '{"data": true}'
30- stub_request ( :any , 'https://api.securenative-stg.com/collector/api/v1/some-path/to-api' ) . to_return ( body : res_body . to_json , status : 200 )
30+ stub_request ( :any , 'http://api.securenative-stg.com:443/collector/api/v1/some-path/to-api' )
31+ . with ( headers : {
32+ 'Accept' => '*/*' ,
33+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' ,
34+ 'Authorization' => 'YOUR_API_KEY' ,
35+ 'Content-Type' => 'application/json' ,
36+ 'Sn-Version' => '0.1.19' ,
37+ 'User-Agent' => 'SecureNative-ruby'
38+ } ) . to_return ( status : 200 , body : '' , headers : { } )
3139 event_manager = EventManager . new ( options )
3240
3341 event_manager . start_event_persist
34- data = event_manager . send_sync ( event , 'some-path/to-api' , false )
42+ res = event_manager . send_sync ( event , 'some-path/to-api' , false )
3543 event_manager . stop_event_persist
3644
37- expect ( '"{\"data\": true}"' ) . to eq ( data . body . to_s )
45+ expect ( res . code ) . to eq ( '200' )
3846 end
3947
4048 it 'fails when send sync event status code is 401' do
4149 options = ConfigurationBuilder . new ( api_key : 'YOUR_API_KEY' , api_url : 'https://api.securenative-stg.com/collector/api/v1' )
4250 event = SampleEvent . new
4351
44- stub_request ( :post , 'https://api.securenative-stg.com/collector/api/v1/some-path/to-api' ) . to_return ( status : 401 )
52+ stub_request ( :any , 'http://api.securenative-stg.com:443/collector/api/v1/some-path/to-api' )
53+ . with ( headers : {
54+ 'Accept' => '*/*' ,
55+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' ,
56+ 'Authorization' => 'YOUR_API_KEY' ,
57+ 'Content-Type' => 'application/json' ,
58+ 'Sn-Version' => '0.1.19' ,
59+ 'User-Agent' => 'SecureNative-ruby'
60+ } ) . to_return ( status : 401 , body : '' , headers : { } )
61+
4562 event_manager = EventManager . new ( options )
4663 res = event_manager . send_sync ( event , 'some-path/to-api' , false )
4764
48- expect ( res . status_code ) . to eq ( 401 )
65+ expect ( res . code ) . to eq ( ' 401' )
4966 end
5067
5168 it 'fails when send sync event status code is 500' do
5269 options = ConfigurationBuilder . new ( api_key : 'YOUR_API_KEY' , api_url : 'https://api.securenative-stg.com/collector/api/v1' )
5370 event = SampleEvent . new
5471
55- stub_request ( :post , 'https://api.securenative-stg.com/collector/api/v1/some-path/to-api' ) . to_return ( status : 500 )
72+ stub_request ( :post , 'http://api.securenative-stg.com:443/collector/api/v1/some-path/to-api' )
73+ . with ( headers : {
74+ 'Accept' => '*/*' ,
75+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' ,
76+ 'Authorization' => 'YOUR_API_KEY' ,
77+ 'Content-Type' => 'application/json' ,
78+ 'Sn-Version' => '0.1.19' ,
79+ 'User-Agent' => 'SecureNative-ruby'
80+ } ) . to_return ( status : 500 , body : '' , headers : { } )
5681 event_manager = EventManager . new ( options )
5782 res = event_manager . send_sync ( event , 'some-path/to-api' , false )
5883
59- expect ( res . status_code ) . to eq ( 500 )
84+ expect ( res . code ) . to eq ( ' 500' )
6085 end
6186end
0 commit comments