You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.5 KiB

  1. require 'rails_helper'
  2. describe Api::V1::Lists::AccountsController do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let(:list) { Fabricate(:list, account: user.account) }
  7. before do
  8. follow = Fabricate(:follow, account: user.account)
  9. list.accounts << follow.target_account
  10. allow(controller).to receive(:doorkeeper_token) { token }
  11. end
  12. describe 'GET #index' do
  13. let(:scopes) { 'read:lists' }
  14. it 'returns http success' do
  15. get :show, params: { list_id: list.id }
  16. expect(response).to have_http_status(200)
  17. end
  18. end
  19. describe 'POST #create' do
  20. let(:scopes) { 'write:lists' }
  21. let(:bob) { Fabricate(:account, username: 'bob') }
  22. before do
  23. user.account.follow!(bob)
  24. post :create, params: { list_id: list.id, account_ids: [bob.id] }
  25. end
  26. it 'returns http success' do
  27. expect(response).to have_http_status(200)
  28. end
  29. it 'adds account to the list' do
  30. expect(list.accounts.include?(bob)).to be true
  31. end
  32. end
  33. describe 'DELETE #destroy' do
  34. let(:scopes) { 'write:lists' }
  35. before do
  36. delete :destroy, params: { list_id: list.id, account_ids: [list.accounts.first.id] }
  37. end
  38. it 'returns http success' do
  39. expect(response).to have_http_status(200)
  40. end
  41. it 'removes account from the list' do
  42. expect(list.accounts.count).to eq 0
  43. end
  44. end
  45. end