Skip to content

Commit

Permalink
expand tests
Browse files Browse the repository at this point in the history
  • Loading branch information
merefield committed Apr 5, 2024
1 parent def25df commit 31c654c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions spec/lib/event_evaluation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require_relative '../plugin_helper'

CHATBOT_QUERIES_CUSTOM_FIELD = "chatbot_queries"
CHATBOT_QUERIES_QUOTA_REACH_ESCALATION_DATE_CUSTOM_FIELD = "chatbot_queries_quota_reach_escalation_date"

describe ::DiscourseChatbot::EventEvaluation do
let(:normal_user) { Fabricate(:user, trust_level: TrustLevel[1], refresh_auto_groups: true) }
Expand Down Expand Up @@ -54,7 +55,7 @@
expect(event.over_quota(high_trust_user.id)).to equal(false)
end

it "returns the correct quota decision if user is in high trust group and user is outside of quota" do
it "returns the correct quota decision if user is in high trust group and user is outside of quota and escalates" do
UserCustomField.create!(user_id: high_trust_user.id, name: CHATBOT_QUERIES_CUSTOM_FIELD, value: 3)
SiteSetting.chatbot_high_trust_groups = "13|14"
SiteSetting.chatbot_medium_trust_groups = "11|12"
Expand All @@ -64,7 +65,22 @@
SiteSetting.chatbot_quota_low_trust = 1

event = ::DiscourseChatbot::EventEvaluation.new
expect { event.over_quota(high_trust_user.id) }.to change { Topic.where(archetype: "private_message").count }.by(1)
expect { event.over_quota(high_trust_user.id) }.to change { Topic.where(archetype: Archetype.private_message).count }.by(1)
expect(event.over_quota(high_trust_user.id)).to equal(true)
end

it "returns the correct quota decision if user is in high trust group and user is outside of quota but doesn't escalate" do
UserCustomField.create!(user_id: high_trust_user.id, name: CHATBOT_QUERIES_CUSTOM_FIELD, value: 3)
UserCustomField.create!(user_id: high_trust_user.id, name: CHATBOT_QUERIES_QUOTA_REACH_ESCALATION_DATE_CUSTOM_FIELD, value: 30.minutes.ago)
SiteSetting.chatbot_high_trust_groups = "13|14"
SiteSetting.chatbot_medium_trust_groups = "11|12"
SiteSetting.chatbot_low_trust_groups = "10"
SiteSetting.chatbot_quota_high_trust = 3
SiteSetting.chatbot_quota_medium_trust = 2
SiteSetting.chatbot_quota_low_trust = 1

event = ::DiscourseChatbot::EventEvaluation.new
expect { event.over_quota(high_trust_user.id) }.to change { Topic.where(archetype: Archetype.private_message).count }.by(0)
expect(event.over_quota(high_trust_user.id)).to equal(true)
end

Expand Down

0 comments on commit 31c654c

Please sign in to comment.