2019-04-30 10:27:42 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 05:27:38 +03:00
|
|
|
RSpec.describe InlineOneboxController do
|
2017-07-19 15:08:54 -04:00
|
|
|
it "requires the user to be logged in" do
|
2018-06-06 12:10:59 +03:00
|
|
|
get "/inline-onebox.json", params: { urls: [] }
|
2018-01-12 14:15:10 +11:00
|
|
|
expect(response.status).to eq(403)
|
2017-07-19 15:08:54 -04:00
|
|
|
end
|
|
|
|
|
2022-07-27 18:14:14 +02:00
|
|
|
context "when logged in" do
|
2018-06-06 12:10:59 +03:00
|
|
|
let!(:user) { sign_in(Fabricate(:user)) }
|
2017-07-19 15:08:54 -04:00
|
|
|
|
|
|
|
it "returns empty JSON for empty input" do
|
2018-06-06 12:10:59 +03:00
|
|
|
get "/inline-onebox.json", params: { urls: [] }
|
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 17:04:12 +02:00
|
|
|
json = response.parsed_body
|
2017-07-19 15:08:54 -04:00
|
|
|
expect(json["inline-oneboxes"]).to eq([])
|
|
|
|
end
|
|
|
|
|
2022-07-27 18:14:14 +02:00
|
|
|
context "with topic link" do
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:topic)
|
2017-07-19 15:08:54 -04:00
|
|
|
|
|
|
|
it "returns information for a valid link" do
|
2018-06-06 12:10:59 +03:00
|
|
|
get "/inline-onebox.json", params: { urls: [topic.url] }
|
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 17:04:12 +02:00
|
|
|
json = response.parsed_body
|
2017-07-19 15:08:54 -04:00
|
|
|
onebox = json["inline-oneboxes"][0]
|
|
|
|
|
|
|
|
expect(onebox).to be_present
|
|
|
|
expect(onebox["url"]).to eq(topic.url)
|
|
|
|
expect(onebox["title"]).to eq(topic.title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|