module DiasporaFederation
describe WebFinger::HCard do
let(:guid) { "abcdef0123456789" }
let(:handle) { "user@pod.example.tld" }
let(:first_name) { "Test" }
let(:last_name) { "Testington" }
let(:name) { "#{first_name} #{last_name}" }
let(:url) { "https://pod.example.tld/users/me" }
let(:photo_url) { "https://pod.example.tld/uploads/f.jpg" }
let(:photo_url_m) { "https://pod.example.tld/uploads/m.jpg" }
let(:photo_url_s) { "https://pod.example.tld/uploads/s.jpg" }
let(:key) { "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----" }
let(:searchable) { true }
let(:html) {
<<-HTML
#{name}
#{name}
User profile
- Uid
-
#{guid}
- Nickname
-
#{handle.split('@').first}
- Full_name
-
#{name}
- Searchable
-
#{searchable}
- Key
-
#{key}
- First_name
-
#{first_name}
- Family_name
-
#{last_name}
- Url
-
#{url}
- Photo
-
- Photo_medium
-
- Photo_small
-
HTML
}
it "must not create blank instances" do
expect { WebFinger::HCard.new }.to raise_error NameError
end
context "generation" do
it "creates an instance from a data hash" do
hc = WebFinger::HCard.from_profile(
guid: guid,
diaspora_handle: handle,
full_name: name,
url: url,
photo_full_url: photo_url,
photo_medium_url: photo_url_m,
photo_small_url: photo_url_s,
pubkey: key,
searchable: searchable,
first_name: first_name,
last_name: last_name
)
expect(hc.to_html).to eq(html)
end
it "fails if some params are missing" do
expect {
WebFinger::HCard.from_profile(
guid: guid,
diaspora_handle: handle
)
}.to raise_error WebFinger::InvalidData
end
it "fails if nothing was given" do
expect { WebFinger::HCard.from_profile({}) }.to raise_error WebFinger::InvalidData
end
it "fails if nil was given" do
expect { WebFinger::HCard.from_profile(nil) }.to raise_error WebFinger::InvalidData
end
end
context "parsing" do
it "reads its own output" do
hc = WebFinger::HCard.from_html(html)
expect(hc.guid).to eq(guid)
expect(hc.nickname).to eq(handle.split("@").first)
expect(hc.full_name).to eq(name)
expect(hc.url).to eq(url)
expect(hc.photo_full_url).to eq(photo_url)
expect(hc.photo_medium_url).to eq(photo_url_m)
expect(hc.photo_small_url).to eq(photo_url_s)
expect(hc.pubkey).to eq(key)
expect(hc.searchable).to eq(searchable.to_s)
expect(hc.first_name).to eq(first_name)
expect(hc.last_name).to eq(last_name)
end
it "reads old-style HTML" do
historic_html = <<-HTML
#{name}
User profile
- Nickname
-
#{name}
- First name
-
#{first_name}
- Family name
-
#{last_name}
- Full name
-
#{name}
- URL
-
#{url}
- Photo
-
- Photo
-
- Photo
-
- Searchable
-
#{searchable}
HTML
hc = WebFinger::HCard.from_html(historic_html)
expect(hc.url).to eq(url)
expect(hc.photo_full_url).to eq(photo_url)
expect(hc.photo_medium_url).to eq(photo_url_m)
expect(hc.photo_small_url).to eq(photo_url_s)
expect(hc.searchable).to eq(searchable.to_s)
expect(hc.first_name).to eq(first_name)
expect(hc.last_name).to eq(last_name)
end
it "fails if the document is incomplete" do
invalid_html = <<-HTML
#{name}
HTML
expect { WebFinger::HCard.from_html(invalid_html) }.to raise_error WebFinger::InvalidData
end
it "fails if the document is not HTML" do
expect { WebFinger::HCard.from_html("") }.to raise_error WebFinger::InvalidData
end
end
end
end