discourse/plugins/automation/spec/triggers/user_first_logged_in_spec.rb

31 lines
851 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
describe DiscourseAutomation::Triggers::USER_FIRST_LOGGED_IN do
before { SiteSetting.discourse_automation_enabled = true }
fab!(:user)
let(:topic) { post.topic }
fab!(:automation) do
Fabricate(:automation, trigger: DiscourseAutomation::Triggers::USER_FIRST_LOGGED_IN)
end
context "when user logs in for first time" do
it "triggers the automation" do
contexts = capture_contexts { user.logged_in }
expect(contexts[0]["kind"]).to eq(DiscourseAutomation::Triggers::USER_FIRST_LOGGED_IN)
expect(contexts[0]["user"]).to eq(user)
end
end
context "when user logs in multiple times" do
it "doesnt trigger the automation" do
user.update_last_seen!(2.days.ago)
contexts = capture_contexts { user.logged_in }
expect(contexts).to eq([])
end
end
end