2017-02-16 00:29:42 -05:00
|
|
|
require 'rails_helper'
|
2017-03-19 21:08:30 -04:00
|
|
|
require_relative '../../support/dd_helper'
|
2017-02-16 00:29:42 -05:00
|
|
|
|
2017-02-23 21:23:11 -05:00
|
|
|
module DiscourseDonations
|
2017-02-16 00:29:42 -05:00
|
|
|
RSpec.describe ChargesController, type: :controller do
|
2017-02-23 21:23:11 -05:00
|
|
|
routes { DiscourseDonations::Engine.routes }
|
2017-03-19 21:08:30 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.stubs(:discourse_donations_secret_key).returns('secret-key-yo')
|
2017-04-06 00:22:22 -04:00
|
|
|
SiteSetting.stubs(:discourse_donations_description).returns('charity begins at discourse plugin')
|
|
|
|
SiteSetting.stubs(:discourse_donations_currency).returns('AUD')
|
2017-03-19 21:08:30 -04:00
|
|
|
end
|
|
|
|
|
2017-04-03 22:00:23 -04:00
|
|
|
it 'responds ok for anonymous users' do
|
|
|
|
post :create, { email: 'foobar@example.com' }
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds ok when the email is empty' do
|
2017-04-04 19:49:57 -04:00
|
|
|
post :create, { email: '' }
|
2017-04-03 22:00:23 -04:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds ok for logged in user' do
|
|
|
|
current_user = log_in(:coding_horror)
|
2017-02-16 00:29:42 -05:00
|
|
|
post :create
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2017-04-20 22:08:52 -04:00
|
|
|
|
2017-04-21 00:26:53 -04:00
|
|
|
describe 'rewards' do
|
2017-04-23 20:06:47 -04:00
|
|
|
let(:group_name) { 'Zasch' }
|
2017-04-23 21:44:55 -04:00
|
|
|
let(:badge_name) { 'Beanie' }
|
2017-04-23 20:06:47 -04:00
|
|
|
let(:response_rewards) { JSON.parse(response.body)['rewards'] }
|
|
|
|
let(:stripe) { ::Stripe::Charge }
|
|
|
|
|
2017-04-21 00:26:53 -04:00
|
|
|
before do
|
2017-04-23 20:06:47 -04:00
|
|
|
SiteSetting.stubs(:discourse_donations_reward_group_name).returns(group_name)
|
2017-04-23 21:44:55 -04:00
|
|
|
SiteSetting.stubs(:discourse_donations_reward_badge_name).returns(badge_name)
|
2017-04-23 16:05:51 -04:00
|
|
|
Fabricate(:group, name: SiteSetting.discourse_donations_reward_group_name)
|
2017-04-23 21:44:55 -04:00
|
|
|
Fabricate(:badge, name: SiteSetting.discourse_donations_reward_badge_name)
|
2017-04-21 00:26:53 -04:00
|
|
|
log_in :coding_horror
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has no rewards' do
|
2017-04-23 16:31:18 -04:00
|
|
|
stripe.expects(:create).returns({ outcome: { seller_message: 'bummer' } })
|
2017-04-21 00:26:53 -04:00
|
|
|
post :create
|
2017-04-23 20:06:47 -04:00
|
|
|
expect(response_rewards).to be_empty
|
2017-04-21 00:26:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'awards a group' do
|
|
|
|
post :create
|
2017-04-23 21:44:55 -04:00
|
|
|
expect(response_rewards).to include({'type' => 'group', 'name' => group_name})
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'awards a badge' do
|
|
|
|
post :create
|
|
|
|
expect(response_rewards).to include({'type' => 'badge', 'name' => badge_name})
|
2017-04-21 00:26:53 -04:00
|
|
|
end
|
2017-04-20 22:08:52 -04:00
|
|
|
end
|
2017-02-16 00:29:42 -05:00
|
|
|
end
|
|
|
|
end
|