logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

tag_manager_spec.rb (5482B)


  1. require 'rails_helper'
  2. RSpec.describe TagManager do
  3. describe '#local_domain?' do
  4. # The following comparisons MUST be case-insensitive.
  5. around do |example|
  6. original_local_domain = Rails.configuration.x.local_domain
  7. Rails.configuration.x.local_domain = 'domain'
  8. example.run
  9. Rails.configuration.x.local_domain = original_local_domain
  10. end
  11. it 'returns true for nil' do
  12. expect(TagManager.instance.local_domain?(nil)).to eq true
  13. end
  14. it 'returns true if the slash-stripped string equals to local domain' do
  15. expect(TagManager.instance.local_domain?('DoMaIn/')).to eq true
  16. end
  17. it 'returns false for irrelevant string' do
  18. expect(TagManager.instance.local_domain?('DoMaIn!')).to eq false
  19. end
  20. end
  21. describe '#web_domain?' do
  22. # The following comparisons MUST be case-insensitive.
  23. around do |example|
  24. original_web_domain = Rails.configuration.x.web_domain
  25. Rails.configuration.x.web_domain = 'domain'
  26. example.run
  27. Rails.configuration.x.web_domain = original_web_domain
  28. end
  29. it 'returns true for nil' do
  30. expect(TagManager.instance.web_domain?(nil)).to eq true
  31. end
  32. it 'returns true if the slash-stripped string equals to web domain' do
  33. expect(TagManager.instance.web_domain?('DoMaIn/')).to eq true
  34. end
  35. it 'returns false for string with irrelevant characters' do
  36. expect(TagManager.instance.web_domain?('DoMaIn!')).to eq false
  37. end
  38. end
  39. describe '#normalize_domain' do
  40. it 'returns nil if the given parameter is nil' do
  41. expect(TagManager.instance.normalize_domain(nil)).to eq nil
  42. end
  43. it 'returns normalized domain' do
  44. expect(TagManager.instance.normalize_domain('DoMaIn/')).to eq 'domain'
  45. end
  46. end
  47. describe '#local_url?' do
  48. around do |example|
  49. original_web_domain = Rails.configuration.x.web_domain
  50. example.run
  51. Rails.configuration.x.web_domain = original_web_domain
  52. end
  53. it 'returns true if the normalized string with port is local URL' do
  54. Rails.configuration.x.web_domain = 'domain:42'
  55. expect(TagManager.instance.local_url?('https://DoMaIn:42/')).to eq true
  56. end
  57. it 'returns true if the normalized string without port is local URL' do
  58. Rails.configuration.x.web_domain = 'domain'
  59. expect(TagManager.instance.local_url?('https://DoMaIn/')).to eq true
  60. end
  61. it 'returns false for string with irrelevant characters' do
  62. Rails.configuration.x.web_domain = 'domain'
  63. expect(TagManager.instance.local_url?('https://domainn/')).to eq false
  64. end
  65. end
  66. describe '#same_acct?' do
  67. # The following comparisons MUST be case-insensitive.
  68. it 'returns true if the needle has a correct username and domain for remote user' do
  69. expect(TagManager.instance.same_acct?('username@domain', 'UsErNaMe@DoMaIn')).to eq true
  70. end
  71. it 'returns false if the needle is missing a domain for remote user' do
  72. expect(TagManager.instance.same_acct?('username@domain', 'UsErNaMe')).to eq false
  73. end
  74. it 'returns false if the needle has an incorrect domain for remote user' do
  75. expect(TagManager.instance.same_acct?('username@domain', 'UsErNaMe@incorrect')).to eq false
  76. end
  77. it 'returns false if the needle has an incorrect username for remote user' do
  78. expect(TagManager.instance.same_acct?('username@domain', 'incorrect@DoMaIn')).to eq false
  79. end
  80. it 'returns true if the needle has a correct username and domain for local user' do
  81. expect(TagManager.instance.same_acct?('username', 'UsErNaMe@Cb6E6126.nGrOk.Io')).to eq true
  82. end
  83. it 'returns true if the needle is missing a domain for local user' do
  84. expect(TagManager.instance.same_acct?('username', 'UsErNaMe')).to eq true
  85. end
  86. it 'returns false if the needle has an incorrect username for local user' do
  87. expect(TagManager.instance.same_acct?('username', 'UsErNaM@Cb6E6126.nGrOk.Io')).to eq false
  88. end
  89. it 'returns false if the needle has an incorrect domain for local user' do
  90. expect(TagManager.instance.same_acct?('username', 'incorrect@Cb6E6126.nGrOk.Io')).to eq false
  91. end
  92. end
  93. describe '#url_for' do
  94. let(:alice) { Fabricate(:account, username: 'alice') }
  95. subject { TagManager.instance.url_for(target) }
  96. context 'activity object' do
  97. let(:target) { Fabricate(:status, account: alice, reblog: Fabricate(:status)).stream_entry }
  98. it 'returns the unique tag for status' do
  99. expect(target.object_type).to eq :activity
  100. is_expected.to eq "https://cb6e6126.ngrok.io/@alice/#{target.id}"
  101. end
  102. end
  103. context 'comment object' do
  104. let(:target) { Fabricate(:status, account: alice, reply: true) }
  105. it 'returns the unique tag for status' do
  106. expect(target.object_type).to eq :comment
  107. is_expected.to eq "https://cb6e6126.ngrok.io/@alice/#{target.id}"
  108. end
  109. end
  110. context 'note object' do
  111. let(:target) { Fabricate(:status, account: alice, reply: false, thread: nil) }
  112. it 'returns the unique tag for status' do
  113. expect(target.object_type).to eq :note
  114. is_expected.to eq "https://cb6e6126.ngrok.io/@alice/#{target.id}"
  115. end
  116. end
  117. context 'person object' do
  118. let(:target) { alice }
  119. it 'returns the URL for account' do
  120. expect(target.object_type).to eq :person
  121. is_expected.to eq 'https://cb6e6126.ngrok.io/@alice'
  122. end
  123. end
  124. end
  125. end