Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unspecifieds #7180

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/admin/mailshots_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def show
@send_count = User::Mailshot.where(mailshot: @mailshot).count
@audiences = %w[
admins donors insiders challenge#12in23 challenge#48in24
bc_interested bc_beginners bc_juniors bc_mid_seniors bc_unspecified
bc_interested bc_beginners bc_juniors bc_mid_seniors
bc_unspecified_recent_90
]
@audiences += (1..10).map { |min| "bc_unspecified##{min}" }
@audiences += [100, 10, 3, 2, 1].map { |min| "reputation##{min}" }
@audiences += [10, 30, 60, 90].map { |min| "recent##{min}" }
@audiences += Track.pluck(:slug).map { |slug| "track##{slug}" }
Expand Down
20 changes: 18 additions & 2 deletions app/models/mailshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ def audience_for_bc_mid_seniors(_)
]
end

def audience_for_bc_unspecified(_)
def audience_for_bc_unspecified_recent_90(_)
[
User::Data.where(seniority: nil).includes(user: :bootcamp_data),
User::Data.where(seniority: nil).
where('user_data.last_visited_on >= ?', Time.current - 90.days).
includes(user: :bootcamp_data),
lambda do |user_data|
user = user_data.user
return if user.bootcamp_data&.paid?
Expand All @@ -120,4 +122,18 @@ def audience_for_bc_unspecified(_)
end
]
end

def audience_for_bc_unspecified(batch)
start_id = (batch.to_i - 1) * 200_000
end_id = (batch.to_i * 200_000) - 1
[
User.where(id: (start_id..end_id)).includes(:data, :bootcamp_data),
lambda do |user|
return if user.seniority.present?
return if user.bootcamp_data&.paid?

user
end
]
end
end
24 changes: 21 additions & 3 deletions test/commands/mailshot/send_to_audience_segment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ class Mailshot::SendToAudienceSegmentTest < ActiveSupport::TestCase
junior = create :user, seniority: :junior
mid = create :user, seniority: :mid
senior = create :user, seniority: :senior
unspecified = create :user, seniority: nil

# Now some users that have viewed the page
absolute_beginner_viewed = create :user, seniority: :absolute_beginner
Expand All @@ -181,6 +180,10 @@ class Mailshot::SendToAudienceSegmentTest < ActiveSupport::TestCase
create :user_bootcamp_data, user:, paid_at: Time.current
end

# Finally some unspecified users with specific ids for batches
unspecified_id_199_999 = create :user, seniority: nil, id: 199_999
unspecified_id_200_000 = create :user, seniority: nil, id: 200_000

# Let's start with a mailshot to interested people
mailshot = create :mailshot
User::Mailshot::Send.expects(:call).with(absolute_beginner_viewed, mailshot)
Expand Down Expand Up @@ -210,8 +213,23 @@ class Mailshot::SendToAudienceSegmentTest < ActiveSupport::TestCase

# And now to unspecifieds
mailshot = create :mailshot
User::Mailshot::Send.expects(:call).with(unspecified, mailshot)
Mailshot::SendToAudienceSegment.(mailshot, :bc_unspecified, nil, 20, 0)
User::Mailshot::Send.expects(:call).with(unspecified_id_199_999, mailshot)
Mailshot::SendToAudienceSegment.(mailshot, :bc_unspecified, 1, 20, 0)

User::Mailshot::Send.expects(:call).with(unspecified_id_200_000, mailshot)
Mailshot::SendToAudienceSegment.(mailshot, :bc_unspecified, 2, 20, 0)
end

test "schedules bc unspecified audience for recently active" do
mailshot = create :mailshot

user = create :user, last_visited_on: 89.days.ago, seniority: nil
create :user, last_visited_on: 91.days.ago, seniority: nil
create :user, last_visited_on: 89.days.ago, seniority: :mid

User::Mailshot::Send.expects(:call).with(user, mailshot)

Mailshot::SendToAudienceSegment.(mailshot, :bc_unspecified_recent_90, nil, 10, 0)
end

test "requeues with deserialization error" do
Expand Down
Loading