conversations_controller_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 pagination headers', :aggregate_failures do
  18. get :index, params: { limit: 1 }
  19. expect(response).to have_http_status(200)
  20. expect(response.headers['Link'].links.size).to eq(2)
  21. end
  22. it 'returns conversations', :aggregate_failures do
  23. get :index
  24. json = body_as_json
  25. expect(json.size).to eq 2
  26. expect(json[0][:accounts].size).to eq 1
  27. end
  28. context 'with since_id' do
  29. context 'when requesting old posts' do
  30. it 'returns conversations' do
  31. get :index, params: { since_id: Mastodon::Snowflake.id_at(1.hour.ago, with_random: false) }
  32. json = body_as_json
  33. expect(json.size).to eq 2
  34. end
  35. end
  36. context 'when requesting posts in the future' do
  37. it 'returns no conversation' do
  38. get :index, params: { since_id: Mastodon::Snowflake.id_at(1.hour.from_now, with_random: false) }
  39. json = body_as_json
  40. expect(json.size).to eq 0
  41. end
  42. end
  43. end
  44. end
  45. end