|
32 | 32 | end |
33 | 33 |
|
34 | 34 | describe "quik_pay_url" do |
35 | | - context "no arguments" do |
| 35 | + shared_examples "quik pay redirect parameters" do |
36 | 36 | it "generates a url with only default params" do |
37 | | - expect(controller.quik_pay_url).to match(/quikpay.*?orderNumber=.*&orderType=Temple%20Library&amountDue=.*&redirectUrl=.*&redirectUrlParameters=transactionStatus%2CtransactionTotalAmount%2CorderNumber×tamp=.*&hash=.*$/) |
| 37 | + expect(controller.quik_pay_url).to match(/quikpay.*?orderNumber=.*&orderType=Temple%20Library&amountDue=.*&redirectUrl=.*&redirectUrlParameters=#{redirect_params}×tamp=.*&hash=.*$/) |
38 | 38 | end |
39 | | - end |
40 | 39 |
|
41 | | - context "with param as args" do |
42 | 40 | it "does not diviate from the order URL contrat" do |
43 | | - expect(controller.quik_pay_url(foo: "bar")).to match(/quikpay.*?orderNumber=.*&orderType=Temple%20Library&amountDue=.*&redirectUrl=.*&redirectUrlParameters=transactionStatus%2CtransactionTotalAmount%2CorderNumber×tamp=.*&hash=.*$/) |
| 41 | + expect(controller.quik_pay_url(foo: "bar")).to match(/quikpay.*?orderNumber=.*&orderType=Temple%20Library&amountDue=.*&redirectUrl=.*&redirectUrlParameters=#{redirect_params}×tamp=.*&hash=.*$/) |
44 | 42 | end |
45 | | - end |
46 | 43 |
|
47 | | - context "with param as args + secret" do |
48 | 44 | it "generates a url with params" do |
49 | | - expect(controller.quik_pay_url({ foo: "bar" }, "buzz")).to match(/quikpay.*?orderNumber=.*&orderType=Temple%20Library&amountDue=.*&redirectUrl=.*&redirectUrlParameters=transactionStatus%2CtransactionTotalAmount%2CorderNumber×tamp=.*&hash=.*$/) |
| 45 | + expect(controller.quik_pay_url({ foo: "bar" }, "buzz")).to match(/quikpay.*?orderNumber=.*&orderType=Temple%20Library&amountDue=.*&redirectUrl=.*&redirectUrlParameters=#{redirect_params}×tamp=.*&hash=.*$/) |
50 | 46 | end |
51 | 47 | end |
| 48 | + |
| 49 | + context "when quik pay sessionless callback is disabled" do |
| 50 | + before { allow(Flipflop).to receive(:quik_pay_sessionless_callback?).and_return(false) } |
| 51 | + let(:redirect_params) { "transactionStatus%2CtransactionTotalAmount" } |
| 52 | + |
| 53 | + include_examples "quik pay redirect parameters" |
| 54 | + end |
| 55 | + |
| 56 | + context "when quik pay sessionless callback is enabled" do |
| 57 | + before { allow(Flipflop).to receive(:quik_pay_sessionless_callback?).and_return(true) } |
| 58 | + let(:redirect_params) { "transactionStatus%2CtransactionTotalAmount%2CorderNumber" } |
| 59 | + |
| 60 | + include_examples "quik pay redirect parameters" |
| 61 | + end |
52 | 62 | end |
53 | 63 |
|
54 | 64 | describe "GET #quik_pay_callback" do |
55 | | - context "user is not logged in but parameters are valid" do |
56 | | - let (:params) { with_validation_params(transactionStatus: "1") } |
57 | | - before(:each) do |
58 | | - resp = OpenStruct.new(total_sum: 0.0) |
59 | | - balance = Alma::PaymentResponse.new(resp) |
60 | | - allow(Alma::User).to receive(:send_payment) { balance } |
61 | | - end |
| 65 | + context "when quik pay sessionless callback is disabled" do |
| 66 | + before { allow(Flipflop).to receive(:quik_pay_sessionless_callback?).and_return(false) } |
| 67 | + |
| 68 | + context "user is not logged in" do |
| 69 | + it "redirects you to login page" do |
| 70 | + get :quik_pay_callback |
| 71 | + expect(response).to redirect_to new_user_session_path |
62 | 72 |
|
63 | | - it "redirects GET requests to the users account page with success notice" do |
64 | | - get(:quik_pay_callback, params:) |
65 | | - expect(response).to redirect_to users_account_path |
66 | | - expect(flash[:notice]).to include("Your fees have been paid."); |
| 73 | + post :quik_pay_callback |
| 74 | + expect(response).to redirect_to new_user_session_path |
| 75 | + end |
67 | 76 | end |
| 77 | + end |
| 78 | + |
| 79 | + context "when quik pay sessionless callback is enabled" do |
| 80 | + before { allow(Flipflop).to receive(:quik_pay_sessionless_callback?).and_return(true) } |
| 81 | + |
| 82 | + context "user is not logged in but parameters are valid" do |
| 83 | + let (:params) { with_validation_params(transactionStatus: "1") } |
| 84 | + before(:each) do |
| 85 | + resp = OpenStruct.new(total_sum: 0.0) |
| 86 | + balance = Alma::PaymentResponse.new(resp) |
| 87 | + allow(Alma::User).to receive(:send_payment) { balance } |
| 88 | + end |
| 89 | + |
| 90 | + it "redirects GET requests to the users account page with success notice" do |
| 91 | + get(:quik_pay_callback, params:) |
| 92 | + expect(response).to redirect_to users_account_path |
| 93 | + expect(flash[:notice]).to include("Your fees have been paid."); |
| 94 | + end |
68 | 95 |
|
69 | | - it "redirects POST requests to the users account page with success notice" do |
70 | | - post(:quik_pay_callback, params:) |
71 | | - expect(response).to redirect_to users_account_path |
72 | | - expect(flash[:notice]).to include("Your fees have been paid."); |
| 96 | + it "redirects POST requests to the users account page with success notice" do |
| 97 | + post(:quik_pay_callback, params:) |
| 98 | + expect(response).to redirect_to users_account_path |
| 99 | + expect(flash[:notice]).to include("Your fees have been paid."); |
| 100 | + end |
73 | 101 | end |
74 | 102 | end |
75 | 103 |
|
|
194 | 222 | end |
195 | 223 |
|
196 | 224 | context "user can pay online" do |
197 | | - it "redirects to users account paths" do |
| 225 | + before do |
198 | 226 | session["can_pay_online?"] = true; |
199 | | - get :quik_pay |
200 | | - expect(response.location).to match(/quikpay.*?orderNumber=.*&orderType=Temple%20Library&amountDue=.*&redirectUrl=.*&redirectUrlParameters=transactionStatus%2CtransactionTotalAmount%2CorderNumber×tamp=.*&hash=.*$/) |
| 227 | + end |
| 228 | + |
| 229 | + context "when quik pay sessionless callback is disabled" do |
| 230 | + before { allow(Flipflop).to receive(:quik_pay_sessionless_callback?).and_return(false) } |
| 231 | + |
| 232 | + it "redirects to users account paths" do |
| 233 | + get :quik_pay |
| 234 | + expect(response.location).to match(/quikpay.*?orderNumber=.*&orderType=Temple%20Library&amountDue=.*&redirectUrl=.*&redirectUrlParameters=transactionStatus%2CtransactionTotalAmount×tamp=.*&hash=.*$/) |
| 235 | + end |
| 236 | + end |
| 237 | + |
| 238 | + context "when quik pay sessionless callback is enabled" do |
| 239 | + before { allow(Flipflop).to receive(:quik_pay_sessionless_callback?).and_return(true) } |
| 240 | + |
| 241 | + it "redirects to users account paths" do |
| 242 | + get :quik_pay |
| 243 | + expect(response.location).to match(/quikpay.*?orderNumber=.*&orderType=Temple%20Library&amountDue=.*&redirectUrl=.*&redirectUrlParameters=transactionStatus%2CtransactionTotalAmount%2CorderNumber×tamp=.*&hash=.*$/) |
| 244 | + end |
201 | 245 | end |
202 | 246 | end |
203 | 247 |
|
204 | 248 | context "the fine has cent amounts" do |
205 | | - it "does not lose precision when coverting total_fines to cents" do |
| 249 | + before do |
206 | 250 | session["can_pay_online?"] = true; |
207 | 251 | session["total_fines"] = "25.11" |
| 252 | + end |
208 | 253 |
|
209 | | - get :quik_pay |
210 | | - expect(response.location).to match(/#{Rails.configuration.quik_pay["url"]}.*orderNumber=.*&orderType=Temple%20Library&amountDue=2511.*&redirectUrl=.*&redirectUrlParameters=transactionStatus%2CtransactionTotalAmount%2CorderNumber×tamp=.*&hash=.*$/) |
| 254 | + context "when quik pay sessionless callback is disabled" do |
| 255 | + before { allow(Flipflop).to receive(:quik_pay_sessionless_callback?).and_return(false) } |
| 256 | + |
| 257 | + it "does not lose precision when converting total_fines to cents" do |
| 258 | + get :quik_pay |
| 259 | + expect(response.location).to match(/#{Rails.configuration.quik_pay["url"]}.*orderNumber=.*&orderType=Temple%20Library&amountDue=2511.*&redirectUrl=.*&redirectUrlParameters=transactionStatus%2CtransactionTotalAmount×tamp=.*&hash=.*$/) |
| 260 | + end |
| 261 | + end |
| 262 | + |
| 263 | + context "when quik pay sessionless callback is enabled" do |
| 264 | + before { allow(Flipflop).to receive(:quik_pay_sessionless_callback?).and_return(true) } |
| 265 | + |
| 266 | + it "does not lose precision when converting total_fines to cents" do |
| 267 | + get :quik_pay |
| 268 | + expect(response.location).to match(/#{Rails.configuration.quik_pay["url"]}.*orderNumber=.*&orderType=Temple%20Library&amountDue=2511.*&redirectUrl=.*&redirectUrlParameters=transactionStatus%2CtransactionTotalAmount%2CorderNumber×tamp=.*&hash=.*$/) |
| 269 | + end |
211 | 270 | end |
212 | 271 | end |
213 | 272 |
|
|
0 commit comments