1 # frozen_string_literal: true
5 class SocialLinkTest < ActiveSupport::TestCase
7 social_link = create(:social_link)
9 assert_predicate social_link, :valid?
10 social_link.user = nil
11 assert_not_predicate social_link, :valid?
15 social_link = create(:social_link)
17 assert_predicate social_link, :valid?
19 assert_not_predicate social_link, :valid?
22 def test_url_https_valid
23 social_link = create(:social_link)
25 assert_predicate social_link, :valid?
26 social_link.url = "test"
27 assert_not_predicate social_link, :valid?
30 def test_parsed_platform
31 social_link = create(:social_link, :url => "https://github.com/test")
33 assert_equal "github", social_link.parsed[:platform]
34 assert_equal "test", social_link.parsed[:name]
37 def test_parsed_platform_with_www
38 social_link = create(:social_link, :url => "http://www.github.com/test")
40 assert_equal "github", social_link.parsed[:platform]
41 assert_equal "test", social_link.parsed[:name]
44 def test_parsed_platform_custom_name
45 social_link = create(:social_link, :url => "https://discord.com/users/0")
47 assert_equal "discord", social_link.parsed[:platform]
48 assert_equal "Discord", social_link.parsed[:name]
51 def test_parsed_platform_mastodon
52 social_link = create(:social_link, :url => "https://mastodon.social/@test")
54 assert_equal "mastodon", social_link.parsed[:platform]
55 assert_equal "@test@mastodon.social", social_link.parsed[:name]
58 def test_parsed_platform_mastodon_parsed
59 social_link = create(:social_link, :url => "@test@mapstodon.space")
61 assert_equal "https://mapstodon.space/@test", social_link.parsed[:url]
62 assert_equal "mastodon", social_link.parsed[:platform]
63 assert_equal "@test@mapstodon.space", social_link.parsed[:name]
66 def test_parsed_platform_other
67 url = "https://test.com/test"
68 expected = "test.com/test"
69 social_link = create(:social_link, :url => url)
71 assert_nil social_link.parsed[:platform]
72 assert_equal social_link.parsed[:name], expected