accounts_show_spec.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe 'GET /api/v1/accounts/{account_id}' do
  4. it 'returns account entity as 200 OK' do
  5. account = Fabricate(:account)
  6. get "/api/v1/accounts/#{account.id}"
  7. aggregate_failures do
  8. expect(response).to have_http_status(200)
  9. expect(body_as_json[:id]).to eq(account.id.to_s)
  10. end
  11. end
  12. it 'returns 404 if account not found' do
  13. get '/api/v1/accounts/1'
  14. aggregate_failures do
  15. expect(response).to have_http_status(404)
  16. expect(body_as_json[:error]).to eq('Record not found')
  17. end
  18. end
  19. context 'when with token' do
  20. it 'returns account entity as 200 OK if token is valid' do
  21. account = Fabricate(:account)
  22. user = Fabricate(:user, account: account)
  23. token = Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:accounts').token
  24. get "/api/v1/accounts/#{account.id}", headers: { Authorization: "Bearer #{token}" }
  25. aggregate_failures do
  26. expect(response).to have_http_status(200)
  27. expect(body_as_json[:id]).to eq(account.id.to_s)
  28. end
  29. end
  30. it 'returns 403 if scope of token is invalid' do
  31. account = Fabricate(:account)
  32. user = Fabricate(:user, account: account)
  33. token = Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:statuses').token
  34. get "/api/v1/accounts/#{account.id}", headers: { Authorization: "Bearer #{token}" }
  35. aggregate_failures do
  36. expect(response).to have_http_status(403)
  37. expect(body_as_json[:error]).to eq('This action is outside the authorized scopes')
  38. end
  39. end
  40. end
  41. end