Fetch and return metadata

This commit is contained in:
2018-06-29 14:39:12 -07:00
parent 936aa38ff8
commit 4c0d40bd34
7 changed files with 114 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
require "spec_helper"
RSpec.describe Manifique::Agent do
describe "options" do
describe "URL validation" do
context "with invalid URL" do
@@ -19,4 +20,9 @@ RSpec.describe Manifique::Agent do
end
end
end
describe "#fetch_metadata" do
end
end

View File

@@ -0,0 +1,7 @@
require "spec_helper"
require "manifique/metadata"
RSpec.describe Manifique::Metadata do
# RSpec.describe "Manifique::MetaData" do
end

View File

@@ -2,6 +2,7 @@ require "spec_helper"
require "manifique/web_client"
RSpec.describe Manifique::WebClient do
describe "#do_get_request" do
before do
stub_request(:get, "http://example.com/404").
@@ -49,7 +50,29 @@ RSpec.describe Manifique::WebClient do
end
end
describe "#fetch_website" do
let(:web_client) { Manifique::WebClient.new(url: "https://kosmos.social/") }
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"
})
web_client.fetch_website
end
it "instantiates an HTML parser object" do
html = web_client.instance_variable_get("@html")
expect(html).to be_kind_of(Nokogiri::HTML::Document)
end
end
describe "#fetch_web_manifest" do
let(:web_client) { Manifique::WebClient.new(url: "https://kosmos.social/") }
context "link[rel=manifest] present" do
before do
index_html = File.read(File.join(__dir__, "..", "fixtures", "mastodon.html"));
@@ -62,12 +85,11 @@ RSpec.describe Manifique::WebClient do
to_return(body: manifest, status: 200, headers: {
"Content-Type": "application/json; charset=utf-8"
})
web_client.fetch_website
end
let(:web_client) { Manifique::WebClient.new(url: "https://kosmos.social") }
subject do
web_client.fetch_website
web_client.fetch_web_manifest
end
@@ -84,12 +106,11 @@ RSpec.describe Manifique::WebClient do
to_return(body: index_html, status: 200, headers: {
"Content-Type": "text/html; charset=utf-8"
})
web_client.fetch_website
end
let(:web_client) { Manifique::WebClient.new(url: "https://kosmos.social") }
subject do
web_client.fetch_website
web_client.fetch_web_manifest
end
@@ -98,4 +119,35 @@ RSpec.describe Manifique::WebClient do
end
end
end
describe "#fetch_metadata" do
let(:web_client) { Manifique::WebClient.new(url: "https://kosmos.social/") }
context "web app 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
subject { web_client.fetch_metadata }
it "returns a metadata object" do
expect(subject).to be_kind_of(Manifique::Metadata)
end
it "stores the web app manifest data" do
expect(subject.manifest).to be_kind_of(Hash)
expect(subject.manifest["name"]).to eq("kosmos.social")
end
end
end
end

View File

@@ -1,6 +1,7 @@
require "spec_helper"
RSpec.describe Manifique do
it "has a version number" do
expect(Manifique::VERSION).not_to be nil
end