2019-10-27 23:05:58 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2019-12-03 19:23:45 -05:00
|
|
|
module DiscourseSubscriptions
|
2019-10-27 23:05:58 -04:00
|
|
|
RSpec.describe InvoicesController do
|
|
|
|
describe "index" do
|
|
|
|
describe "not authenticated" do
|
|
|
|
it "does not list the invoices" do
|
|
|
|
::Stripe::Invoice.expects(:list).never
|
2019-12-02 19:48:12 -05:00
|
|
|
get "/s/invoices.json"
|
2019-10-27 23:05:58 -04:00
|
|
|
expect(response.status).to eq 403
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "authenticated" do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:stripe_customer) { { id: 'cus_id4567' } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "other user invoices" do
|
|
|
|
it "does not list the invoices" do
|
|
|
|
::Stripe::Invoice.expects(:list).never
|
2019-12-02 19:48:12 -05:00
|
|
|
get "/s/invoices.json", params: { user_id: 999999 }
|
2019-10-27 23:05:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "own invoices" do
|
|
|
|
context "stripe customer does not exist" do
|
|
|
|
it "lists empty" do
|
|
|
|
::Stripe::Invoice.expects(:list).never
|
2019-12-02 19:48:12 -05:00
|
|
|
get "/s/invoices.json", params: { user_id: user.id }
|
2019-10-27 23:05:58 -04:00
|
|
|
expect(response.body).to eq "[]"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "stripe customer exists" do
|
|
|
|
before do
|
2019-12-03 19:23:45 -05:00
|
|
|
DiscourseSubscriptions::Customer.create_customer(user, stripe_customer)
|
2019-10-27 23:05:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "lists the invoices" do
|
|
|
|
::Stripe::Invoice.expects(:list).with(customer: 'cus_id4567')
|
2019-12-02 19:48:12 -05:00
|
|
|
get "/s/invoices.json", params: { user_id: user.id }
|
2019-10-27 23:05:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|