Skip to content

Commit c7d062d

Browse files
author
Inbal Tako
committed
Fix tests
1 parent ce0e20e commit c7d062d

3 files changed

Lines changed: 60 additions & 51 deletions

File tree

spec/spec_api_manager.rb

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,18 @@
5757
it 'verifies an event' do
5858
options = ConfigurationBuilder.new(api_key: 'YOUR_API_KEY', api_url: 'https://api.securenative-stg.com/collector/api/v1')
5959

60-
# stub_request(:post, 'https://api.securenative-stg.com/collector/api/v1/track')
61-
# .with(body: { riskLevel: 'medium', score: 0.32, triggers: ['New IP', 'New City'] }).to_return(status: 200)
60+
stub_request(:post, "https://api.securenative-stg.com/collector/api/v1/verify").
61+
with(
62+
headers: {
63+
'Accept'=>'*/*',
64+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
65+
'Authorization'=>'YOUR_API_KEY',
66+
'Content-Type'=>'application/json',
67+
'Sn-Version'=>'0.1.22',
68+
'User-Agent'=>'SecureNative-ruby'
69+
}).
70+
to_return(status: 200, body: "", headers: {})
6271

63-
stub_request(:post, 'https://api.securenative-stg.com/collector/api/v1/verify')
64-
.with(headers: {
65-
'Accept' => '*/*',
66-
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
67-
'Authorization' => 'YOUR_API_KEY',
68-
'Content-Type' => 'application/json',
69-
'Sn-Version' => '0.1.21',
70-
'User-Agent' => 'SecureNative-ruby'
71-
}).to_return(status: 200, body: '', headers: {})
72-
verify_result = VerifyResult.new(risk_level: RiskLevel::LOW, score: 0, triggers: nil)
7372

7473
event_manager = EventManager.new(options)
7574
event_manager.start_event_persist
@@ -81,8 +80,8 @@
8180
result = api_manager.verify(event_options)
8281

8382
expect(result).not_to be_nil
84-
expect(result.risk_level).to eq(verify_result.risk_level)
85-
expect(result.score).to eq(verify_result.score)
86-
expect(result.triggers).to eq(verify_result.triggers)
83+
expect(result.risk_level).to eq('low')
84+
expect(result.score).to eq(0)
85+
expect(result.triggers).to eq(nil)
8786
end
8887
end

spec/spec_event_manager.rb

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@ def initialize
2626
options = ConfigurationBuilder.new(api_key: 'YOUR_API_KEY', api_url: 'https://api.securenative-stg.com/collector/api/v1')
2727
event = SampleEvent.new
2828

29-
stub_request(:post, 'https://api.securenative-stg.com/collector/api/v1/some-path/to-api')
30-
.with(headers: {
31-
'Accept' => '*/*',
32-
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
33-
'Authorization' => 'YOUR_API_KEY',
34-
'Content-Type' => 'application/json',
35-
'Sn-Version' => '0.1.21',
36-
'User-Agent' => 'SecureNative-ruby'
37-
}).to_return(status: 200, body: '', headers: {})
29+
stub_request(:post, "https://api.securenative-stg.com/collector/api/v1/some-path/to-api").
30+
with(
31+
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.22',
37+
'User-Agent'=>'SecureNative-ruby'
38+
}).
39+
to_return(status: 200, body: "", headers: {})
40+
3841
event_manager = EventManager.new(options)
3942

4043
event_manager.start_event_persist
@@ -48,15 +51,17 @@ def initialize
4851
options = ConfigurationBuilder.new(api_key: 'YOUR_API_KEY', api_url: 'https://api.securenative-stg.com/collector/api/v1')
4952
event = SampleEvent.new
5053

51-
stub_request(:post, 'https://api.securenative-stg.com/collector/api/v1/some-path/to-api')
52-
.with(headers: {
53-
'Accept' => '*/*',
54-
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
55-
'Authorization' => 'YOUR_API_KEY',
56-
'Content-Type' => 'application/json',
57-
'Sn-Version' => '0.1.21',
58-
'User-Agent' => 'SecureNative-ruby'
59-
}).to_return(status: 401, body: '', headers: {})
54+
stub_request(:post, "https://api.securenative-stg.com/collector/api/v1/some-path/to-api").
55+
with(
56+
headers: {
57+
'Accept'=>'*/*',
58+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
59+
'Authorization'=>'YOUR_API_KEY',
60+
'Content-Type'=>'application/json',
61+
'Sn-Version'=>'0.1.22',
62+
'User-Agent'=>'SecureNative-ruby'
63+
}).
64+
to_return(status: 401, body: "", headers: {})
6065

6166
event_manager = EventManager.new(options)
6267
res = event_manager.send_sync(event, 'some-path/to-api', false)
@@ -68,15 +73,18 @@ def initialize
6873
options = ConfigurationBuilder.new(api_key: 'YOUR_API_KEY', api_url: 'https://api.securenative-stg.com/collector/api/v1')
6974
event = SampleEvent.new
7075

71-
stub_request(:post, 'https://api.securenative-stg.com/collector/api/v1/some-path/to-api')
72-
.with(headers: {
73-
'Accept' => '*/*',
74-
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
75-
'Authorization' => 'YOUR_API_KEY',
76-
'Content-Type' => 'application/json',
77-
'Sn-Version' => '0.1.21',
78-
'User-Agent' => 'SecureNative-ruby'
79-
}).to_return(status: 500, body: '', headers: {})
76+
stub_request(:post, "https://api.securenative-stg.com/collector/api/v1/some-path/to-api").
77+
with(
78+
headers: {
79+
'Accept'=>'*/*',
80+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
81+
'Authorization'=>'YOUR_API_KEY',
82+
'Content-Type'=>'application/json',
83+
'Sn-Version'=>'0.1.22',
84+
'User-Agent'=>'SecureNative-ruby'
85+
}).
86+
to_return(status: 500, body: "", headers: {})
87+
8088
event_manager = EventManager.new(options)
8189
res = event_manager.send_sync(event, 'some-path/to-api', false)
8290

spec/spec_securenative_http_client.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
it 'makes a simple post call' do
1010
options = ConfigurationBuilder.new(api_key: 'YOUR_API_KEY', api_url: 'https://api.securenative-stg.com/collector/api/v1')
1111

12-
stub_request(:post, 'https://api.securenative-stg.com/collector/api/v1/track')
13-
.with(body: '{"event": "SOME_EVENT_NAME"}',
12+
stub_request(:post, "https://api.securenative-stg.com/collector/api/v1/track").
13+
with(
14+
body: "{\"event\": \"SOME_EVENT_NAME\"}",
1415
headers: {
15-
'Accept' => '*/*',
16-
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
17-
'Authorization' => 'YOUR_API_KEY',
18-
'Content-Type' => 'application/json',
19-
'Sn-Version' => '0.1.21',
20-
'User-Agent' => 'SecureNative-ruby'
21-
}).to_return(status: 200, body: '', headers: {})
16+
'Accept'=>'*/*',
17+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
18+
'Authorization'=>'YOUR_API_KEY',
19+
'Content-Type'=>'application/json',
20+
'Sn-Version'=>'0.1.22',
21+
'User-Agent'=>'SecureNative-ruby'
22+
}).
23+
to_return(status: 200, body: "", headers: {})
2224
client = SecureNativeHttpClient.new(options)
2325
payload = '{"event": "SOME_EVENT_NAME"}'
2426

0 commit comments

Comments
 (0)