2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe "Discobot welcome post" do
|
2017-06-01 16:20:16 +08:00
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
before { SiteSetting.discourse_narrative_bot_enabled = true }
|
|
|
|
|
|
|
|
context "when discourse_narrative_bot_welcome_post_delay is 0" do
|
|
|
|
it "should not delay the welcome post" do
|
|
|
|
user
|
|
|
|
expect { sign_in(user) }.to_not change { Jobs::NarrativeInit.jobs.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
context "when discourse_narrative_bot_welcome_post_delay is greater than 0" do
|
2017-06-01 16:20:16 +08:00
|
|
|
before { SiteSetting.discourse_narrative_bot_welcome_post_delay = 5 }
|
|
|
|
|
|
|
|
context "when user logs in normally" do
|
|
|
|
it "should delay the welcome post until user logs in" do
|
|
|
|
expect { sign_in(user) }.to change { Jobs::NarrativeInit.jobs.count }.by(1)
|
|
|
|
expect(Jobs::NarrativeInit.jobs.first["args"].first["user_id"]).to eq(user.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when user redeems an invite" do
|
2021-04-14 17:15:56 +08:00
|
|
|
let!(:invite) do
|
|
|
|
Fabricate(:invite, invited_by: Fabricate(:admin), email: "testing@gmail.com")
|
2023-01-07 04:42:16 +08:00
|
|
|
end
|
2017-06-01 16:20:16 +08:00
|
|
|
|
|
|
|
it "should delay the welcome post until the user logs in" do
|
|
|
|
expect do
|
2017-08-31 12:06:56 +08:00
|
|
|
put "/invites/show/#{invite.invite_key}.json",
|
|
|
|
params: {
|
2017-06-01 16:20:16 +08:00
|
|
|
username: "somename",
|
|
|
|
name: "testing",
|
2021-04-14 17:15:56 +08:00
|
|
|
password: "verystrongpassword",
|
|
|
|
email_token: invite.email_token,
|
2017-08-31 12:06:56 +08:00
|
|
|
}
|
2017-06-01 16:20:16 +08:00
|
|
|
end.to change { User.count }.by(1)
|
|
|
|
|
|
|
|
expect(Jobs::NarrativeInit.jobs.first["args"].first["user_id"]).to eq(User.last.id)
|
|
|
|
end
|
|
|
|
end
|
2019-01-31 07:03:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when user is staged" do
|
|
|
|
let(:staged_user) { Fabricate(:user, staged: true) }
|
|
|
|
|
|
|
|
before { SiteSetting.discourse_narrative_bot_welcome_post_type = "welcome_message" }
|
2017-06-01 16:20:16 +08:00
|
|
|
|
2019-01-31 07:03:16 +08:00
|
|
|
it "should not send welcome message" do
|
|
|
|
expect { staged_user }.to_not change { Jobs::SendDefaultWelcomeMessage.jobs.count }
|
|
|
|
end
|
2017-06-01 16:20:16 +08:00
|
|
|
end
|
|
|
|
end
|