add rewards to response
This commit is contained in:
parent
c3fe90f4d1
commit
f383a0c4f9
|
@ -14,12 +14,14 @@ 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
|
||||
reward.add_to_group(group_name) if group_name.present?
|
||||
if reward.add_to_group(group_name)
|
||||
response['rewards']['groups'] = [SiteSetting.discourse_donations_reward_group]
|
||||
end
|
||||
end
|
||||
|
||||
render :json => response
|
||||
|
|
|
@ -8,7 +8,9 @@ module DiscourseDonations
|
|||
|
||||
def add_to_group(name)
|
||||
group = ::Group.find_by_name(name)
|
||||
group.add(@user) if group.present?
|
||||
return false if group.nil?
|
||||
group.add(@user)
|
||||
group.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,10 +27,26 @@ module DiscourseDonations
|
|||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'has no rewards' do
|
||||
current_user = log_in(:coding_horror)
|
||||
post :create
|
||||
expect(JSON.parse(response.body)['rewards']).to eq([])
|
||||
describe 'rewards' do
|
||||
before do
|
||||
SiteSetting.stubs(:discourse_donations_reward_group).returns('Skimby')
|
||||
Fabricate(:group, name: SiteSetting.discourse_donations_reward_group)
|
||||
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({ bummer: true })
|
||||
post :create
|
||||
expect(response_rewards).to eq({})
|
||||
end
|
||||
|
||||
it 'awards a group' do
|
||||
post :create
|
||||
expect(response_rewards['groups']).to eq([SiteSetting.discourse_donations_reward_group])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,12 @@ module DiscourseDonations
|
|||
it 'adds the user to a group' do
|
||||
Group.expects(:find_by_name).with(grp.name).returns(grp)
|
||||
grp.expects(:add).with(user)
|
||||
subject.add_to_group(grp.name)
|
||||
expect(subject.add_to_group(grp.name)).to eq true
|
||||
end
|
||||
|
||||
it 'does not add the user to a group' do
|
||||
Group.expects(:find_by_name).with(grp.name).returns(nil)
|
||||
expect(subject.add_to_group(grp.name)).to eq false
|
||||
end
|
||||
|
||||
it 'grants the user a badge'
|
||||
|
|
Loading…
Reference in New Issue