pins_spec.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Accounts Pins API' do
  4. let(:user) { Fabricate(:user) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let(:scopes) { 'write:accounts' }
  7. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  8. let(:kevin) { Fabricate(:user) }
  9. before do
  10. kevin.account.followers << user.account
  11. end
  12. describe 'POST /api/v1/accounts/:account_id/pin' do
  13. subject { post "/api/v1/accounts/#{kevin.account.id}/pin", headers: headers }
  14. it 'creates account_pin', :aggregate_failures do
  15. expect do
  16. subject
  17. end.to change { AccountPin.where(account: user.account, target_account: kevin.account).count }.by(1)
  18. expect(response).to have_http_status(200)
  19. expect(response.content_type)
  20. .to start_with('application/json')
  21. end
  22. end
  23. describe 'POST /api/v1/accounts/:account_id/unpin' do
  24. subject { post "/api/v1/accounts/#{kevin.account.id}/unpin", headers: headers }
  25. before do
  26. Fabricate(:account_pin, account: user.account, target_account: kevin.account)
  27. end
  28. it 'destroys account_pin', :aggregate_failures do
  29. expect do
  30. subject
  31. end.to change { AccountPin.where(account: user.account, target_account: kevin.account).count }.by(-1)
  32. expect(response).to have_http_status(200)
  33. expect(response.content_type)
  34. .to start_with('application/json')
  35. end
  36. end
  37. end