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