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