Skip to content

Commit 484ecf7

Browse files
Added new test cases
1 parent 38fea35 commit 484ecf7

5 files changed

Lines changed: 104 additions & 25 deletions

fraudlabspro_ruby.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
3232
"lib/fraudlabspro_ruby/configuration.rb",
3333
"lib/fraudlabspro_ruby/version.rb",
3434
"spec/spec_helper.rb",
35-
"spec/fraudlabspro_ruby_spec.rb"
35+
"spec/fraudlabspro_ruby_fraudvalidation_spec.rb"
36+
"spec/fraudlabspro_ruby_smsverification_spec.rb"
3637
]
3738
end
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2+
3+
describe "FraudlabsproRuby" do
4+
it "work correctly with invalid Api Key" do
5+
FraudlabsproRuby::Configuration.api_key = ''
6+
result = FraudlabsproRuby::Api::Order.validate(
7+
ip: '8.8.8.8'
8+
)
9+
data = JSON.parse(result.body)
10+
expect(data['fraudlabspro_message']).to eq 'INVALID API KEY'
11+
end
12+
13+
it "work correctly with Api Key exist" do
14+
if $test_api_key == 'YOUR_API_KEY'
15+
print "/*
16+
* You could enter a FraudLabs Pro API Key in spec/spec_helper.rb
17+
* for real web service calling test.
18+
*
19+
* You could sign up for a free API key at https://www.fraudlabspro.com/pricing
20+
* if you do not have one.
21+
*/"
22+
expect($test_api_key).to eq 'YOUR_API_KEY'
23+
else
24+
expect($test_api_key).to_not eq 'YOUR_API_KEY'
25+
end
26+
end
27+
28+
it "work correctly with validate order" do
29+
FraudlabsproRuby::Configuration.api_key = $test_api_key
30+
result = FraudlabsproRuby::Api::Order.validate(
31+
ip: '8.8.8.8'
32+
)
33+
data = JSON.parse(result.body)
34+
if $test_api_key == 'YOUR_API_KEY'
35+
expect(data['fraudlabspro_id']).to eq 'NA'
36+
else
37+
expect(data['ip_country']).to eq 'US'
38+
end
39+
end
40+
41+
it "work correctly with get transaction" do
42+
FraudlabsproRuby::Configuration.api_key = $test_api_key
43+
result = FraudlabsproRuby::Api::Order.getTransaction(
44+
transaction_id: '20180713-ZNVPV4',
45+
id_type: FraudlabsproRuby::Api::Order::FLP_ID
46+
)
47+
data = JSON.parse(result.body)
48+
expect(data['fraudlabspro_id']).to eq 'NA'
49+
end
50+
51+
it "work correctly with validate order" do
52+
FraudlabsproRuby::Configuration.api_key = $test_api_key
53+
result = FraudlabsproRuby::Api::Order.feedback(
54+
transaction_id: '20180713-ZNVPV4',
55+
status: FraudlabsproRuby::Api::Order::APPROVE
56+
)
57+
data = JSON.parse(result.body)
58+
if $test_api_key == 'YOUR_API_KEY'
59+
expect(data['fraudlabspro_message']).to eq 'INVALID API KEY'
60+
else
61+
expect(data['fraudlabspro_message']).to eq 'INVALID TRANSACTION ID'
62+
end
63+
end
64+
65+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2+
3+
describe "FraudlabsproRuby" do
4+
it "work correctly with send sms" do
5+
FraudlabsproRuby::Configuration.api_key = $test_api_key
6+
result = FraudlabsproRuby::Api::SMSVerification.sendSMS(
7+
tel: '+123456789',
8+
mesg: 'Hi, your OTP is <otp>.',
9+
otp_timeout: 3600,
10+
country_code: 'US'
11+
)
12+
data = JSON.parse(result.body)
13+
if $test_api_key == 'YOUR_API_KEY'
14+
expect(data['error']).to eq 'API key not found.'
15+
else
16+
expect(data['error']).to eq 'Invalid phone number.'
17+
end
18+
end
19+
20+
it "work correctly with verify otp" do
21+
FraudlabsproRuby::Configuration.api_key = $test_api_key
22+
result = FraudlabsproRuby::Api::SMSVerification.verifySMS(
23+
tran_id: 'UNIQUE_TRANS_ID',
24+
otp: 'OTP_RECEIVED'
25+
)
26+
data = JSON.parse(result.body)
27+
if $test_api_key == 'YOUR_API_KEY'
28+
expect(data['error']).to eq 'API key not found.'
29+
else
30+
expect(data['error']).to eq 'Invalid OTP.'
31+
end
32+
end
33+
34+
end

spec/fraudlabspro_ruby_spec.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

spec/spec_helper.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
$LOAD_PATH.unshift(File.dirname(__FILE__))
33
require 'rspec'
44
require 'fraudlabspro_ruby'
5+
require 'json'
56

67
# Requires supporting files with custom matchers and macros, etc,
78
# in ./support/ and its subdirectories.
@@ -10,4 +11,5 @@
1011
RSpec.configure do |config|
1112

1213
end
13-
require 'awesome_print'
14+
15+
$test_api_key = 'YOUR_API_KEY'

0 commit comments

Comments
 (0)