Permette di scegliere 12 ore, 24 ore o la settimana nello storico invii.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -36,6 +36,30 @@ class MailingsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_match(/1 ultimi 15 min/, response.body)
|
||||
assert_select "div", text: "Storico invio"
|
||||
assert_match(/1 inviate · ultime 12 ore/, response.body)
|
||||
assert_select "span", text: "12h"
|
||||
assert_select "a", text: "24h"
|
||||
assert_select "a", text: "7g"
|
||||
end
|
||||
|
||||
test "dashboard history range can switch to the last week" do
|
||||
login_as users(:admin)
|
||||
follow_redirect! if response.redirect?
|
||||
|
||||
mailing = create_mailing(identity: @identity, audience: "to_send")
|
||||
org = organizations(:acme)
|
||||
mailing.mailing_recipients.create!(
|
||||
organization: org,
|
||||
contact: org.contacts.first,
|
||||
email: org.email,
|
||||
status: "sent",
|
||||
sent_at: 2.days.ago
|
||||
)
|
||||
|
||||
get dashboard_mailings_path(project_code: @project.code, history: "7d")
|
||||
assert_response :success
|
||||
assert_match(/1 inviate · ultima settimana/, response.body)
|
||||
assert_select "span", text: "7g"
|
||||
assert_select "a[href=?]", dashboard_mailings_path(project_code: @project.code, history: "24h")
|
||||
end
|
||||
|
||||
test "creates a draft and opens audience filters" do
|
||||
|
||||
@@ -55,7 +55,7 @@ class Mailings::HourlyThroughputTest < ActiveSupport::TestCase
|
||||
add_recipient status: "sent", sent_at: now - 13.hours, mailing: extra_mailing("Fuori finestra")
|
||||
|
||||
stats = Mailings::HourlyThroughput.new(@project, now: now)
|
||||
history = stats.hourly_history
|
||||
history = stats.history
|
||||
|
||||
assert_equal 12, history.size
|
||||
assert_equal now.beginning_of_hour, history.last[:at]
|
||||
@@ -66,6 +66,45 @@ class Mailings::HourlyThroughputTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
test "includes the previous day when the range is 24 hours" do
|
||||
now = Time.zone.parse("2026-09-07 12:40")
|
||||
travel_to now do
|
||||
add_recipient status: "sent", sent_at: now - 20.hours
|
||||
|
||||
twelve = Mailings::HourlyThroughput.new(@project, now: now, range: "12h")
|
||||
day = Mailings::HourlyThroughput.new(@project, now: now, range: "24h")
|
||||
|
||||
assert_equal 0, twelve.history_total
|
||||
assert_equal 24, day.history.size
|
||||
assert_equal 1, day.history_total
|
||||
end
|
||||
end
|
||||
|
||||
test "groups the last week by day" do
|
||||
now = Time.zone.parse("2026-09-07 12:40")
|
||||
travel_to now do
|
||||
add_recipient status: "sent", sent_at: now - 3.days
|
||||
add_recipient status: "sent", sent_at: now - 8.days, mailing: extra_mailing("Vecchia")
|
||||
|
||||
stats = Mailings::HourlyThroughput.new(@project, now: now, range: "7d")
|
||||
history = stats.history
|
||||
|
||||
assert_equal 7, history.size
|
||||
assert_equal now.beginning_of_day, history.last[:at]
|
||||
assert_equal 1, history[-4][:count]
|
||||
assert_equal 0, history.last[:count]
|
||||
assert_equal 1, stats.history_total
|
||||
assert_equal "7d", stats.range_key
|
||||
end
|
||||
end
|
||||
|
||||
test "falls back to 12 hours for an unknown range" do
|
||||
stats = Mailings::HourlyThroughput.new(@project, range: "nope")
|
||||
|
||||
assert_equal "12h", stats.range_key
|
||||
assert_equal 12, stats.history.size
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def extra_mailing(name = "Altra campagna")
|
||||
|
||||
Reference in New Issue
Block a user