conversations_spec.rb 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'API V1 Conversations' do
  4. let!(:user) { Fabricate(:user, account_attributes: { username: 'alice' }) }
  5. let(:scopes) { 'read:statuses' }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  7. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  8. let(:other) { Fabricate(:user) }
  9. describe 'GET /api/v1/conversations', :inline_jobs do
  10. before do
  11. user.account.follow!(other.account)
  12. PostStatusService.new.call(other.account, text: 'Hey @alice', visibility: 'direct')
  13. PostStatusService.new.call(user.account, text: 'Hey, nobody here', visibility: 'direct')
  14. end
  15. it 'returns pagination headers', :aggregate_failures do
  16. get '/api/v1/conversations', params: { limit: 1 }, headers: headers
  17. expect(response)
  18. .to have_http_status(200)
  19. .and include_pagination_headers(
  20. prev: api_v1_conversations_url(limit: 1, min_id: Status.first.id),
  21. next: api_v1_conversations_url(limit: 1, max_id: Status.first.id)
  22. )
  23. expect(response.content_type)
  24. .to start_with('application/json')
  25. end
  26. it 'returns conversations', :aggregate_failures do
  27. get '/api/v1/conversations', headers: headers
  28. expect(response.parsed_body.size).to eq 2
  29. expect(response.parsed_body.first[: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 '/api/v1/conversations', params: { since_id: Mastodon::Snowflake.id_at(1.hour.ago, with_random: false) }, headers: headers
  35. expect(response.parsed_body.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 '/api/v1/conversations', params: { since_id: Mastodon::Snowflake.id_at(1.hour.from_now, with_random: false) }, headers: headers
  41. expect(response.parsed_body.size).to eq 0
  42. end
  43. end
  44. end
  45. end
  46. end