embeds_controller_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Api::Web::EmbedsController do
  4. render_views
  5. let(:user) { Fabricate(:user) }
  6. before { sign_in user }
  7. describe 'POST #create' do
  8. subject(:response) { post :create, params: { url: url } }
  9. subject(:body) { JSON.parse(response.body, symbolize_names: true) }
  10. context 'when successfully finds status' do
  11. let(:status) { Fabricate(:status) }
  12. let(:url) { "http://#{Rails.configuration.x.web_domain}/@#{status.account.username}/#{status.id}" }
  13. it 'returns a right response' do
  14. expect(response).to have_http_status :ok
  15. expect(body[:author_name]).to eq status.account.username
  16. end
  17. end
  18. context 'when fails to find status' do
  19. let(:url) { 'https://host.test/oembed.html' }
  20. let(:service_instance) { double('fetch_oembed_service') }
  21. before do
  22. allow(FetchOEmbedService).to receive(:new) { service_instance }
  23. allow(service_instance).to receive(:call) { call_result }
  24. end
  25. context 'when successfully fetching oembed' do
  26. let(:call_result) { { result: :ok } }
  27. it 'returns a right response' do
  28. expect(response).to have_http_status :ok
  29. expect(body[:result]).to eq 'ok'
  30. end
  31. end
  32. context 'when fails to fetch oembed' do
  33. let(:call_result) { nil }
  34. it 'returns a right response' do
  35. expect(response).to have_http_status :not_found
  36. end
  37. end
  38. end
  39. end
  40. end