scheduled_status_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe 'Scheduled Statuses' do
  4. let(:user) { Fabricate(:user) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  7. describe 'GET /api/v1/scheduled_statuses' do
  8. context 'when not authorized' do
  9. it 'returns http unauthorized' do
  10. get api_v1_scheduled_statuses_path
  11. expect(response)
  12. .to have_http_status(401)
  13. end
  14. end
  15. context 'with wrong scope' do
  16. before do
  17. get api_v1_scheduled_statuses_path, headers: headers
  18. end
  19. it_behaves_like 'forbidden for wrong scope', 'write write:statuses'
  20. end
  21. context 'with correct scope' do
  22. let(:scopes) { 'read:statuses' }
  23. context 'without scheduled statuses' do
  24. it 'returns http success without json' do
  25. get api_v1_scheduled_statuses_path, headers: headers
  26. expect(response)
  27. .to have_http_status(200)
  28. expect(body_as_json)
  29. .to_not be_present
  30. end
  31. end
  32. context 'with scheduled statuses' do
  33. let!(:scheduled_status) { Fabricate(:scheduled_status, account: user.account) }
  34. it 'returns http success and status json' do
  35. get api_v1_scheduled_statuses_path, headers: headers
  36. expect(response)
  37. .to have_http_status(200)
  38. expect(body_as_json)
  39. .to be_present
  40. .and have_attributes(
  41. first: include(id: scheduled_status.id.to_s)
  42. )
  43. end
  44. end
  45. end
  46. end
  47. end