* REFACTOR: Use api to add subscribe link * FIX: I18n subscribe link * REFACTOR: Use models to store some data This enables the plugin to show only subscription information which was generated on Discourse. Subscription data storage is limited to the external identifiers Stripe generates so we can interact with the API. * DEV: Test/linting fixes/rake task
64 lines
1.5 KiB
Ruby
64 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
module DiscourseSubscriptions
|
|
RSpec.describe User::PaymentsController do
|
|
it 'is a subclass of ApplicationController' do
|
|
expect(DiscourseSubscriptions::User::PaymentsController < ::ApplicationController).to eq(true)
|
|
end
|
|
|
|
context "not authenticated" do
|
|
it "does not get the payment intents" do
|
|
::Stripe::PaymentIntent.expects(:list).never
|
|
get "/s/user/payments.json"
|
|
expect(response.status).to eq(403)
|
|
end
|
|
end
|
|
|
|
context "authenticated" do
|
|
let(:user) { Fabricate(:user, email: '[email protected]') }
|
|
|
|
before do
|
|
sign_in(user)
|
|
Fabricate(:customer, customer_id: 'c_345678', user_id: user.id)
|
|
Fabricate(:product, external_id: 'prod_8675309')
|
|
end
|
|
|
|
it "gets payment intents" do
|
|
::Stripe::Invoice.expects(:list).with(
|
|
customer: 'c_345678'
|
|
).returns(
|
|
data: [
|
|
id: "inv_900007",
|
|
lines: {
|
|
data: [
|
|
plan: {
|
|
product: "prod_8675309"
|
|
}
|
|
]
|
|
},
|
|
]
|
|
)
|
|
|
|
::Stripe::PaymentIntent.expects(:list).with(
|
|
customer: 'c_345678',
|
|
).returns(
|
|
data: [
|
|
{ invoice: "inv_900007" },
|
|
{ invoice: "inv_007" }
|
|
]
|
|
)
|
|
|
|
get "/s/user/payments.json"
|
|
|
|
invoice = response.parsed_body[0]["invoice"]
|
|
|
|
expect(invoice).to eq("inv_900007")
|
|
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|