2019-09-11 03:57:29 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
module DiscoursePatrons
|
|
|
|
RSpec.describe PatronsController, type: :controller do
|
|
|
|
routes { DiscoursePatrons::Engine.routes }
|
2019-09-11 04:32:09 -04:00
|
|
|
|
2019-09-11 05:11:02 -04:00
|
|
|
describe 'index' do
|
|
|
|
it 'responds ok' do
|
|
|
|
get :index, format: :json
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2019-09-12 22:35:38 -04:00
|
|
|
|
|
|
|
it 'has a current user email' do
|
|
|
|
user = Fabricate(:user, email: 'hello@example.com')
|
|
|
|
controller.expects(:current_user).at_least(1).returns(user)
|
|
|
|
|
|
|
|
get :index, format: :json
|
|
|
|
|
|
|
|
expect(JSON.parse(response.body)['email']).to eq 'hello@example.com'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has no current user email' do
|
|
|
|
get :index, format: :json
|
2019-09-12 22:58:17 -04:00
|
|
|
expect(JSON.parse(response.body)['email']).to be_empty
|
2019-09-12 22:35:38 -04:00
|
|
|
end
|
2019-09-11 05:11:02 -04:00
|
|
|
end
|
2019-09-11 04:32:09 -04:00
|
|
|
|
2019-09-11 05:11:02 -04:00
|
|
|
describe 'create' do
|
2019-09-11 05:55:35 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.stubs(:discourse_patrons_currency).returns('AUD')
|
|
|
|
SiteSetting.stubs(:discourse_patrons_secret_key).returns('xyz-678')
|
|
|
|
end
|
|
|
|
|
2019-09-11 05:11:02 -04:00
|
|
|
it 'responds ok' do
|
2019-09-11 05:55:35 -04:00
|
|
|
::Stripe::PaymentIntent.expects(:create)
|
2019-09-11 05:27:24 -04:00
|
|
|
post :create, params: {}, format: :json
|
2019-09-11 04:32:09 -04:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2019-09-11 21:49:52 -04:00
|
|
|
|
|
|
|
it 'has the correct amount' do
|
|
|
|
::Stripe::PaymentIntent.expects(:create).with(has_entry(:amount, 2000))
|
|
|
|
post :create, params: { amount: '20.00' }, format: :json
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has no amount' do
|
|
|
|
::Stripe::PaymentIntent.expects(:create).with(has_entry(:amount, 0))
|
|
|
|
post :create, params: {}, format: :json
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2019-09-11 23:13:06 -04:00
|
|
|
|
|
|
|
it 'has curency' do
|
|
|
|
::Stripe::PaymentIntent.expects(:create).with(has_entry(:currency, 'AUD'))
|
|
|
|
post :create, params: {}, format: :json
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2019-09-12 05:17:08 -04:00
|
|
|
|
2019-09-12 23:46:32 -04:00
|
|
|
it 'has a receipt email' do
|
|
|
|
::Stripe::PaymentIntent.expects(:create).with(has_entry(:receipt_email, 'hello@example.com'))
|
|
|
|
post :create, params: { receiptEmail: 'hello@example.com' }, format: :json
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
|
2019-09-12 05:17:08 -04:00
|
|
|
it 'has a description' do
|
|
|
|
SiteSetting.stubs(:discourse_patrons_payment_description).returns('hello-world')
|
|
|
|
::Stripe::PaymentIntent.expects(:create).with(has_entry(:description, 'hello-world'))
|
|
|
|
post :create, params: {}, format: :json
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2019-09-11 04:32:09 -04:00
|
|
|
end
|
2019-09-11 03:57:29 -04:00
|
|
|
end
|
|
|
|
end
|