discourse-topic-voting/spec/requests/search_controller_spec.rb
Natalie Tay 3d3037729c
DEV: Scope topic voting tables to avoid confusion with post voting (#196)
Renaming discourse_voting to topic_voting since there are two forms of voting in Discourse - posts and topics.

This PR also moves a OnceOff into a post migration. The post migration will be executed, but should ideally be a no-op. This allows us to not have to maintain the OnceOff as it had to be modified before with a previous migration. I considered removing this file altogether, but I don't think there is anything negative from just converting it into a migration, and it might be useful in the unlikely scenario that a forum from the past has never ran the OnceOff before.
2024-07-17 20:26:40 +08:00

44 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require "rails_helper"
describe SearchController do
fab!(:user)
fab!(:category)
fab!(:topic) { Fabricate(:topic, category: category) }
fab!(:topic_2) { Fabricate(:topic, category: category) }
fab!(:post_1) do
SearchIndexer.enable
Fabricate(:post, topic: topic, raw: "this is an awesome topic")
end
fab!(:post_2) do
SearchIndexer.enable
Fabricate(:post, topic: topic_2, raw: "this is an awesome topic")
end
before do
DiscourseTopicVoting::CategorySetting.create!(category: category)
SiteSetting.topic_voting_enabled = true
sign_in(user)
end
it "can search for posts ordered by votes" do
post "/voting/vote.json", params: { topic_id: post_2.topic_id }
expect(response.status).to eq(200)
get "/search/query.json", params: { term: "awesome order:votes" }
expect(response.status).to eq(200)
data = response.parsed_body
expect(data["posts"].length).to eq(2)
expect(data["posts"][0]["id"]).to eq(post_2.id)
expect(data["posts"][1]["id"]).to eq(post_1.id)
end
end