This commit is contained in:
Rimian Perkins 2019-08-27 18:48:54 +10:00
parent 4c25aa0ad1
commit a654f7410d
1 changed files with 0 additions and 105 deletions

View File

@ -119,110 +119,5 @@ module DiscourseDonations
end end
end end
end end
describe 'new user' do
let(:params) { { create_account: 'true', email: 'email@example.com', password: 'secret', username: 'mr-pink', amount: 100, stripeToken: 'rrurrrurrrrr-rrruurrrr' } }
before { SiteSetting.stubs(:discourse_donations_enable_create_accounts).returns(true) }
describe 'requires an email' do
before { post :create, params: params.merge(email: ''), format: :json }
include_examples 'failure response', 'login.missing_user_field'
end
describe 'requires a username' do
before { post :create, params: params.merge(username: ''), format: :json }
include_examples 'failure response', 'login.missing_user_field'
end
describe 'reserved usernames' do
before do
User.expects(:reserved_username?).returns(true)
post :create, params: params, format: :json
end
include_examples 'failure response', 'login.reserved_username'
end
describe 'minimum password length' do
before do
User.expects(:max_password_length).returns(params[:password].length - 1)
post :create, params: params, format: :json
end
include_examples 'failure response', 'login.password_too_long'
end
end
describe 'rewards' do
let(:body) { JSON.parse(response.body) }
let(:stripe) { ::Stripe::Charge }
shared_examples 'no rewards' do
it 'has no rewards' do
post :create, params: params
expect(body['rewards']).to be_empty
end
end
describe 'new user' do
let(:params) { { create_account: 'true', email: 'dood@example.com', password: 'secretsecret', name: 'dood', username: 'mr-dood' } }
before { SiteSetting.stubs(:discourse_donations_enable_create_accounts).returns(true) }
include_examples 'no rewards' do
before do
stripe.stubs(:create).returns({ 'paid' => false })
end
end
include_examples 'no rewards' do
before do
stripe.stubs(:create).returns({ 'paid' => true })
SiteSetting.stubs(:discourse_donations_reward_group_name).returns(nil)
SiteSetting.stubs(:discourse_donations_reward_badge_name).returns(nil)
end
end
end
describe 'logged in user' do
before do
log_in :coding_horror
end
include_examples 'no rewards' do
let(:params) { {} }
before do
stripe.stubs(:create).returns({ 'paid' => true })
SiteSetting.stubs(:discourse_donations_reward_group_name).returns(nil)
SiteSetting.stubs(:discourse_donations_reward_badge_name).returns(nil)
end
end
describe 'rewards' do
let(:group_name) { 'Zasch' }
let(:badge_name) { 'Beanie' }
let!(:grp) { Fabricate(:group, name: group_name) }
let!(:badge) { Fabricate(:badge, name: badge_name) }
before do
SiteSetting.stubs(:discourse_donations_reward_group_name).returns(group_name)
SiteSetting.stubs(:discourse_donations_reward_badge_name).returns(badge_name)
stripe.stubs(:create).returns({ 'paid' => true })
end
it 'awards a group' do
post :create, format: :json
expect(body['rewards']).to include({ 'type' => 'group', 'name' => group_name })
end
it 'awards a badge' do
post :create, format: :json
expect(body['rewards']).to include({ 'type' => 'badge', 'name' => badge_name })
end
end
end
end
end end
end end