logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

favourites_controller_spec.rb (1872B)


  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Api::V1::Statuses::FavouritesController do
  4. render_views
  5. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  6. let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
  7. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write', application: app) }
  8. context 'with an oauth token' do
  9. before do
  10. allow(controller).to receive(:doorkeeper_token) { token }
  11. end
  12. describe 'POST #create' do
  13. let(:status) { Fabricate(:status, account: user.account) }
  14. before do
  15. post :create, params: { status_id: status.id }
  16. end
  17. it 'returns http success' do
  18. expect(response).to have_http_status(:success)
  19. end
  20. it 'updates the favourites count' do
  21. expect(status.favourites.count).to eq 1
  22. end
  23. it 'updates the favourited attribute' do
  24. expect(user.account.favourited?(status)).to be true
  25. end
  26. it 'return json with updated attributes' do
  27. hash_body = body_as_json
  28. expect(hash_body[:id]).to eq status.id.to_s
  29. expect(hash_body[:favourites_count]).to eq 1
  30. expect(hash_body[:favourited]).to be true
  31. end
  32. end
  33. describe 'POST #destroy' do
  34. let(:status) { Fabricate(:status, account: user.account) }
  35. before do
  36. FavouriteService.new.call(user.account, status)
  37. post :destroy, params: { status_id: status.id }
  38. end
  39. it 'returns http success' do
  40. expect(response).to have_http_status(:success)
  41. end
  42. it 'updates the favourites count' do
  43. expect(status.favourites.count).to eq 0
  44. end
  45. it 'updates the favourited attribute' do
  46. expect(user.account.favourited?(status)).to be false
  47. end
  48. end
  49. end
  50. end