You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.8 KiB

  1. require 'rails_helper'
  2. RSpec.describe AppSignUpService, type: :service do
  3. let(:app) { Fabricate(:application, scopes: 'read write') }
  4. let(:good_params) { { username: 'alice', password: '12345678', email: 'good@email.com', agreement: true } }
  5. subject { described_class.new }
  6. describe '#call' do
  7. it 'returns nil when registrations are closed' do
  8. tmp = Setting.registrations_mode
  9. Setting.registrations_mode = 'none'
  10. expect(subject.call(app, good_params)).to be_nil
  11. Setting.registrations_mode = tmp
  12. end
  13. it 'raises an error when params are missing' do
  14. expect { subject.call(app, {}) }.to raise_error ActiveRecord::RecordInvalid
  15. end
  16. it 'creates an unconfirmed user with access token' do
  17. access_token = subject.call(app, good_params)
  18. expect(access_token).to_not be_nil
  19. user = User.find_by(id: access_token.resource_owner_id)
  20. expect(user).to_not be_nil
  21. expect(user.confirmed?).to be false
  22. end
  23. it 'creates access token with the app\'s scopes' do
  24. access_token = subject.call(app, good_params)
  25. expect(access_token).to_not be_nil
  26. expect(access_token.scopes.to_s).to eq 'read write'
  27. end
  28. it 'creates an account' do
  29. access_token = subject.call(app, good_params)
  30. expect(access_token).to_not be_nil
  31. user = User.find_by(id: access_token.resource_owner_id)
  32. expect(user).to_not be_nil
  33. expect(user.account).to_not be_nil
  34. expect(user.invite_request).to be_nil
  35. end
  36. it 'creates an account with invite request text' do
  37. access_token = subject.call(app, good_params.merge(reason: 'Foo bar'))
  38. expect(access_token).to_not be_nil
  39. user = User.find_by(id: access_token.resource_owner_id)
  40. expect(user).to_not be_nil
  41. expect(user.invite_request&.text).to eq 'Foo bar'
  42. end
  43. end
  44. end