mirror of
https://github.com/plausible/analytics.git
synced 2024-12-25 02:24:55 +03:00
ae42b86792
* Checks - added Dialyzer - fixed Dialyzer errors - added Dialyzer check to GitHub Actions with cache - added Credo - fixed Credo Warnings - added Credo Warnings check to GitHub Actions with cache - added compile warnings check to GitHub Actions - reformated GitHub Actions YAML * Dialyzer - allow it in test env * Dialyzer - fixed test env - renamed GitHub actions steps * AppSignal - upgraded deprecated version - Upgraded: appsignal 2.0.5 => 2.0.7 certifi 2.5.2 => 2.5.3 hackney 1.16.0 => 1.17.0 idna 6.0.1 => 6.1.1 parse_trans 3.3.0 => 3.3.1 unicode_util_compat 0.5.0 => 0.7.0 (minor) * Credo - fixed CRM plug
83 lines
2.8 KiB
Elixir
83 lines
2.8 KiB
Elixir
defmodule Plausible.Workers.ScheduleEmailReportsTest do
|
|
use Plausible.DataCase
|
|
use Oban.Testing, repo: Plausible.Repo
|
|
alias Plausible.Workers.{ScheduleEmailReports, SendEmailReport}
|
|
|
|
defp perform(args) do
|
|
ScheduleEmailReports.new(args) |> Oban.insert!()
|
|
Oban.drain_queue(:schedule_email_reports)
|
|
end
|
|
|
|
describe "weekly reports" do
|
|
test "schedules weekly report on Monday 9am local timezone" do
|
|
site = insert(:site, domain: "test-site.com", timezone: "US/Eastern")
|
|
insert(:weekly_report, site: site, recipients: ["user@email.com"])
|
|
|
|
perform(%{})
|
|
|
|
assert_enqueued(
|
|
worker: SendEmailReport,
|
|
args: %{site_id: site.id, interval: "weekly"},
|
|
scheduled_at: ScheduleEmailReports.monday_9am(site.timezone)
|
|
)
|
|
end
|
|
|
|
test "does not schedule more than one weekly report at a time" do
|
|
site = insert(:site, domain: "test-site.com", timezone: "US/Eastern")
|
|
insert(:weekly_report, site: site, recipients: ["user@email.com"])
|
|
|
|
perform(%{})
|
|
perform(%{})
|
|
|
|
assert Enum.count(all_enqueued(worker: SendEmailReport)) == 1
|
|
end
|
|
|
|
test "schedules a new report as soon as a previous one is completed" do
|
|
site = insert(:site, domain: "test-site.com", timezone: "US/Eastern")
|
|
insert(:weekly_report, site: site, recipients: ["user@email.com"])
|
|
|
|
perform(%{})
|
|
Repo.update_all("oban_jobs", set: [state: "completed"])
|
|
assert Enum.empty?(all_enqueued(worker: SendEmailReport))
|
|
perform(%{})
|
|
assert Enum.count(all_enqueued(worker: SendEmailReport)) == 1
|
|
end
|
|
end
|
|
|
|
describe "monthly_reports" do
|
|
test "schedules monthly report on first of the next month at 9am local timezone" do
|
|
site = insert(:site, domain: "test-site.com", timezone: "US/Eastern")
|
|
insert(:monthly_report, site: site, recipients: ["user@email.com"])
|
|
|
|
perform(%{})
|
|
|
|
assert_enqueued(
|
|
worker: SendEmailReport,
|
|
args: %{site_id: site.id, interval: "monthly"},
|
|
scheduled_at: ScheduleEmailReports.first_of_month_9am(site.timezone)
|
|
)
|
|
end
|
|
|
|
test "does not schedule more than one monthly report at a time" do
|
|
site = insert(:site, domain: "test-site.com", timezone: "US/Eastern")
|
|
insert(:monthly_report, site: site, recipients: ["user@email.com"])
|
|
|
|
perform(%{})
|
|
perform(%{})
|
|
|
|
assert Enum.count(all_enqueued(worker: SendEmailReport)) == 1
|
|
end
|
|
|
|
test "schedules a new report as soon as a previous one is completed" do
|
|
site = insert(:site, domain: "test-site.com", timezone: "US/Eastern")
|
|
insert(:monthly_report, site: site, recipients: ["user@email.com"])
|
|
|
|
perform(%{})
|
|
Repo.update_all("oban_jobs", set: [state: "completed"])
|
|
assert Enum.empty?(all_enqueued(worker: SendEmailReport))
|
|
perform(%{})
|
|
assert Enum.count(all_enqueued(worker: SendEmailReport)) == 1
|
|
end
|
|
end
|
|
end
|