conversations_controller_spec.rb 1.7 KB

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