rocketgate-ruby 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe RocketGate::Request do
4
+ describe '.new' do
5
+ subject { RocketGate::Request.new(transaction) }
6
+
7
+ let(:transaction) { double(:transaction) }
8
+
9
+ it 'sets the transaction' do
10
+ expect(subject.transaction).to eq transaction
11
+ end
12
+ end
13
+
14
+ describe '#base_parameters' do
15
+ subject { request.base_parameters }
16
+ let(:request) { RocketGate::Request.new }
17
+
18
+ before { config.testing! }
19
+
20
+ let(:config) { RocketGate.configuration }
21
+
22
+ it 'returns a hash that respects configuration' do
23
+ expect(subject[:version]).to eq 'R1.2'
24
+ expect(subject[:merchantID]).to eq '1'
25
+ expect(subject[:merchantPassword]).to eq 'testpassword'
26
+ expect(subject[:avsCheck]).to eq 'YES'
27
+ expect(subject[:cvv2Check]).to eq 'YES'
28
+ expect(subject[:scrub]).to eq 'YES'
29
+ end
30
+
31
+ context 'when the transaction is referenced' do
32
+ before { request.transaction = double(:transaction, is_referenced?: true) }
33
+
34
+ it 'does not include AVS, CVV or Scrub configuration' do
35
+ expect(subject[:version]).to eq 'R1.2'
36
+ expect(subject[:merchantID]).to eq '1'
37
+ expect(subject[:merchantPassword]).to eq 'testpassword'
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '#build_gateway_request' do
43
+ subject { RocketGate::Request.new(transaction).build_gateway_request }
44
+ let(:transaction) do
45
+ RocketGate::Transaction.new.tap do |tx|
46
+ tx.amount = 10.97
47
+ tx.currency = 'GBP'
48
+ tx.id = 'abbb2170-6a71-4d96-aa8f-ceb8b7d1a7ca'
49
+
50
+ tx.customer = RocketGate::Customer.new.tap do |cust|
51
+ cust.id = 'Customer-1'
52
+ cust.first_name = 'Test'
53
+ cust.last_name = 'Person'
54
+ cust.street_address = '123 Fake Street'
55
+ cust.city = 'Beverly Hills'
56
+ cust.state = 'CA'
57
+ cust.postal_code = '90210'
58
+ cust.country = 'US'
59
+ cust.email = 'test@example.com'
60
+ cust.ip_address = '127.0.0.1'
61
+ end
62
+
63
+ tx.credit_card = RocketGate::CreditCard.new.tap do |cc|
64
+ cc.number = '4111111111111111'
65
+ cc.exp_month = '02'
66
+ cc.exp_year = '2015'
67
+ cc.cvv = '999'
68
+ end
69
+ end
70
+ end
71
+
72
+ before do
73
+ RocketGate.configuration.testing!
74
+ RocketGate.configuration.require_avs = false
75
+ end
76
+
77
+ it 'matches the expected xml output' do
78
+ expected = %Q{<?xml version="1.0" encoding="UTF-8"?><gatewayRequest><version>R1.2</version><merchantID>1</merchantID><merchantPassword>testpassword</merchantPassword><avsCheck>IGNORE</avsCheck><cvv2Check>YES</cvv2Check><scrub>YES</scrub><amount>10.97</amount><currency>GBP</currency><merchantInvoiceID>abbb2170-6a71-4d96-aa8f-ceb8b7d1a7ca</merchantInvoiceID><transactionType>CC_AUTH</transactionType><cardNo>4111111111111111</cardNo><expireMonth>02</expireMonth><expireYear>2015</expireYear><cvv2>999</cvv2><merchantCustomerID>Customer-1</merchantCustomerID><customerFirstName>Test</customerFirstName><customerLastName>Person</customerLastName><billingAddress>123 Fake Street</billingAddress><billingCity>Beverly Hills</billingCity><billingState>CA</billingState><billingZipCode>90210</billingZipCode><billingCountry>US</billingCountry><email>test@example.com</email><ipAddress>127.0.0.1</ipAddress></gatewayRequest>}
79
+ expect(subject).to eq expected
80
+ end
81
+ end
82
+
83
+ describe '#yes_or_ignore' do
84
+ it 'returns yes for true' do
85
+ expect(RocketGate::Request.new.yes_or_ignore(true)).to eq 'YES'
86
+ end
87
+
88
+ it 'returns ignore for false' do
89
+ expect(RocketGate::Request.new.yes_or_ignore(false)).to eq 'IGNORE'
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,190 @@
1
+ require 'spec_helper'
2
+
3
+ describe RocketGate::Response do
4
+ before { RocketGate.configuration.testing! }
5
+
6
+ let(:xml) { '<?xml version="1.0" encoding="UTF-8"?><gatewayResponse><cardType>VISA</cardType><approvedAmount>9.99</approvedAmount><retrievalNo>1000148e87eab19</retrievalNo><approvedCurrency>USD</approvedCurrency><reasonCode>0</reasonCode><merchantAccount>1</merchantAccount><version>1.0</version><cardLastFour>1111</cardLastFour><cardHash>m77xlHZiPKVsF9p1/VdzTb+CUwaGBDpuSRxtcb7+j24=</cardHash><guidNo>1000148E87EAB19</guidNo><responseCode>0</responseCode><authNo>892343</authNo><cardExpiration>0210</cardExpiration><payType>CREDIT</payType></gatewayResponse>' }
7
+
8
+ describe '.from_xml' do
9
+ subject { RocketGate::Response.from_xml(xml) }
10
+ let(:response) { RocketGate::Response.new }
11
+
12
+ it 'builds a new instance with the xml document' do
13
+ expect(RocketGate::Response).to receive(:new).and_return(response)
14
+ expect(Nokogiri).to receive(:parse).with(xml).and_call_original
15
+ expect(response).to receive(:xml_document=).with(an_instance_of(Nokogiri::XML::Document))
16
+ expect(response).to receive(:build!)
17
+ subject
18
+ end
19
+ end
20
+
21
+ describe '#build!' do
22
+ subject { response.build! }
23
+ let(:response) { RocketGate::Response.new.tap{|r| r.xml_document = Nokogiri.parse(xml) } }
24
+ let(:authorization) { RocketGate::Authorization.new }
25
+
26
+ before { allow(RocketGate::Authorization).to receive(:new).and_return(authorization) }
27
+
28
+ it 'fills in the response code' do
29
+ expect{subject}.to change{response.response_code}.from(nil).to(:success)
30
+ end
31
+
32
+ it 'builds an authorization' do
33
+ expect{subject}.to change{response.authorization}
34
+ .from(nil).to(authorization)
35
+
36
+ expect(authorization.approved_amount).to eq 9.99
37
+ expect(authorization.approved_currency).to eq 'USD'
38
+ expect(authorization.auth_code).to eq '892343'
39
+ expect(authorization.avs_response).to be_nil
40
+ expect(authorization.card_expiration).to eq '0210'
41
+ expect(authorization.card_hash).to eq 'm77xlHZiPKVsF9p1/VdzTb+CUwaGBDpuSRxtcb7+j24='
42
+ expect(authorization.card_last_four).to eq '1111'
43
+ expect(authorization.cvv_response).to be_nil
44
+ expect(authorization.reason_code).to eq :success
45
+ expect(authorization.reference_id).to eq '1000148E87EAB19'
46
+ end
47
+ end
48
+
49
+ describe '#confirm!' do
50
+ subject { response.confirm! }
51
+ let(:response) { RocketGate::Response.from_xml(xml) }
52
+
53
+ before do
54
+ allow(response).to receive(:success?).and_return(success)
55
+ allow(RocketGate).to receive(:send_request!).and_return(:ok)
56
+ end
57
+
58
+ context 'when the request was successful' do
59
+ let(:success) { true }
60
+ let(:transaction) { RocketGate::Transaction.new }
61
+
62
+ before { allow(RocketGate::Transaction).to receive(:new).and_return(transaction) }
63
+
64
+ it 'builds a confirmation transaction' do
65
+ expect(RocketGate::Transaction).to receive(:new)
66
+ expect(transaction).to receive(:reference_id=)
67
+ .with('1000148E87EAB19').and_call_original
68
+ expect(transaction).to receive(:type=)
69
+ .with(RocketGate::Transaction::TYPE[:confirmation]).and_call_original
70
+ expect(RocketGate::Request).to receive(:new)
71
+ .with(transaction).and_call_original
72
+
73
+ subject
74
+ end
75
+
76
+ it 'sends the confirmation transaction' do
77
+ expect(RocketGate).to receive(:send_request!).with(an_instance_of(RocketGate::Request))
78
+ subject
79
+ end
80
+
81
+ it 'returns the confirmation response' do
82
+ allow(RocketGate).to receive(:send_request!).and_return(response)
83
+ expect(subject).to eq response
84
+ end
85
+ end
86
+
87
+ context 'when the request was not successful' do
88
+ let(:success) { false }
89
+
90
+ it 'raises an error' do
91
+ expect{subject}.to raise_error(RocketGate::AuthorizationError, 'Unable to confirm unauthorized transaction')
92
+ end
93
+ end
94
+ end
95
+
96
+ describe '#authorized?' do
97
+ subject { response.authorized? }
98
+ let(:response) { RocketGate::Response.new }
99
+
100
+ context 'when there is a successful authorization' do
101
+ before { response.authorization = double(:authorization, success?: true) }
102
+
103
+ it 'returns true' do
104
+ expect(subject).to be true
105
+ end
106
+ end
107
+
108
+ context 'when there is an unsuccessful authorization' do
109
+ before { response.authorization = double(:authorization, success?: false) }
110
+
111
+ it 'returns true' do
112
+ expect(subject).to be false
113
+ end
114
+ end
115
+
116
+ context 'when there is no authorization' do
117
+ before { response.authorization = nil }
118
+
119
+ it 'returns true' do
120
+ expect(subject).to be false
121
+ end
122
+ end
123
+ end
124
+
125
+ describe '#success?' do
126
+ subject { response.success? }
127
+ let(:response) { RocketGate::Response.new }
128
+
129
+ before do
130
+ allow(response).to receive(:authorized?).and_return(authorized)
131
+ response.response_code = response_code
132
+ end
133
+
134
+ context 'when the request was authorized' do
135
+ let(:authorized) { true }
136
+ let(:response_code) { :success }
137
+
138
+ it 'returns true' do
139
+ expect(subject).to be true
140
+ end
141
+ end
142
+
143
+ context 'when the request was not authorized' do
144
+ let(:authorized) { false }
145
+ let(:response_code) { :success }
146
+
147
+ it 'returns false' do
148
+ expect(subject).to be false
149
+ end
150
+ end
151
+
152
+ context 'when the request was not successful' do
153
+ let(:authorized) { true }
154
+ let(:response_code) { :bank_decline }
155
+
156
+ it 'returns false' do
157
+ expect(subject).to be false
158
+ end
159
+ end
160
+ end
161
+
162
+ describe '#find_value' do
163
+ subject { response.send(:find_value, key) }
164
+ let(:response) { RocketGate::Response.from_xml(xml) }
165
+
166
+ context 'when the key is present' do
167
+ let(:key) { 'authNo' }
168
+
169
+ it 'returns the corresponding value' do
170
+ expect(subject).to eq '892343'
171
+ end
172
+ end
173
+
174
+ context 'when the key is not present' do
175
+ let(:key) { 'missingKey' }
176
+
177
+ it 'returns nothing' do
178
+ expect(subject).to be_nil
179
+ end
180
+ end
181
+
182
+ context 'when the response is not what we expect' do
183
+ let(:xml) { '<?xml version="1.0" encoding="UTF-8"?><unexpectedDocument />' }
184
+
185
+ it 'raises an error' do
186
+ expect{subject}.to raise_error(RocketGate::GatewayResponseError, 'Unexpected response format')
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe RocketGate do
4
+ describe '.configuration' do
5
+ subject { RocketGate.configuration }
6
+
7
+ context 'when configuration is available' do
8
+ before { RocketGate.configure {|c| c.merchant_id = '123' } }
9
+
10
+ it 'returns it' do
11
+ expect(RocketGate::Configuration).not_to receive(:new)
12
+ expect(subject.merchant_id).to eq '123'
13
+ end
14
+ end
15
+
16
+ context 'when configuration is not available' do
17
+ before { RocketGate.reset! }
18
+
19
+ it 'supplies a default config' do
20
+ expect(subject.request_host).to eq RocketGate::Configuration::GATEWAY_LIVE_HOST
21
+ end
22
+ end
23
+ end
24
+
25
+ describe '.configure' do
26
+ subject { RocketGate.configure {|c| c.require_avs = false } }
27
+ let(:config) { RocketGate.configuration }
28
+
29
+ it 'applies settings from a config block' do
30
+ expect{subject}.to change{config.require_avs}.from(true).to(false)
31
+ end
32
+ end
33
+
34
+ describe '.connection' do
35
+ subject { RocketGate.connection }
36
+ let(:config) { RocketGate.configuration }
37
+
38
+ before { config.testing! }
39
+
40
+ it 'validates the configuration' do
41
+ expect(config).to receive(:validate!)
42
+ subject
43
+ end
44
+
45
+ it 'returns a connection' do
46
+ expect(RocketGate::Connection).to receive(:new)
47
+ .with(config.request_host, config.request_port, config.request_path)
48
+ .and_call_original
49
+ expect(subject).to be_an_instance_of(RocketGate::Connection)
50
+ end
51
+ end
52
+
53
+ describe '.reset!' do
54
+ subject { RocketGate.reset! }
55
+ before do
56
+ RocketGate.configuration.testing!
57
+ RocketGate.connection
58
+ end
59
+
60
+ it 'clears the memoized configuration' do
61
+ expect(RocketGate.instance_variable_get(:@configuration)).not_to be_nil
62
+ subject
63
+ expect(RocketGate.instance_variable_get(:@configuration)).to be_nil
64
+ end
65
+
66
+ it 'clears the memoized connection' do
67
+ expect(RocketGate.instance_variable_get(:@connection)).not_to be_nil
68
+ subject
69
+ expect(RocketGate.instance_variable_get(:@connection)).to be_nil
70
+ end
71
+ end
72
+
73
+ describe '.send_request!' do
74
+ subject { RocketGate.send_request!(request) }
75
+
76
+ before do
77
+ RocketGate.configuration.testing!
78
+ allow(RocketGate.connection).to receive(:make_request!).and_return(response)
79
+ end
80
+
81
+ let(:request) { double(:request, build_gateway_request: 'request') }
82
+ let(:response) { double(:response, code: 200, body: xml) }
83
+ let(:xml) { '<?xml version="1.0" encoding="UTF-8"?><gatewayResponse><cardType>VISA</cardType><approvedAmount>9.99</approvedAmount><retrievalNo>1000148e87eab19</retrievalNo><approvedCurrency>USD</approvedCurrency><reasonCode>0</reasonCode><merchantAccount>1</merchantAccount><version>1.0</version><cardLastFour>1111</cardLastFour><cardHash>m77xlHZiPKVsF9p1/VdzTb+CUwaGBDpuSRxtcb7+j24=</cardHash><guidNo>1000148E87EAB19</guidNo><responseCode>0</responseCode><authNo>892343</authNo><cardExpiration>0210</cardExpiration><payType>CREDIT</payType></gatewayResponse>' }
84
+
85
+ it 'sends the request via the connection' do
86
+ expect(RocketGate.connection).to receive(:make_request!).with('request')
87
+ subject
88
+ end
89
+
90
+ it 'builds a response object from the parsed body' do
91
+ expect(RocketGate::Response).to receive(:from_xml).with(xml).and_call_original
92
+
93
+ subject
94
+ end
95
+
96
+ it 'does not raise an error' do
97
+ expect{subject}.not_to raise_error
98
+ end
99
+
100
+ context 'when the request was unsuccessful' do
101
+ before { allow(response).to receive(:code).and_return(500) }
102
+
103
+ it 'raises an error' do
104
+ expect{subject}.to raise_error(RocketGate::GatewayRequestError, 'Unexpected status code in gateway response: 500')
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,9 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'pry'
5
+ require 'rocketgate'
6
+
7
+ RSpec.configure do |config|
8
+ config.before(:each) { RocketGate.reset! }
9
+ end
@@ -0,0 +1,250 @@
1
+ require 'spec_helper'
2
+
3
+ describe RocketGate::Transaction do
4
+ describe '.new' do
5
+ let(:customer) { double(:customer) }
6
+ let(:credit_card) { double(:credit_card) }
7
+
8
+ it 'accepts an arbitrary set of arguments and assigns them to certain attributes' do
9
+ transaction = RocketGate::Transaction.new(12.34, customer, credit_card, 'GBP')
10
+ expect(transaction.amount).to eq 12.34
11
+ expect(transaction.customer).to eq customer
12
+ expect(transaction.credit_card).to eq credit_card
13
+ expect(transaction.currency).to eq 'GBP'
14
+ end
15
+ end
16
+
17
+ describe '#credit_card_hash' do
18
+ subject { transaction.credit_card_hash }
19
+ let(:transaction) do
20
+ RocketGate::Transaction.new.tap {|tx| tx.credit_card = credit_card }
21
+ end
22
+ let(:credit_card) { double(:credit_card) }
23
+
24
+ it 'delegates to the credit card' do
25
+ expect(credit_card).to receive(:to_hash)
26
+ subject
27
+ end
28
+ end
29
+
30
+ describe '#customer_hash' do
31
+ subject { transaction.customer_hash }
32
+ let(:transaction) do
33
+ RocketGate::Transaction.new.tap {|tx| tx.customer = customer }
34
+ end
35
+ let(:customer) { double(:customer) }
36
+
37
+ it 'delegates to the customer' do
38
+ expect(customer).to receive(:to_hash)
39
+ subject
40
+ end
41
+ end
42
+
43
+ describe '#id' do
44
+ let(:transaction) { RocketGate::Transaction.new }
45
+
46
+ it 'returns the supplied ID when set' do
47
+ transaction.id = 'abc123'
48
+ expect(transaction.id).to eq 'abc123'
49
+ end
50
+
51
+ it 'generates a random UUID when not set' do
52
+ expect(SecureRandom).to receive(:uuid).and_return('def456')
53
+ expect(transaction.id).to eq 'def456'
54
+ end
55
+ end
56
+
57
+ describe '#is_referenced?' do
58
+ let(:transaction) do
59
+ RocketGate::Transaction.new.tap do |tx|
60
+ tx.reference_id = 'abc123'
61
+ tx.type = type
62
+ end
63
+ end
64
+
65
+ context 'when it is a ticket transaction' do
66
+ let(:type) { RocketGate::Transaction::TYPE[:ticket] }
67
+
68
+ it 'returns true' do
69
+ expect(transaction.is_referenced?).to eq true
70
+ end
71
+ end
72
+
73
+ context 'when it is a void transaction' do
74
+ let(:type) { RocketGate::Transaction::TYPE[:void] }
75
+
76
+ it 'returns true' do
77
+ expect(transaction.is_referenced?).to eq true
78
+ end
79
+ end
80
+
81
+ context 'when it is not a referenced transaction' do
82
+ let(:type) { RocketGate::Transaction::TYPE[:auth] }
83
+
84
+ it 'returns true' do
85
+ expect(transaction.is_referenced?).to eq false
86
+ end
87
+ end
88
+ end
89
+
90
+ describe '#type' do
91
+ let(:transaction) { RocketGate::Transaction.new }
92
+
93
+ it 'returns auth type by default' do
94
+ expect(transaction.type).to eq RocketGate::Transaction::TYPE[:auth]
95
+ end
96
+
97
+ it 'returns the assigned value when set' do
98
+ transaction.type = RocketGate::Transaction::TYPE[:purchase]
99
+ expect(transaction.type).to eq RocketGate::Transaction::TYPE[:purchase]
100
+ end
101
+ end
102
+
103
+ describe '#type=' do
104
+ let(:transaction) { RocketGate::Transaction.new }
105
+
106
+ it 'converts symbols to their associated string values' do
107
+ transaction.type = :auth
108
+ expect(transaction.type).to eq RocketGate::Transaction::TYPE[:auth]
109
+ end
110
+
111
+ it 'raises an error if an unknown type is specified' do
112
+ expect{ transaction.type = :fake_type }.to raise_error(RocketGate::ValidationError, 'Unknown transaction type: fake_type')
113
+ expect{ transaction.type = 'FAKETYPE' }.to raise_error(RocketGate::ValidationError, 'Unknown transaction type: FAKETYPE')
114
+ end
115
+ end
116
+
117
+ describe '#to_hash' do
118
+ context 'when it is a standard transaction' do
119
+ let(:transaction) do
120
+ RocketGate::Transaction.new.tap do |tx|
121
+ tx.id = '90c3e1d8-14f0-4aea-9eda-a7a59396e264'
122
+ tx.amount = 12.34
123
+ tx.type = RocketGate::Transaction::TYPE[:auth]
124
+
125
+ tx.customer = RocketGate::Customer.new.tap do |cust|
126
+ cust.id = '07f7b231-9b29-46d4-9c19-cd6790e712b5'
127
+ cust.first_name = 'Test'
128
+ cust.last_name = 'Person'
129
+ cust.street_address = '123 Fake Street'
130
+ cust.city = 'Beverly Hills'
131
+ cust.state = 'CA'
132
+ cust.postal_code = '90210'
133
+ cust.country = 'US'
134
+ cust.email = 'test@example.com'
135
+ cust.username = 'tester'
136
+ cust.ip_address = '127.0.0.1'
137
+ end
138
+
139
+ tx.credit_card = RocketGate::CreditCard.new.tap do |cc|
140
+ cc.number = '4111111111111111'
141
+ cc.exp_month = '01'
142
+ cc.exp_year = '2020'
143
+ cc.cvv = '999'
144
+ end
145
+ end
146
+ end
147
+
148
+ let(:expected) do
149
+ {
150
+ cardNo: '4111111111111111',
151
+ expireMonth: '01',
152
+ expireYear: '2020',
153
+ cvv2: '999',
154
+ amount: 12.34,
155
+ currency: 'USD',
156
+ merchantCustomerID: '07f7b231-9b29-46d4-9c19-cd6790e712b5',
157
+ merchantInvoiceID: '90c3e1d8-14f0-4aea-9eda-a7a59396e264',
158
+ customerFirstName: 'Test',
159
+ customerLastName: 'Person',
160
+ billingAddress: '123 Fake Street',
161
+ billingCity: 'Beverly Hills',
162
+ billingState: 'CA',
163
+ billingZipCode: '90210',
164
+ billingCountry: 'US',
165
+ email: 'test@example.com',
166
+ username: 'tester',
167
+ ipAddress: '127.0.0.1',
168
+ referenceGUID: nil,
169
+ transactionType: 'CC_AUTH'
170
+ }
171
+ end
172
+
173
+ it 'returns a hash of the transaction attributes' do
174
+ expect(transaction.to_hash).to eq expected
175
+ end
176
+ end
177
+
178
+ context 'when it is a ticket transaction' do
179
+ let(:transaction) do
180
+ RocketGate::Transaction.new.tap do |tx|
181
+ tx.reference_id = 'abc123'
182
+ tx.type = RocketGate::Transaction::TYPE[:ticket]
183
+ end
184
+ end
185
+
186
+ let(:expected) do
187
+ { referenceGUID: 'abc123', transactionType: 'CC_TICKET' }
188
+ end
189
+
190
+ it 'returns only the reference id and type' do
191
+ expect(transaction.to_hash).to eq expected
192
+ end
193
+ end
194
+
195
+ context 'when it is a void transaction' do
196
+ let(:transaction) do
197
+ RocketGate::Transaction.new.tap do |tx|
198
+ tx.reference_id = 'abc123'
199
+ tx.type = RocketGate::Transaction::TYPE[:void]
200
+ end
201
+ end
202
+
203
+ let(:expected) do
204
+ { referenceGUID: 'abc123', transactionType: 'CC_VOID' }
205
+ end
206
+
207
+ it 'returns only the reference id and type' do
208
+ expect(transaction.to_hash).to eq expected
209
+ end
210
+ end
211
+
212
+ context 'when it is a confirmation' do
213
+ let(:transaction) do
214
+ RocketGate::Transaction.new.tap do |tx|
215
+ tx.reference_id = 'abc123'
216
+ tx.type = RocketGate::Transaction::TYPE[:confirmation]
217
+ end
218
+ end
219
+
220
+ let(:expected) do
221
+ { referenceGUID: 'abc123', transactionType: 'CC_CONFIRM' }
222
+ end
223
+
224
+ it 'returns only the reference id and type' do
225
+ expect(transaction.to_hash).to eq expected
226
+ end
227
+ end
228
+ end
229
+
230
+ describe '#valid?' do
231
+ subject { transaction.valid? }
232
+ context 'when it is a referenced transaction' do
233
+ let(:transaction) { RocketGate::Transaction.new }
234
+ before { allow(transaction).to receive(:is_referenced?).and_return(true) }
235
+
236
+ it 'bypasses normal validation rules' do
237
+ expect(subject).to be true
238
+ end
239
+ end
240
+
241
+ context 'when it is a standard transaction' do
242
+ let(:transaction) { RocketGate::Transaction.new }
243
+ before { allow(transaction).to receive(:is_referenced?).and_return(false) }
244
+
245
+ it 'defers to normal validation rules' do
246
+ expect(subject).to be false
247
+ end
248
+ end
249
+ end
250
+ end