confirmations_controller_spec.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Api::V1::Emails::ConfirmationsController, type: :controller do
  4. let(:confirmed_at) { nil }
  5. let(:user) { Fabricate(:user, confirmed_at: confirmed_at) }
  6. let(:app) { Fabricate(:application) }
  7. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes, application: app) }
  8. let(:scopes) { 'write' }
  9. describe '#create' do
  10. context 'with an oauth token' do
  11. before do
  12. allow(controller).to receive(:doorkeeper_token) { token }
  13. end
  14. context 'from a random app' do
  15. it 'returns http forbidden' do
  16. post :create
  17. expect(response).to have_http_status(403)
  18. end
  19. end
  20. context 'from an app that created the account' do
  21. before do
  22. user.update(created_by_application: token.application)
  23. end
  24. context 'when the account is already confirmed' do
  25. let(:confirmed_at) { Time.now.utc }
  26. it 'returns http forbidden' do
  27. post :create
  28. expect(response).to have_http_status(403)
  29. end
  30. context 'but user changed e-mail and has not confirmed it' do
  31. before do
  32. user.update(email: 'foo@bar.com')
  33. end
  34. it 'returns http success' do
  35. post :create
  36. expect(response).to have_http_status(:success)
  37. end
  38. end
  39. end
  40. context 'when the account is unconfirmed' do
  41. it 'returns http success' do
  42. post :create
  43. expect(response).to have_http_status(:success)
  44. end
  45. end
  46. end
  47. end
  48. context 'without an oauth token' do
  49. it 'returns http unauthorized' do
  50. post :create
  51. expect(response).to have_http_status(401)
  52. end
  53. end
  54. end
  55. end