conversations_controller_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. require 'rails_helper'
  2. RSpec.describe Api::V1::ConversationsController, type: :controller do
  3. render_views
  4. let!(:user) { Fabricate(:user, account_attributes: { username: 'alice' }) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let(:other) { Fabricate(:user) }
  7. before do
  8. allow(controller).to receive(:doorkeeper_token) { token }
  9. end
  10. describe 'GET #index' do
  11. let(:scopes) { 'read:statuses' }
  12. before do
  13. PostStatusService.new.call(other.account, text: 'Hey @alice', visibility: 'direct')
  14. PostStatusService.new.call(user.account, text: 'Hey, nobody here', visibility: 'direct')
  15. end
  16. it 'returns http success' do
  17. get :index
  18. expect(response).to have_http_status(200)
  19. end
  20. it 'returns pagination headers' do
  21. get :index, params: { limit: 1 }
  22. expect(response.headers['Link'].links.size).to eq(2)
  23. end
  24. it 'returns conversations' do
  25. get :index
  26. json = body_as_json
  27. expect(json.size).to eq 2
  28. expect(json[0][:accounts].size).to eq 1
  29. end
  30. context 'with since_id' do
  31. context 'when requesting old posts' do
  32. it 'returns conversations' do
  33. get :index, params: { since_id: Mastodon::Snowflake.id_at(1.hour.ago, with_random: false) }
  34. json = body_as_json
  35. expect(json.size).to eq 2
  36. end
  37. end
  38. context 'when requesting posts in the future' do
  39. it 'returns no conversation' do
  40. get :index, params: { since_id: Mastodon::Snowflake.id_at(1.hour.from_now, with_random: false) }
  41. json = body_as_json
  42. expect(json.size).to eq 0
  43. end
  44. end
  45. end
  46. end
  47. end