DEV: Add specs for hashtags related code (#18526)

Adding a couple of small specs to code around hashtags
for tags and categories since I will be working in this
area soon and these were not covered.
This commit is contained in:
Martin Brennan 2022-10-11 09:04:51 +10:00 committed by GitHub
parent dc89b72d46
commit cab173d3b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -15,4 +15,35 @@ RSpec.describe PrettyText::Helpers do
expect(result[short_url][:url]).to eq("https://awesome.com#{upload.url}")
end
end
describe ".category_tag_hashtag_lookup" do
fab!(:tag) { Fabricate(:tag, name: "somecooltag") }
fab!(:category) do
Fabricate(:category, name: "Some Awesome Category", slug: "someawesomecategory")
end
it "handles tags based on slug with TAG_HASHTAG_POSTFIX" do
expect(
PrettyText::Helpers.category_tag_hashtag_lookup(
+"somecooltag#{PrettyText::Helpers::TAG_HASHTAG_POSTFIX}",
),
).to eq([tag.url, "somecooltag"])
end
it "handles categories based on slug" do
expect(PrettyText::Helpers.category_tag_hashtag_lookup("someawesomecategory")).to eq(
[category.url, "someawesomecategory"],
)
end
it "handles tags based on slug without TAG_HASHTAG_POSTFIX" do
expect(PrettyText::Helpers.category_tag_hashtag_lookup(+"somecooltag")).to eq(
[tag.url, "somecooltag"],
)
end
it "returns nil when no tag or category that matches exists" do
expect(PrettyText::Helpers.category_tag_hashtag_lookup("blah")).to eq(nil)
end
end
end

View File

@ -32,6 +32,16 @@ RSpec.describe HashtagsController do
)
end
it "handles tags with the TAG_HASHTAG_POSTFIX" do
get "/hashtags.json", params: { slugs: ["#{tag.name}#{PrettyText::Helpers::TAG_HASHTAG_POSTFIX}"] }
expect(response.status).to eq(200)
expect(response.parsed_body).to eq(
"categories" => {},
"tags" => { tag.name => tag.full_url }
)
end
it "does not return restricted categories or hidden tags" do
get "/hashtags.json", params: { slugs: [private_category.slug, hidden_tag.name] }