mirror of
https://github.com/plausible/analytics.git
synced 2024-11-26 23:27:54 +03:00
1d01328287
* Migration (PR: https://github.com/plausible/analytics/pull/2802) * Implement Site.Domain interface allowing change and expiry * Fixup seeds so they work with V2_MIGRATION_DONE=1 * Update Sites.Cache so it's capable of multi-keyed lookups * Implement worker handling domain change expiration * Implement domain change UI * Implement transition period for public APIs * Exclude v2 tests in primary test run * Update lib/plausible_web/controllers/site_controller.ex Co-authored-by: Vini Brasil <vini@hey.com> * Update lib/plausible_web/controllers/site_controller.ex Co-authored-by: Vini Brasil <vini@hey.com> * Update moduledoc * Update changelog * Remove remnant from previous implementation attempt * !fixup * !fixup * Implement domain change via Sites API cc @ukutaht * Update CHANGELOG * Credo * !fixup commit missing tests * Allow continuous domain change within the same site --------- Co-authored-by: Vini Brasil <vini@hey.com>
44 lines
1.5 KiB
Elixir
44 lines
1.5 KiB
Elixir
defmodule Plausible.Workers.ExpireDomainChangeTransitionsTest do
|
|
use Plausible.DataCase, async: true
|
|
alias Plausible.Workers.ExpireDomainChangeTransitions
|
|
alias Plausible.Site
|
|
alias Plausible.Sites
|
|
|
|
import ExUnit.CaptureLog
|
|
|
|
@moduletag :v2_only
|
|
|
|
test "doesn't log when there is nothing to do" do
|
|
log =
|
|
capture_log(fn ->
|
|
assert :ok = ExpireDomainChangeTransitions.perform(nil)
|
|
end)
|
|
|
|
assert log == ""
|
|
end
|
|
|
|
test "expires domains selectively after change and logs the result" do
|
|
now = NaiveDateTime.utc_now()
|
|
yesterday = now |> NaiveDateTime.add(-60 * 60 * 24, :second)
|
|
three_days_ago = now |> NaiveDateTime.add(-60 * 60 * 72, :second)
|
|
long_time_ago = now |> NaiveDateTime.add(-60 * 60 * 24 * 365, :second)
|
|
|
|
insert(:site) |> Site.Domain.change("site1.example.com")
|
|
insert(:site) |> Site.Domain.change("site2.example.com", at: yesterday)
|
|
insert(:site) |> Site.Domain.change("site3.example.com", at: three_days_ago)
|
|
insert(:site) |> Site.Domain.change("site4.example.com", at: long_time_ago)
|
|
|
|
log =
|
|
capture_log(fn ->
|
|
assert :ok = ExpireDomainChangeTransitions.perform(nil)
|
|
end)
|
|
|
|
assert log =~ "Expired 2 from the domain change transition period"
|
|
|
|
assert Sites.get_by_domain("site1.example.com").domain_changed_from
|
|
assert Sites.get_by_domain("site2.example.com").domain_changed_from
|
|
refute Sites.get_by_domain("site3.example.com").domain_changed_from
|
|
refute Sites.get_by_domain("site4.example.com").domain_changed_from
|
|
end
|
|
end
|