This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luuk Veenis
committed
Sep 14, 2016
1 parent
dcf35a4
commit f7b0bb6
Showing
2 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe SolidusPaypalBraintree::TransactionsController, type: :controller do | ||
include_context "order ready for payment" | ||
|
||
let(:payment_method) { create_gateway } | ||
|
||
before do | ||
allow(controller).to receive(:spree_current_user) { user } | ||
allow(controller).to receive(:current_order) { order } | ||
end | ||
|
||
cassette_options = { cassette_name: "transactions_controller/create" } | ||
describe "POST create", vcr: cassette_options do | ||
subject(:post_create) { post :create, params } | ||
|
||
let(:params) do | ||
{ | ||
transaction: { | ||
nonce: "ABC123", | ||
payment_type: "MonopolyMoney", | ||
phone: "1112223333", | ||
email: "[email protected]", | ||
address_attributes: { | ||
first_name: "Wade", | ||
last_name: "Wilson", | ||
address_line_1: "123 Fake Street", | ||
city: "Seattle", | ||
zip: "98101", | ||
state_code: "WA", | ||
country_code: "US" | ||
} | ||
}, | ||
payment_method_id: payment_method.id | ||
} | ||
end | ||
|
||
context "when the transaction is valid" do | ||
it "imports the payment" do | ||
expect { post_create }.to change { order.payments.count }.by(1) | ||
expect(order.payments.first.amount).to eq 55 | ||
end | ||
|
||
context "and an address is provided" do | ||
it "creates a new address" do | ||
# Creating the order also creates 3 addresses, we want to make sure | ||
# the transaction import only creates 1 new one | ||
order | ||
expect { post_create }.to change { Spree::Address.count }.by(1) | ||
expect(Spree::Address.last.full_name).to eq "Wade Wilson" | ||
end | ||
end | ||
|
||
context "and the transaction does not have an address" do | ||
before { params[:transaction].delete(:address_attributes) } | ||
|
||
it "does not create a new address" do | ||
order | ||
expect { post_create }.to_not change { Spree::Address.count } | ||
end | ||
end | ||
|
||
context "when import! leaves the order in confirm" do | ||
it "redirects the user to the confirm page" do | ||
expect(post_create).to redirect_to spree.checkout_state_path("confirm") | ||
end | ||
end | ||
|
||
context "when import! completes the order" do | ||
before { allow(order).to receive(:complete?).and_return(true) } | ||
|
||
it "displays the order to the user" do | ||
expect(post_create).to redirect_to spree.order_path(order) | ||
end | ||
end | ||
end | ||
|
||
context "when the transaction is invalid" do | ||
before { params[:transaction].delete(:phone) } | ||
|
||
it "displays the errors object" do | ||
subject | ||
expect(response.body).to match(/^#<ActiveModel::Errors:0x[\w]{14}>$/) | ||
end | ||
end | ||
end | ||
end |
141 changes: 141 additions & 0 deletions
141
spec/fixtures/cassettes/transactions_controller/create.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.