about summary refs log tree commit diff
path: root/spec/controllers/api
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2018-06-07 05:13:49 -0500
committerDavid Yip <yipdw@member.fsf.org>2018-06-07 05:13:49 -0500
commit8142bd2553e7819722fdfc401e06cb10eeddd230 (patch)
treed771e65a58d3c69ba1c08c3fc145f24b5b806274 /spec/controllers/api
parentf8d50a40701f344ea7c2a0e5475bbcbc727ef930 (diff)
parent2304d52599bfd3a907931971a94b9b68f229ab0a (diff)
Merge remote-tracking branch 'tootsuite/master' into merge-upstream
  Conflicts:
 	app/models/status.rb

The conflict in the Status model was due to
https://github.com/tootsuite/mastodon/commit/5bf500338478f819a65d25636a0af61a482972d3.
It was resolved by accepting tootsuite's changes.
Diffstat (limited to 'spec/controllers/api')
-rw-r--r--spec/controllers/api/web/embeds_controller_spec.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/controllers/api/web/embeds_controller_spec.rb b/spec/controllers/api/web/embeds_controller_spec.rb
new file mode 100644
index 000000000..6b7297189
--- /dev/null
+++ b/spec/controllers/api/web/embeds_controller_spec.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe Api::Web::EmbedsController do
+  render_views
+
+  let(:user) { Fabricate(:user) }
+  before { sign_in user }
+
+  describe 'POST #create' do
+    subject(:response) { post :create, params: { url: url } }
+    subject(:body) { JSON.parse(response.body, symbolize_names: true) }
+
+    context 'when successfully finds status' do
+      let(:status) { Fabricate(:status) }
+      let(:url) { "http://#{ Rails.configuration.x.web_domain }/@#{status.account.username}/#{status.id}" }
+
+      it 'returns a right response' do
+        expect(response).to have_http_status :ok
+        expect(body[:author_name]).to eq status.account.username
+      end
+    end
+
+    context 'when fails to find status' do
+      let(:url) { 'https://host.test/oembed.html' }
+      let(:service_instance) { double('fetch_oembed_service') }
+
+      before do
+        allow(FetchOEmbedService).to receive(:new) { service_instance }
+        allow(service_instance).to receive(:call) { call_result }
+      end
+
+      context 'when successfully fetching oembed' do
+        let(:call_result) { { result: :ok } }
+
+        it 'returns a right response' do
+          expect(response).to have_http_status :ok
+          expect(body[:result]).to eq 'ok'
+        end
+      end
+
+      context 'when fails to fetch oembed' do
+        let(:call_result) { nil }
+
+        it 'returns a right response' do
+          expect(response).to have_http_status :not_found
+        end
+      end
+    end
+  end
+end