search_controller_spec.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Api::V2::SearchController, type: :controller do
  4. render_views
  5. context 'with token' do
  6. let(:user) { Fabricate(:user) }
  7. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:search') }
  8. before do
  9. allow(controller).to receive(:doorkeeper_token) { token }
  10. end
  11. describe 'GET #index' do
  12. before do
  13. get :index, params: { q: 'test' }
  14. end
  15. it 'returns http success' do
  16. expect(response).to have_http_status(200)
  17. end
  18. end
  19. end
  20. context 'without token' do
  21. describe 'GET #index' do
  22. let(:search_params) {}
  23. before do
  24. get :index, params: search_params
  25. end
  26. context 'with a `q` shorter than 5 characters' do
  27. let(:search_params) { { q: 'test' } }
  28. it 'returns http success' do
  29. expect(response).to have_http_status(200)
  30. end
  31. end
  32. context 'with a `q` equal to or longer than 5 characters' do
  33. let(:search_params) { { q: 'test1' } }
  34. it 'returns http success' do
  35. expect(response).to have_http_status(200)
  36. end
  37. context 'with truthy `resolve`' do
  38. let(:search_params) { { q: 'test1', resolve: '1' } }
  39. it 'returns http unauthorized' do
  40. expect(response).to have_http_status(401)
  41. end
  42. end
  43. context 'with `offset`' do
  44. let(:search_params) { { q: 'test1', offset: 1 } }
  45. it 'returns http unauthorized' do
  46. expect(response).to have_http_status(401)
  47. end
  48. end
  49. end
  50. end
  51. end
  52. end