58 lines
1.6 KiB
Ruby
58 lines
1.6 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe ApiSalesController do
|
|
render_views
|
|
|
|
let(:user) {FactoryGirl.create(:user)}
|
|
let(:jam_track) {FactoryGirl.create(:jam_track)}
|
|
|
|
before(:each) do
|
|
controller.current_user = user
|
|
end
|
|
|
|
describe "index" do
|
|
|
|
it "empty" do
|
|
get :index, { :format => 'json'}
|
|
|
|
response.should be_success
|
|
body = JSON.parse(response.body)
|
|
body['next_page'].should be_nil
|
|
body['entries'].should eq([])
|
|
end
|
|
|
|
it "one item" do
|
|
sale = Sale.create_jam_track_sale(user)
|
|
sale.recurly_invoice_id = SecureRandom.uuid
|
|
sale.save!
|
|
|
|
shopping_cart = ShoppingCart.create(user, jam_track)
|
|
sale_line_item = SaleLineItem.create_from_shopping_cart(sale, shopping_cart, nil, 'some_adjustment_uuid', nil)
|
|
|
|
get :index, { :format => 'json'}
|
|
response.should be_success
|
|
body = JSON.parse(response.body)
|
|
body['next_page'].should be_nil
|
|
entries = body['entries']
|
|
entries.should have(1).items
|
|
sale_entry = entries[0]
|
|
sale_entry["line_items"].should have(1).items
|
|
sale_entry["recurly_transactions"].should have(0).items
|
|
|
|
|
|
transaction = FactoryGirl.create(:recurly_transaction_web_hook, invoice_id: sale.recurly_invoice_id, transaction_type: RecurlyTransactionWebHook::VOID)
|
|
|
|
get :index, { :format => 'json'}
|
|
response.should be_success
|
|
body = JSON.parse(response.body)
|
|
body['next_page'].should be_nil
|
|
entries = body['entries']
|
|
entries.should have(1).items
|
|
sale_entry = entries[0]
|
|
sale_entry["line_items"].should have(1).items
|
|
sale_entry["recurly_transactions"].should have(1).items
|
|
end
|
|
end
|
|
|
|
end
|