2021-11-12 10:00:48 -05:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
|
require "rails_helper"
|
2021-11-12 10:00:48 -05:00
|
|
|
|
|
|
|
|
|
describe FirstAcceptedPostSolutionValidator do
|
2023-12-13 21:28:50 -05:00
|
|
|
|
fab!(:user_tl1) { Fabricate(:user, trust_level: TrustLevel[1], refresh_auto_groups: true) }
|
2021-11-12 10:00:48 -05:00
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
|
context "when user is under max trust level" do
|
|
|
|
|
context "with no post accepted yet" do
|
|
|
|
|
it "validates the post" do
|
2021-11-12 10:00:48 -05:00
|
|
|
|
post_1 = create_post(user: user_tl1)
|
|
|
|
|
expect(described_class.check(post_1, trust_level: TrustLevel[2])).to eq(true)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
|
context "with already had accepted posts" do
|
2021-11-12 10:00:48 -05:00
|
|
|
|
before do
|
|
|
|
|
accepted_post = create_post(user: user_tl1)
|
|
|
|
|
DiscourseSolved.accept_answer!(accepted_post, Discourse.system_user)
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
|
it "doesn’t validate the post" do
|
2021-11-12 10:00:48 -05:00
|
|
|
|
post_1 = create_post(user: user_tl1)
|
|
|
|
|
expect(described_class.check(post_1, trust_level: TrustLevel[2])).to eq(false)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
|
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
|
2021-11-12 10:00:48 -05:00
|
|
|
|
post_1 = create_post(user: user_tl1)
|
|
|
|
|
expect(described_class.check(post_1, trust_level: TrustLevel[1])).to eq(false)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
|
context "when a post is already accepted" do
|
2021-11-12 10:00:48 -05:00
|
|
|
|
before do
|
|
|
|
|
accepted_post = create_post(user: user_tl1)
|
|
|
|
|
DiscourseSolved.accept_answer!(accepted_post, Discourse.system_user)
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
|
it "doesn’t validate the post" do
|
2021-11-12 10:00:48 -05:00
|
|
|
|
post_1 = create_post(user: user_tl1)
|
|
|
|
|
expect(described_class.check(post_1, trust_level: TrustLevel[1])).to eq(false)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
|
context "when using any trust level" do
|
|
|
|
|
it "validates the post" do
|
2021-11-12 10:00:48 -05:00
|
|
|
|
post_1 = create_post(user: user_tl1)
|
2022-12-23 15:36:08 -05:00
|
|
|
|
expect(described_class.check(post_1, trust_level: "any")).to eq(true)
|
2021-11-12 10:00:48 -05:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
|
context "when user is system" do
|
|
|
|
|
it "doesn’t validate the post" do
|
2021-11-12 10:00:48 -05:00
|
|
|
|
post_1 = create_post(user: Discourse.system_user)
|
2022-12-23 15:36:08 -05:00
|
|
|
|
expect(described_class.check(post_1, trust_level: "any")).to eq(false)
|
2021-11-12 10:00:48 -05:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
|
context "when post is a PM" do
|
|
|
|
|
it "doesn’t validate the post" do
|
2022-10-04 00:19:45 -04:00
|
|
|
|
Group.refresh_automatic_groups!
|
2022-12-23 15:36:08 -05:00
|
|
|
|
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)
|
2021-11-12 10:00:48 -05:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|