* Adjust digest rate if recent clicks tracked * Fix issues * Fix issues * Fix issues * Fiddle with tests * Fix syntax * Fiddle with tests * Fiddle with tests * Fiddle with tests * Fiddle with tests * Fiddle with tests * Fiddle with tests * Fiddle with tests * Remove .env.test symlink (#20839) * Update the mdx vscode extension (#20840) * Update @cypress/code-coverage to version 3.12.30 (#20803) Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> Co-authored-by: Mac Siri <mac@forem.com> * Update ruby VSCode extensions for debugging (#20816) The 'rebornix.Ruby' extension is deprecated. I replaced with the 'Shopify.ruby-lsp' extension since VSCode's Ruby docs pointed users to ruby-lsp, see https://code.visualstudio.com/docs/languages/ruby. * Update esbuild to version 0.19.12 (#20841) Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> * Update eslint to version 8.57.0 (#20853) Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> * fix: remove listings option from views/dashboards/_actions_mobile.html.erb (#20849) Co-authored-by: Mac Siri <mac@forem.com> * Update eslint-import-resolver-webpack to version 0.13.8 (#20854) Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> * add timestamp to users roles table (#20844) * Update eslint-plugin-import to version 2.29.1 (#20855) Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> * Adjust tests to account for clicks * Adjust tests to account for clicks --------- Co-authored-by: Mac Siri <mac@forem.com> Co-authored-by: Meredith <meredith.edwards1771@gmail.com> Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> Co-authored-by: Gabriel Quaresma <j.quaresmasantos_98@hotmail.com> Co-authored-by: Philip How <philip.j.how@gmail.com>
144 lines
5.5 KiB
Ruby
144 lines
5.5 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe EmailDigestArticleCollector, type: :service do
|
|
let(:user) { create(:user) }
|
|
|
|
describe "#articles_to_send" do
|
|
context "when user is brand new with no-follow" do
|
|
it "provides top 3 articles" do
|
|
create_list(:article, 3, public_reactions_count: 40, featured: true, score: 40)
|
|
articles = described_class.new(user).articles_to_send
|
|
expect(articles.length).to eq(3)
|
|
end
|
|
|
|
it "marks as not ready if there isn't atleast 3 articles" do
|
|
create_list(:article, 2, public_reactions_count: 40, score: 40)
|
|
articles = described_class.new(user).articles_to_send
|
|
expect(articles).to be_empty
|
|
end
|
|
|
|
it "marks as not ready if there isn't at least 3 email-digest-eligible articles" do
|
|
create_list(:article, 2, public_reactions_count: 40, score: 40)
|
|
create_list(:article, 2, public_reactions_count: 40, email_digest_eligible: false)
|
|
articles = described_class.new(user).articles_to_send
|
|
expect(articles).to be_empty
|
|
end
|
|
end
|
|
|
|
context "when it's been less than the set number of digest email days" do
|
|
before do
|
|
author = create(:user)
|
|
user.follow(author)
|
|
user.update(following_users_count: 1)
|
|
create_list(:article, 3, user_id: author.id, public_reactions_count: 20, score: 20)
|
|
Ahoy::Message.create(mailer: "DigestMailer#digest_email",
|
|
user_id: user.id, sent_at: Time.current.utc)
|
|
end
|
|
|
|
it "will return no articles when user shouldn't receive any" do
|
|
Timecop.freeze(Settings::General.periodic_email_digest.days.from_now - 1) do
|
|
articles = described_class.new(user).articles_to_send
|
|
expect(articles).to be_empty
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when it's been more than the set number of digest email days" do
|
|
before do
|
|
Ahoy::Message.create(mailer: "DigestMailer#digest_email", user_id: user.id,
|
|
sent_at: Time.current.utc)
|
|
author = create(:user)
|
|
user.follow(author)
|
|
user.update(following_users_count: 1)
|
|
create_list(:article, 3, user_id: author.id, public_reactions_count: 40, score: 40)
|
|
end
|
|
|
|
it "evaluates that user is ready to receive an email" do
|
|
Timecop.freeze((Settings::General.periodic_email_digest + 1).days.from_now) do
|
|
articles = described_class.new(user).articles_to_send
|
|
expect(articles).not_to be_empty
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when using tags" do
|
|
it "takes 'antifollowed' tags into account", :aggregate_failures do
|
|
articles = create_list(:article, 3, public_reactions_count: 40, score: 40)
|
|
tag = articles.first.tags.first
|
|
user.follow(tag)
|
|
|
|
digest1 = described_class.new(user).articles_to_send
|
|
expect(digest1.size).to eq 3
|
|
|
|
tag_follow = user.follows.first
|
|
tag_follow.update(explicit_points: -999)
|
|
|
|
digest2 = described_class.new(user).articles_to_send
|
|
expect(digest2.size).to eq 0
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "#should_receive_email?" do
|
|
let(:user) { create(:user) }
|
|
let(:collector) { described_class.new(user) }
|
|
|
|
before do
|
|
Settings::General.periodic_email_digest = 3
|
|
end
|
|
|
|
context "when the user clicked the last email within the lookback period" do
|
|
it "returns true" do
|
|
Ahoy::Message.create(mailer: "DigestMailer#digest_email",
|
|
user_id: user.id, sent_at: 2.days.ago, clicked_at: 1.day.ago)
|
|
expect(collector.should_receive_email?).to be true
|
|
end
|
|
end
|
|
|
|
context "when the user has not received any emails" do
|
|
it "returns true" do
|
|
expect(collector.should_receive_email?).to be true
|
|
end
|
|
end
|
|
|
|
context "when the last email was received outside the periodic email digest days" do
|
|
it "returns true" do
|
|
Ahoy::Message.create(mailer: "DigestMailer#digest_email",
|
|
user_id: user.id, sent_at: 4.days.ago)
|
|
expect(collector.should_receive_email?).to be true
|
|
end
|
|
end
|
|
|
|
context "when the last email was received within the periodic email digest days without click" do
|
|
it "returns false" do
|
|
Ahoy::Message.create(mailer: "DigestMailer#digest_email",
|
|
user_id: user.id, sent_at: 2.days.ago)
|
|
expect(collector.should_receive_email?).to be false
|
|
end
|
|
end
|
|
|
|
context "when the last email was received just before the periodic email digest days limit" do
|
|
it "returns true" do
|
|
Ahoy::Message.create(mailer: "DigestMailer#digest_email",
|
|
user_id: user.id, sent_at: 3.days.ago)
|
|
expect(collector.should_receive_email?).to be true
|
|
end
|
|
end
|
|
|
|
context "when the last email was clicked but outside the lookback period" do
|
|
it "returns true" do
|
|
Ahoy::Message.create(mailer: "DigestMailer#digest_email",
|
|
user_id: user.id, sent_at: 33.days.ago, clicked_at: 32.days.ago)
|
|
expect(collector.should_receive_email?).to be true
|
|
end
|
|
|
|
it "returns false when there is a sent at within the thredhold" do
|
|
Ahoy::Message.create(mailer: "DigestMailer#digest_email",
|
|
user_id: user.id, sent_at: 33.days.ago, clicked_at: 32.days.ago)
|
|
Ahoy::Message.create(mailer: "DigestMailer#digest_email",
|
|
user_id: user.id, sent_at: 2.days.ago)
|
|
expect(collector.should_receive_email?).to be false
|
|
end
|
|
end
|
|
end
|
|
end
|