# frozen_string_literal: true RSpec.describe Onebox::Engine::YoutubeOnebox do before do stub_request(:get, "https://www.youtube.com/watch?feature=player_embedded&v=21Lk4YiASMo").to_return(status: 200, body: onebox_response("youtube")) stub_request(:get, "https://youtu.be/21Lk4YiASMo").to_return(status: 200, body: onebox_response("youtube")) stub_request(:get, "https://www.youtube.com/embed/21Lk4YiASMo").to_return(status: 200, body: onebox_response("youtube")) stub_request(:get, "http://www.youtube.com/watch?v=21Lk4YiASMo").to_return(status: 200, body: onebox_response("youtube")) stub_request(:get, "https://www.youtube.com/watch?v=21Lk4YiASMo").to_return(status: 200, body: onebox_response("youtube")) stub_request(:get, "https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ").to_return(status: 200, body: onebox_response("youtube-channel")) stub_request(:get, "http://www.youtube.com/user/googlechrome").to_return(status: 200, body: onebox_response("youtube-channel")) stub_request(:get, "https://www.youtube.com/playlist?list=PL5308B2E5749D1696").to_return(status: 200, body: onebox_response("youtube-playlist")) stub_request(:get, "https://www.youtube.com/embed/KCyIfcevExE").to_return(status: 200, body: onebox_response("youtube-embed")) stub_request(:get, "https://www.youtube.com/embed/VvoFuaLAslw").to_return(status: 200, body: onebox_response("youtube-shorts")) end it "adds wmode=opaque" do expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo').to_s).to match(/wmode=opaque/) end it "rewrites URLs for videos to be HTTPS" do # match: plain HTTP and protocol agnostic regex = /(http:|["']\/\/)/ expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo').to_s).not_to match(regex) expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo').placeholder_html).not_to match(regex) expect(Onebox.preview('https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ').to_s).not_to match(regex) end it "can onebox a channel page" do expect(Onebox.preview('https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ').to_s).to match(/Google Chrome/) end it "can onebox a playlist" do expect(Onebox.preview('https://www.youtube.com/playlist?list=PL5308B2E5749D1696').to_s).to match(/iframe/) placeholder_html = Onebox.preview('https://www.youtube.com/playlist?list=PL5308B2E5749D1696').placeholder_html expect(placeholder_html).to match(/