sage_pay 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,231 @@
1
+ require 'spec_helper'
2
+
3
+ include SagePay::Server
4
+
5
+ describe TransactionRegistrationResponse do
6
+ it "should work straight from the factory" do
7
+ lambda {
8
+ transaction_registration_response_factory.should_not be_nil
9
+ }.should_not raise_error
10
+ end
11
+
12
+ describe ".from_response_body" do
13
+ context "with an invalid response" do
14
+ before(:each) do
15
+ @response_body = <<-RESPONSE
16
+ VPSProtocol=2.23
17
+ Status=INVALID
18
+ StatusDetail=4000 : The VendorName is invalid or the account is not active.
19
+ RESPONSE
20
+ @response = TransactionRegistrationResponse.from_response_body(@response_body)
21
+ end
22
+
23
+ it "should successfully parse the body" do
24
+ lambda {
25
+ TransactionRegistrationResponse.from_response_body(@response_body)
26
+ }.should_not raise_error
27
+ end
28
+
29
+ it "should report the vps_protocol as '2.23'" do
30
+ @response.vps_protocol.should == "2.23"
31
+ end
32
+
33
+ it "should report the status as :invalid" do
34
+ @response.status.should == :invalid
35
+ end
36
+
37
+ it "should report the status detail as the status detail message supplied" do
38
+ @response.status_detail.should == "4000 : The VendorName is invalid or the account is not active."
39
+ end
40
+
41
+ it "should admit to being invalid" do
42
+ @response.should be_invalid
43
+ end
44
+
45
+ it "should admit to having failed" do
46
+ @response.should be_failed
47
+ end
48
+
49
+ it "should raise an error if we try to ask for the transaction id" do
50
+ lambda {
51
+ @response.vps_tx_id
52
+ }.should raise_error RuntimeError, "Unable to retrieve the transaction id as the status was not OK."
53
+ end
54
+
55
+ it "should raise an error if we try to ask for the security key" do
56
+ lambda {
57
+ @response.security_key
58
+ }.should raise_error RuntimeError, "Unable to retrieve the security key as the status was not OK."
59
+ end
60
+
61
+ it "should raise an error if we try to ask for the next URL" do
62
+ lambda {
63
+ @response.next_url
64
+ }.should raise_error RuntimeError, "Unable to retrieve the next URL as the status was not OK."
65
+ end
66
+ end
67
+
68
+ context "with a malformed response" do
69
+ before(:each) do
70
+ @response_body = <<-RESPONSE
71
+ VPSProtocol=2.23
72
+ Status=MALFORMED
73
+ StatusDetail=5000 : Your request had too many toes.
74
+ RESPONSE
75
+ @response = TransactionRegistrationResponse.from_response_body(@response_body)
76
+ end
77
+
78
+ it "should successfully parse the body" do
79
+ lambda {
80
+ TransactionRegistrationResponse.from_response_body(@response_body)
81
+ }.should_not raise_error
82
+ end
83
+
84
+ it "should report the vps_protocol as '2.23'" do
85
+ @response.vps_protocol.should == "2.23"
86
+ end
87
+
88
+ it "should report the status as :malformed" do
89
+ @response.status.should == :malformed
90
+ end
91
+
92
+ it "should report the status detail as the status detail message supplied" do
93
+ @response.status_detail.should == "5000 : Your request had too many toes."
94
+ end
95
+
96
+ it "should admit to being malformed" do
97
+ @response.should be_malformed
98
+ end
99
+
100
+ it "should admit to having failed" do
101
+ @response.should be_failed
102
+ end
103
+
104
+ it "should raise an error if we try to ask for the transaction id" do
105
+ lambda {
106
+ @response.vps_tx_id
107
+ }.should raise_error RuntimeError, "Unable to retrieve the transaction id as the status was not OK."
108
+ end
109
+
110
+ it "should raise an error if we try to ask for the security key" do
111
+ lambda {
112
+ @response.security_key
113
+ }.should raise_error RuntimeError, "Unable to retrieve the security key as the status was not OK."
114
+ end
115
+
116
+ it "should raise an error if we try to ask for the next URL" do
117
+ lambda {
118
+ @response.next_url
119
+ }.should raise_error RuntimeError, "Unable to retrieve the next URL as the status was not OK."
120
+ end
121
+ end
122
+
123
+ context "with an error response" do
124
+ before(:each) do
125
+ @response_body = <<-RESPONSE
126
+ VPSProtocol=2.23
127
+ Status=ERROR
128
+ StatusDetail=5000 : SagePay blew up.
129
+ RESPONSE
130
+ @response = TransactionRegistrationResponse.from_response_body(@response_body)
131
+ end
132
+
133
+ it "should successfully parse the body" do
134
+ lambda {
135
+ TransactionRegistrationResponse.from_response_body(@response_body)
136
+ }.should_not raise_error
137
+ end
138
+
139
+ it "should report the vps_protocol as '2.23'" do
140
+ @response.vps_protocol.should == "2.23"
141
+ end
142
+
143
+ it "should report the status as :error" do
144
+ @response.status.should == :error
145
+ end
146
+
147
+ it "should report the status detail as the status detail message supplied" do
148
+ @response.status_detail.should == "5000 : SagePay blew up."
149
+ end
150
+
151
+ it "should admit to being an error" do
152
+ @response.should be_error
153
+ end
154
+
155
+ it "should admit to having failed" do
156
+ @response.should be_failed
157
+ end
158
+
159
+ it "should raise an error if we try to ask for the transaction id" do
160
+ lambda {
161
+ @response.vps_tx_id
162
+ }.should raise_error RuntimeError, "Unable to retrieve the transaction id as the status was not OK."
163
+ end
164
+
165
+ it "should raise an error if we try to ask for the security key" do
166
+ lambda {
167
+ @response.security_key
168
+ }.should raise_error RuntimeError, "Unable to retrieve the security key as the status was not OK."
169
+ end
170
+
171
+ it "should raise an error if we try to ask for the next URL" do
172
+ lambda {
173
+ @response.next_url
174
+ }.should raise_error RuntimeError, "Unable to retrieve the next URL as the status was not OK."
175
+ end
176
+ end
177
+
178
+ context "with a valid response" do
179
+ before(:each) do
180
+ @response_body = <<-RESPONSE
181
+ VPSProtocol=2.23
182
+ Status=OK
183
+ StatusDetail=Server transaction registered successfully.
184
+ VPSTxId={728A5721-B45F-4570-937E-90A16B0A5000}
185
+ SecurityKey=17F13DCBD8
186
+ NextURL=https://test.sagepay.com/Simulator/VSPServerPaymentPage.asp?TransactionID={728A5721-B45F-4570-937E-90A16B0A5000}
187
+ RESPONSE
188
+
189
+ @response = TransactionRegistrationResponse.from_response_body(@response_body)
190
+ end
191
+
192
+ it "should successfully parse the body" do
193
+ lambda {
194
+ TransactionRegistrationResponse.from_response_body(@response_body)
195
+ }.should_not raise_error
196
+ end
197
+
198
+ it "should report the vps_protocol as '2.23'" do
199
+ @response.vps_protocol.should == "2.23"
200
+ end
201
+
202
+ it "should report the status as :OK" do
203
+ @response.status.should == :ok
204
+ end
205
+
206
+ it "should admit to being OK" do
207
+ @response.should be_ok
208
+ end
209
+
210
+ it "should not admit to being failed" do
211
+ @response.should_not be_failed
212
+ end
213
+
214
+ it "should report the status detail as the status detail message supplied" do
215
+ @response.status_detail.should == "Server transaction registered successfully."
216
+ end
217
+
218
+ it "should report the transaction id" do
219
+ @response.vps_tx_id.should == "{728A5721-B45F-4570-937E-90A16B0A5000}"
220
+ end
221
+
222
+ it "should report the security key" do
223
+ @response.security_key.should == "17F13DCBD8"
224
+ end
225
+
226
+ it "should report the next URL" do
227
+ @response.next_url.should == "https://test.sagepay.com/Simulator/VSPServerPaymentPage.asp?TransactionID={728A5721-B45F-4570-937E-90A16B0A5000}"
228
+ end
229
+ end
230
+ end
231
+ end