forked from AuthorizeNet/sdk-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsim_spec.rb
97 lines (80 loc) · 3.46 KB
/
sim_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
require "spec_helper"
describe AuthorizeNet::SIM::Transaction do
before :all do
begin
creds = YAML.load_file(File.dirname(__FILE__) + "/credentials.yml")
@api_key = creds['api_transaction_key']
@api_login = creds['api_login_id']
rescue Errno::ENOENT => e
@api_key = "TEST"
@api_login = "TEST"
warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
end
end
before do
@amount = 10.00
@fingerprint = 'a8ea7b27729daf76d4a67bdb7d0a2fa3'
@sequence = '123456789'
@timestamp = '987654321'
end
it "should support instantiation" do
AuthorizeNet::SIM::Transaction.new(@api_login, @api_key, @amount).should be_instance_of(AuthorizeNet::SIM::Transaction)
end
it "should generate a correct fingerprint" do
transaction = AuthorizeNet::SIM::Transaction.new('TEST', 'TEST', @amount, :sequence => @sequence, :timestamp => @timestamp)
transaction.fingerprint.should == @fingerprint
end
it "should provide the actual values used to build the fingerprint" do
transaction = AuthorizeNet::SIM::Transaction.new('TEST', 'TEST', @amount)
hash = transaction.fingerprint_fields
transaction2 = AuthorizeNet::SIM::Transaction.new('TEST', 'TEST', @amount, :sequence => hash[:fp_sequence], :timestamp => hash[:fp_timestamp])
hash[:fp_hash].should == transaction2.fingerprint
end
it "should provide a hash of all the form fields, ready for conversion to HTML" do
transaction = AuthorizeNet::SIM::Transaction.new('TEST', 'TEST', @amount)
transaction.form_fields.should be_kind_of(Hash)
transaction.form_fields.should have_key(:x_fp_hash)
end
it "should know if its in test mode" do
transaction = AuthorizeNet::SIM::Transaction.new(@api_login, @api_key, @amount, :test => true)
transaction.test?.should be_truthy
transaction = AuthorizeNet::SIM::Transaction.new(@api_login, @api_key, @amount, :test => false)
transaction.test?.should be_falsey
end
end
describe AuthorizeNet::SIM::Response do
before :all do
begin
creds = YAML.load_file(File.dirname(__FILE__) + "/credentials.yml")
@api_key = creds['api_transaction_key']
@api_login = creds['api_login_id']
rescue Errno::ENOENT => e
@api_key = "TEST"
@api_login = "TEST"
warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
end
end
before do
@amount = (rand(10000) + 100) / 100.0
@fingerprint = 'a8ea7b27729daf76d4a67bdb7d0a2fa3'
@sequence = '123456789'
@timestamp = '987654321'
end
it "should support instantiation" do
AuthorizeNet::SIM::Response.new('').should be_instance_of(AuthorizeNet::SIM::Response)
end
it "should support parsing the response into fields" do
response = AuthorizeNet::SIM::Response.new('x_first_name=John&x_last_name=Doe')
response.fields.should have_key(:first_name)
response.fields.should have_key(:last_name)
end
it "should be able to build a Direct Post Method URL with fields from the response" do
response = AuthorizeNet::SIM::Response.new('x_first_name=John&x_last_name=Doe')
response.direct_post_url('http://www.example.com/').should == 'http://www.example.com/?x_first_name=John&x_last_name=Doe'
end
end
describe AuthorizeNet::SIM::HostedPaymentForm do
it "should support instantiation" do
AuthorizeNet::SIM::HostedPaymentForm.new().should be_instance_of(AuthorizeNet::SIM::HostedPaymentForm)
end
end