|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +describe DiscourseAi::Utils::Research::Filter do |
| 4 | + describe "integration tests" do |
| 5 | + before_all { SiteSetting.min_topic_title_length = 3 } |
| 6 | + |
| 7 | + fab!(:user) |
| 8 | + |
| 9 | + fab!(:feature_tag) { Fabricate(:tag, name: "feature") } |
| 10 | + fab!(:bug_tag) { Fabricate(:tag, name: "bug") } |
| 11 | + |
| 12 | + fab!(:announcement_category) { Fabricate(:category, name: "Announcements") } |
| 13 | + fab!(:feedback_category) { Fabricate(:category, name: "Feedback") } |
| 14 | + |
| 15 | + fab!(:feature_topic) do |
| 16 | + Fabricate( |
| 17 | + :topic, |
| 18 | + user: user, |
| 19 | + tags: [feature_tag], |
| 20 | + category: announcement_category, |
| 21 | + title: "New Feature Discussion", |
| 22 | + ) |
| 23 | + end |
| 24 | + |
| 25 | + fab!(:bug_topic) do |
| 26 | + Fabricate( |
| 27 | + :topic, |
| 28 | + tags: [bug_tag], |
| 29 | + user: user, |
| 30 | + category: announcement_category, |
| 31 | + title: "Bug Report", |
| 32 | + ) |
| 33 | + end |
| 34 | + |
| 35 | + fab!(:feature_bug_topic) do |
| 36 | + Fabricate( |
| 37 | + :topic, |
| 38 | + tags: [feature_tag, bug_tag], |
| 39 | + user: user, |
| 40 | + category: feedback_category, |
| 41 | + title: "Feature with Bug", |
| 42 | + ) |
| 43 | + end |
| 44 | + |
| 45 | + fab!(:no_tag_topic) do |
| 46 | + Fabricate(:topic, user: user, category: feedback_category, title: "General Discussion") |
| 47 | + end |
| 48 | + |
| 49 | + fab!(:feature_post) { Fabricate(:post, topic: feature_topic, user: user) } |
| 50 | + fab!(:bug_post) { Fabricate(:post, topic: bug_topic, user: user) } |
| 51 | + fab!(:feature_bug_post) { Fabricate(:post, topic: feature_bug_topic, user: user) } |
| 52 | + fab!(:no_tag_post) { Fabricate(:post, topic: no_tag_topic, user: user) } |
| 53 | + |
| 54 | + describe "tag filtering" do |
| 55 | + it "correctly filters posts by tags" do |
| 56 | + filter = described_class.new("tag:feature") |
| 57 | + expect(filter.search.pluck(:id)).to contain_exactly(feature_post.id, feature_bug_post.id) |
| 58 | + |
| 59 | + filter = described_class.new("tag:feature,bug") |
| 60 | + expect(filter.search.pluck(:id)).to contain_exactly( |
| 61 | + feature_bug_post.id, |
| 62 | + bug_post.id, |
| 63 | + feature_post.id, |
| 64 | + ) |
| 65 | + |
| 66 | + filter = described_class.new("tags:bug") |
| 67 | + expect(filter.search.pluck(:id)).to contain_exactly(bug_post.id, feature_bug_post.id) |
| 68 | + |
| 69 | + filter = described_class.new("tag:nonexistent") |
| 70 | + expect(filter.search.count).to eq(0) |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + describe "category filtering" do |
| 75 | + it "correctly filters posts by categories" do |
| 76 | + filter = described_class.new("category:Announcements") |
| 77 | + expect(filter.search.pluck(:id)).to contain_exactly(feature_post.id, bug_post.id) |
| 78 | + |
| 79 | + filter = described_class.new("category:Announcements,Feedback") |
| 80 | + expect(filter.search.pluck(:id)).to contain_exactly( |
| 81 | + feature_post.id, |
| 82 | + bug_post.id, |
| 83 | + feature_bug_post.id, |
| 84 | + no_tag_post.id, |
| 85 | + ) |
| 86 | + |
| 87 | + filter = described_class.new("categories:Feedback") |
| 88 | + expect(filter.search.pluck(:id)).to contain_exactly(feature_bug_post.id, no_tag_post.id) |
| 89 | + |
| 90 | + filter = described_class.new("category:Feedback tag:feature") |
| 91 | + expect(filter.search.pluck(:id)).to contain_exactly(feature_bug_post.id) |
| 92 | + end |
| 93 | + end |
| 94 | + end |
| 95 | +end |
0 commit comments