Discover Web App Manifest in HTML
... and return a hash of the JSON data.
This commit is contained in:
20
spec/fixtures/mastodon-web-app-manifest.json
vendored
Normal file
20
spec/fixtures/mastodon-web-app-manifest.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "kosmos.social",
|
||||
"short_name": "kosmos.social",
|
||||
"description": "A friendly place for tooting. Run by the Kosmos peeps.",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/android-chrome-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
}
|
||||
],
|
||||
"theme_color": "#282c37",
|
||||
"background_color": "#191b22",
|
||||
"display": "standalone",
|
||||
"start_url": "/web/timelines/home",
|
||||
"scope": "https://kosmos.social/",
|
||||
"share_target": {
|
||||
"url_template": "share?title={title}&text={text}&url={url}"
|
||||
}
|
||||
}
|
||||
38
spec/fixtures/mastodon.html
vendored
Normal file
38
spec/fixtures/mastodon.html
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -5,8 +5,8 @@ RSpec.describe Manifique::Agent do
|
||||
describe "URL validation" do
|
||||
context "with invalid URL" do
|
||||
it "raises an exception" do
|
||||
expect { Manifique::Agent.new }.to raise_error
|
||||
expect { Manifique::Agent.new(url: "htp://example.com") }.to raise_error
|
||||
expect { Manifique::Agent.new }.to raise_error(RuntimeError)
|
||||
expect { Manifique::Agent.new(url: "htp://example.com") }.to raise_error(RuntimeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,18 +2,18 @@ require "spec_helper"
|
||||
require "manifique/web_client"
|
||||
|
||||
RSpec.describe Manifique::WebClient do
|
||||
before do
|
||||
stub_request(:get, "http://example.com/200_empty").
|
||||
to_return(body: "", status: 200, headers: {})
|
||||
|
||||
stub_request(:get, "http://example.com/404").
|
||||
to_return(body: "", status: 404, headers: {})
|
||||
|
||||
stub_request(:get, "http://example.com/500").
|
||||
to_return(body: "", status: 500, headers: {})
|
||||
end
|
||||
|
||||
describe "#do_get_request" do
|
||||
before do
|
||||
stub_request(:get, "http://example.com/404").
|
||||
to_return(body: "", status: 404, headers: {})
|
||||
|
||||
stub_request(:get, "http://example.com/500").
|
||||
to_return(body: "", status: 500, headers: {})
|
||||
|
||||
stub_request(:get, "http://example.com/200_empty").
|
||||
to_return(body: "", status: 200, headers: {})
|
||||
end
|
||||
|
||||
context "unsuccessful requests" do
|
||||
describe "404" do
|
||||
let(:client) { Manifique::WebClient.new }
|
||||
@@ -48,4 +48,30 @@ RSpec.describe Manifique::WebClient do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#fetch_web_manifest" do
|
||||
context "link[rel=manifest] present" do
|
||||
before do
|
||||
index_html = File.read(File.join(__dir__, "..", "fixtures", "mastodon.html"));
|
||||
stub_request(:get, "https://kosmos.social/").
|
||||
to_return(body: index_html, status: 200, headers: {
|
||||
"Content-Type": "text/html; charset=utf-8"
|
||||
})
|
||||
manifest = File.read(File.join(__dir__, "..", "fixtures", "mastodon-web-app-manifest.json"));
|
||||
stub_request(:get, "https://kosmos.social/mastodon-web-app-manifest.json").
|
||||
to_return(body: manifest, status: 200, headers: {
|
||||
"Content-Type": "application/json; charset=utf-8"
|
||||
})
|
||||
end
|
||||
|
||||
let(:agent) { Manifique::WebClient.new(url: "https://kosmos.social") }
|
||||
|
||||
subject { agent.fetch_web_manifest }
|
||||
|
||||
it "fetches and returns the manifest" do
|
||||
expect(subject).to be_kind_of(Hash)
|
||||
expect(subject["name"]).to eq("kosmos.social")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user