* Use regex to replace with https * Refactor a bit * Update logic to handle edge cases * url being nil * url not a valid URL (weak validation, checks for starting string of http) * Add new test case for http to https conversion
25 lines
845 B
Ruby
25 lines
845 B
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Users::SafeRemoteProfileImageUrl, type: :service do
|
|
it "returns the url if passed for proper URLs" do
|
|
url = "https://image.com/image.png"
|
|
expect(described_class.call(url)).to eq(url)
|
|
end
|
|
|
|
it "returns fallback image if passed nil" do
|
|
expect(described_class.call(nil)).to start_with("https://emojipedia-us.s3")
|
|
end
|
|
|
|
it "returns fallback image if passed blank" do
|
|
expect(described_class.call("")).to start_with("https://emojipedia-us.s3")
|
|
end
|
|
|
|
it "returns fallback image if passed non-URL" do
|
|
expect(described_class.call("image")).to start_with("https://emojipedia-us.s3")
|
|
end
|
|
|
|
it "returns a secure HTTPS image link if pass a regular HTTP link" do
|
|
url = "http://image.com/image.jpg"
|
|
expect(described_class.call(url)).to eq "https://image.com/image.jpg"
|
|
end
|
|
end
|