refactor the rewards interface for extensibility

This commit is contained in:
Rimian Perkins 2017-04-24 10:06:47 +10:00
parent 23b909dc48
commit 1c87a87bd6
2 changed files with 9 additions and 8 deletions

View File

@ -14,13 +14,13 @@ module DiscourseDonations
response = {}
end
response['rewards'] = {}
response['rewards'] = []
if reward_user?(payment)
reward = DiscourseDonations::Rewards.new(current_user)
group_name = SiteSetting.discourse_donations_reward_group_name
if reward.add_to_group(group_name)
response['rewards']['groups'] = [group_name]
response['rewards'] << { type: :group, name: group_name }
end
end

View File

@ -28,24 +28,25 @@ module DiscourseDonations
end
describe 'rewards' do
let(:group_name) { 'Zasch' }
let(:response_rewards) { JSON.parse(response.body)['rewards'] }
let(:stripe) { ::Stripe::Charge }
before do
SiteSetting.stubs(:discourse_donations_reward_group_name).returns('Skimby')
SiteSetting.stubs(:discourse_donations_reward_group_name).returns(group_name)
Fabricate(:group, name: SiteSetting.discourse_donations_reward_group_name)
log_in :coding_horror
end
let(:response_rewards) { JSON.parse(response.body)['rewards'] }
let(:stripe) { ::Stripe::Charge }
it 'has no rewards' do
stripe.expects(:create).returns({ outcome: { seller_message: 'bummer' } })
post :create
expect(response_rewards).to eq({})
expect(response_rewards).to be_empty
end
it 'awards a group' do
post :create
expect(response_rewards['groups']).to eq([SiteSetting.discourse_donations_reward_group_name])
expect(response_rewards.first).to eq({'type' => 'group', 'name' => group_name})
end
end
end