|
12 | 12 | )
|
13 | 13 | end
|
14 | 14 |
|
15 |
| - let(:store) { Spree::Store.default } |
16 |
| - let(:gateway) { create :hpp_gateway } |
| 15 | + let!(:store) { Spree::Store.default } |
| 16 | + let!(:gateway) { create :hpp_gateway } |
17 | 17 |
|
18 | 18 | before do
|
19 | 19 | allow(controller).to receive(:check_signature)
|
|
24 | 24 |
|
25 | 25 | let(:psp_reference) { "8813824003752247" }
|
26 | 26 | let(:payment_method) { "amex" }
|
| 27 | + let(:merchantReturnData) { "#{order.guest_token}|#{gateway.id}" } |
27 | 28 | let(:params) do
|
28 | 29 | { merchantReference: order.number,
|
29 | 30 | skinCode: "xxxxxxxx",
|
|
35 | 36 | merchantReturnData: merchantReturnData
|
36 | 37 | }
|
37 | 38 | end
|
38 |
| - let(:merchantReturnData) { [order.guest_token, gateway.id].join("|") } |
39 |
| - |
40 |
| - shared_examples "payments are pending" do |
41 |
| - it "has pending payments" do |
42 |
| - expect(order.payments).to all be_pending |
43 |
| - end |
44 |
| - end |
45 | 39 |
|
46 | 40 | shared_examples "payment is successful" do
|
47 | 41 | it "changes the order state to completed" do
|
48 |
| - expect { subject }. |
49 |
| - to change { order.reload.state }. |
50 |
| - from("payment"). |
51 |
| - to("complete"). |
52 |
| - |
53 |
| - and change { order.payment_state }. |
54 |
| - from(nil). |
55 |
| - to("balance_due"). |
56 |
| - |
57 |
| - and change { order.shipment_state }. |
58 |
| - from(nil). |
59 |
| - to("pending") |
| 42 | + subject |
| 43 | + order.reload |
| 44 | + expect(order).to have_attributes( |
| 45 | + state: "complete", |
| 46 | + payment_state: "balance_due", |
| 47 | + shipment_state: "pending" |
| 48 | + ) |
| 49 | + end |
| 50 | + |
| 51 | + it "has pending payments" do |
| 52 | + expect(order.payments).to all be_pending |
60 | 53 | end
|
61 | 54 |
|
62 | 55 | it "redirects to the order complete page" do
|
|
65 | 58 | end
|
66 | 59 |
|
67 | 60 | it "creates a payment" do
|
68 |
| - expect{ subject }. |
69 |
| - to change{ order.payments.count }. |
70 |
| - from(0). |
71 |
| - to(1) |
| 61 | + subject |
| 62 | + expect(order.reload.payments.count).to eq 1 |
72 | 63 | end
|
73 | 64 |
|
74 | 65 | context "and the order cannot complete" do
|
|
80 | 71 | end
|
81 | 72 | end
|
82 | 73 |
|
| 74 | + shared_examples "payment is not successful" do |
| 75 | + it "does not change order state" do |
| 76 | + expect{ subject }.to_not change{ order.state } |
| 77 | + end |
| 78 | + |
| 79 | + it "redirects to the order payment page" do |
| 80 | + is_expected.to have_http_status(:redirect). |
| 81 | + and redirect_to checkout_state_path("payment") |
| 82 | + end |
| 83 | + end |
| 84 | + |
83 | 85 | context "when the payment is AUTHORISED" do
|
84 | 86 | include_examples "payment is successful"
|
85 |
| - include_examples "payments are pending" |
| 87 | + |
86 | 88 | let(:auth_result) { "AUTHORISED" }
|
87 | 89 |
|
88 | 90 | context "and the authorisation notification has already been received" do
|
|
91 | 93 | let(:notification) do
|
92 | 94 | create(
|
93 | 95 | :notification,
|
94 |
| - notification_type, |
| 96 | + :auth, |
| 97 | + processed: true, |
95 | 98 | psp_reference: psp_reference,
|
96 | 99 | merchant_reference: order.number)
|
97 | 100 | end
|
98 | 101 |
|
99 |
| - shared_examples "auth received" do |
100 |
| - include_examples "payment is successful" |
| 102 | + # there will already be a payment and source created at this point |
| 103 | + before do |
| 104 | + source = |
| 105 | + create(:hpp_source, psp_reference: psp_reference, order: order) |
101 | 106 |
|
102 |
| - it "processes the notification" do |
103 |
| - expect { subject }. |
104 |
| - to change { notification.reload.processed }. |
105 |
| - from(false). |
106 |
| - to(true) |
107 |
| - end |
108 |
| - end |
| 107 | + create(:hpp_payment, source: source, order: order) |
109 | 108 |
|
110 |
| - context "and payment method is sofort" do |
111 |
| - let(:notification_type) { :sofort_auth } |
112 |
| - include_examples "auth received" |
| 109 | + order.complete |
113 | 110 | end
|
114 | 111 |
|
115 |
| - context "and payment method is ideal" do |
116 |
| - let(:notification_type) { :ideal_auth } |
117 |
| - include_examples "auth received" |
118 |
| - end |
| 112 | + it { expect { subject }.to_not change { order.payments.count }.from 1 } |
119 | 113 |
|
120 |
| - context "and payment method is credit" do |
121 |
| - let(:notification_type) { :auth } |
122 |
| - include_examples "auth received" |
| 114 | + it "updates the source" do |
| 115 | + expect(order.payments.last.source).to have_attributes( |
| 116 | + auth_result: "AUTHORISED", |
| 117 | + skin_code: "XXXXXXXX" |
| 118 | + ) |
123 | 119 | end
|
| 120 | + |
| 121 | + include_examples "payment is successful" |
124 | 122 | end
|
125 | 123 | end
|
126 | 124 |
|
127 | 125 | context "when the payment is PENDING" do
|
128 | 126 | include_examples "payment is successful"
|
129 |
| - include_examples "payments are pending" |
130 | 127 | let(:auth_result) { "PENDING" }
|
131 | 128 | end
|
132 | 129 |
|
133 |
| - shared_examples "payment is not successful" do |
134 |
| - it "does not change order state" do |
135 |
| - expect{ subject }.to_not change{ order.state } |
136 |
| - end |
137 |
| - |
138 |
| - it "redirects to the order payment page" do |
139 |
| - is_expected.to have_http_status(:redirect). |
140 |
| - and redirect_to checkout_state_path("payment") |
141 |
| - end |
142 |
| - end |
143 |
| - |
144 | 130 | context "when the payment is CANCELLED" do
|
145 | 131 | include_examples "payment is not successful"
|
146 | 132 | let(:auth_result) { "CANCELLED" }
|
|
0 commit comments