mirror of
https://github.com/discourse/discourse-solved.git
synced 2026-09-16 22:52:12 -04:00
There exists a bug in the following trigger (see screenshot) where if the user has an existing solution already, they will still pass validation for "first accepted solution" due to the trust level being "any".
82 lines
2.6 KiB
Ruby
82 lines
2.6 KiB
Ruby
# frozen_string_literal: true
|
||
|
||
describe DiscourseSolved::FirstAcceptedPostSolutionValidator do
|
||
fab!(:user_tl1) { Fabricate(:user, trust_level: TrustLevel[1], refresh_auto_groups: true) }
|
||
|
||
context "when user is under max trust level" do
|
||
context "with no post accepted yet" do
|
||
it "validates the post" do
|
||
post_1 = create_post(user: user_tl1)
|
||
expect(described_class.check(post_1, trust_level: TrustLevel[2])).to eq(true)
|
||
end
|
||
end
|
||
|
||
context "with already had accepted posts" do
|
||
before do
|
||
accepted_post = create_post(user: user_tl1)
|
||
DiscourseSolved.accept_answer!(accepted_post, Discourse.system_user)
|
||
end
|
||
|
||
it "doesn’t validate the post" do
|
||
post_1 = create_post(user: user_tl1)
|
||
expect(described_class.check(post_1, trust_level: TrustLevel[2])).to eq(false)
|
||
end
|
||
end
|
||
end
|
||
|
||
context "when a user is above or equal max trust level" do
|
||
context "with no post accepted yet" do
|
||
it "doesn’t validate the post" do
|
||
post_1 = create_post(user: user_tl1)
|
||
expect(described_class.check(post_1, trust_level: TrustLevel[1])).to eq(false)
|
||
end
|
||
end
|
||
|
||
context "when a post is already accepted" do
|
||
before do
|
||
accepted_post = create_post(user: user_tl1)
|
||
DiscourseSolved.accept_answer!(accepted_post, Discourse.system_user)
|
||
end
|
||
|
||
it "doesn’t validate the post" do
|
||
post_1 = create_post(user: user_tl1)
|
||
expect(described_class.check(post_1, trust_level: TrustLevel[1])).to eq(false)
|
||
end
|
||
end
|
||
end
|
||
|
||
context "when using any trust level" do
|
||
it "validates the post" do
|
||
post_1 = create_post(user: user_tl1)
|
||
expect(described_class.check(post_1, trust_level: "any")).to eq(true)
|
||
end
|
||
|
||
it "invalidates if post user already has an accepted post" do
|
||
accepted_post = create_post(user: user_tl1)
|
||
DiscourseSolved.accept_answer!(accepted_post, Discourse.system_user)
|
||
post_1 = create_post(user: user_tl1)
|
||
expect(described_class.check(post_1, trust_level: "any")).to eq(false)
|
||
end
|
||
end
|
||
|
||
context "when user is system" do
|
||
it "doesn’t validate the post" do
|
||
post_1 = create_post(user: Discourse.system_user)
|
||
expect(described_class.check(post_1, trust_level: "any")).to eq(false)
|
||
end
|
||
end
|
||
|
||
context "when post is a PM" do
|
||
it "doesn’t validate the post" do
|
||
Group.refresh_automatic_groups!
|
||
post_1 =
|
||
create_post(
|
||
user: user_tl1,
|
||
target_usernames: [user_tl1.username],
|
||
archetype: Archetype.private_message,
|
||
)
|
||
expect(described_class.check(post_1, trust_level: "any")).to eq(false)
|
||
end
|
||
end
|
||
end
|