mirror of
https://github.com/discourse/discourse.git
synced 2024-12-14 05:43:44 +08:00
283b08d45f
* Move onebox gem in core library * Update template file path * Remove warning for onebox gem caching * Remove onebox version file * Remove onebox gem * Add sanitize gem * Require onebox library in lazy-yt plugin * Remove onebox web specific code This code was used in standalone onebox Sinatra application * Merge Discourse specific AllowlistedGenericOnebox engine in core * Fix onebox engine filenames to match class name casing * Move onebox specs from gem into core * DEV: Rename `response` helper to `onebox_response` Fixes a naming collision. * Require rails_helper * Don't use `before/after(:all)` * Whitespace * Remove fakeweb * Remove poor unit tests * DEV: Re-add fakeweb, plugins are using it * Move onebox helpers * Stub Instagram API * FIX: Follow additional redirect status codes (#476) Don’t throw errors if we encounter 303, 307 or 308 HTTP status codes in responses * Remove an empty file * DEV: Update the license file Using the copy from https://choosealicense.com/licenses/gpl-2.0/# Hopefully this will enable GitHub to show the license UI? * DEV: Update embedded copyrights * DEV: Add Onebox copyright notice * DEV: Add MIT license, convert COPYRIGHT.txt to md * DEV: Remove an incorrect copyright claim Co-authored-by: Jarek Radosz <jradosz@gmail.com> Co-authored-by: jbrw <jamie@goatforce5.org>
75 lines
3.7 KiB
Ruby
75 lines
3.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rails_helper"
|
|
|
|
describe Onebox::Engine::GoogleMapsOnebox do
|
|
URLS = {
|
|
short: {
|
|
test: "https://goo.gl/maps/rEG3D",
|
|
redirect: [302, :long],
|
|
expect: "https://maps.google.de/maps?sll=40.689249,-74.0445&sspn=0.0062479,0.0109864&cid=4667599994556318251&q=Statue+of+Liberty+National+Monument&output=embed&dg=ntvb&ll=40.689249,-74.0445&spn=0.0062479,0.0109864",
|
|
},
|
|
long: {
|
|
test: "https://www.google.de/maps/place/Statue+of+Liberty+National+Monument/@40.689249,-74.0445,17z/data=!3m1!4b1!4m2!3m1!1s0x89c25090129c363d:0x40c6a5770d25022b",
|
|
redirect: [301, :canonical],
|
|
expect: "https://maps.google.de/maps?sll=40.689249,-74.0445&sspn=0.0062479,0.0109864&cid=4667599994556318251&q=Statue+of+Liberty+National+Monument&output=embed&dg=ntvb&ll=40.689249,-74.0445&spn=0.0062479,0.0109864",
|
|
},
|
|
canonical: {
|
|
test: "https://maps.google.de/maps?sll=40.689249,-74.0445&sspn=0.0062479,0.0109864&cid=4667599994556318251&q=Statue+of+Liberty+National+Monument&output=classic&dg=ntvb",
|
|
expect: "https://maps.google.de/maps?sll=40.689249,-74.0445&sspn=0.0062479,0.0109864&cid=4667599994556318251&q=Statue+of+Liberty+National+Monument&output=embed&dg=ntvb&ll=40.689249,-74.0445&spn=0.0062479,0.0109864",
|
|
},
|
|
custom: {
|
|
test: "https://www.google.com/maps/d/edit?mid=zPYyZFrHi1MU.kX85W_Y2y2_E",
|
|
expect: "https://www.google.com/maps/d/embed?mid=zPYyZFrHi1MU.kX85W_Y2y2_E",
|
|
},
|
|
streetview: {
|
|
test: "https://www.google.com/maps/@46.414384,10.013947,3a,75y,232.83h,99.08t/data=!3m5!1e1!3m3!1s9WgYUb5quXDjqqFd3DWI6A!2e0!3e5?hl=de",
|
|
expect: "https://www.google.com/maps/embed?pb=!3m2!2sen!4v0!6m8!1m7!1s9WgYUb5quXDjqqFd3DWI6A!2m2!1d46.414384!2d10.013947!3f232.83!4f9.908!5f0.75",
|
|
streetview: true
|
|
},
|
|
unresolveable: {
|
|
test: "https://www.google.com/maps/place/Den+Abattoir/@51.2285173,4.4336702,17z/data=!4m7!1m4!3m3!1s0x47c3f7a5ac48e237:0x63d716018f584a33!2zUGnDqXRyYWlu!3b1!3m1!1s0x0000000000000000:0xfbfac0c41c32471a",
|
|
redirect: [302, "https://www.google.com/maps/place/Den+Abattoir/@51.2285173,4.4336702,17z/data=!4m7!1m4!3m3!1s0x47c3f7a5ac48e237:0x63d716018f584a33!2zUGnDqXRyYWlu!3b1!3m1!1s0x0000000000000000:0xfbfac0c41c32471a?dg=dbrw&newdg=1"],
|
|
expect: "https://maps.google.com/maps?ll=51.2285173,4.4336702&z=17&output=embed&dg=ntvb&q=Den+Abattoir&cid=18157036796216755994"
|
|
},
|
|
satellite: {
|
|
test: "https://www.google.de/maps/@40.6894264,-74.0449146,758m/data=!3m1!1e3",
|
|
redirect: [302, "https://www.google.de/maps/@40.6894264,-74.0449146,758m/data=!3m1!1e3?dg=dbrw&newdg=1"],
|
|
expect: "https://maps.google.com/maps?ll=40.6894264,-74.0449146&z=16&output=embed&dg=ntvb"
|
|
}
|
|
}
|
|
|
|
# Register URL redirects
|
|
before do
|
|
URLS.values.each do |t|
|
|
status, location = *t[:redirect]
|
|
location = URLS[location][:test] if location.is_a? Symbol
|
|
|
|
stub_request(:head, t[:test])
|
|
.to_return(status: status, headers: { location: location })
|
|
end
|
|
end
|
|
|
|
# Prevent sleep from wasting our time when we test with strange redirects
|
|
subject do
|
|
described_class.send(:allocate).tap do |obj|
|
|
obj.stubs(:sleep)
|
|
obj.send(:initialize, link)
|
|
end
|
|
end
|
|
|
|
let(:data) { Onebox::Helpers.symbolize_keys(subject.send(:data)) }
|
|
let(:link) { |example| URLS[example.metadata[:urltype] || :short][:test] }
|
|
|
|
include_context "an engine", urltype: :short
|
|
|
|
URLS.each do |kind, t|
|
|
it "processes #{kind.to_s} url correctly", urltype: kind do
|
|
expect(subject.url).to eq t[:expect]
|
|
expect(subject.streetview?).to t[:streetview] ? be_truthy : be_falsey
|
|
expect(subject.to_html).to include("<iframe")
|
|
expect(subject.placeholder_html).to include("placeholder-icon map")
|
|
end
|
|
end
|
|
end
|