mirror of
https://github.com/plausible/analytics.git
synced 2024-09-11 18:07:33 +03:00
Fix dry run mode in DataMigration.SiteImports
(#3965)
This commit is contained in:
parent
23a3699dd7
commit
9f27fa303c
@ -141,7 +141,9 @@ defmodule Plausible.DataMigration.SiteImports do
|
||||
|
||||
defp insert!(changeset, true = _dry_run?) do
|
||||
if changeset.valid? do
|
||||
Ecto.Changeset.apply_changes(changeset)
|
||||
changeset
|
||||
|> Ecto.Changeset.change(id: 0)
|
||||
|> Ecto.Changeset.apply_changes()
|
||||
else
|
||||
raise "Invalid insert: #{inspect(changeset)}"
|
||||
end
|
||||
|
@ -50,6 +50,24 @@ defmodule Plausible.DataMigration.SiteImportsTest do
|
||||
assert site_import.source == :universal_analytics
|
||||
end
|
||||
|
||||
test "runs in dry mode without making any persistent changes" do
|
||||
site =
|
||||
insert(:site)
|
||||
|> Site.start_import(~D[2021-01-02], ~D[2021-01-08], "Google Analytics", "ok")
|
||||
|> Repo.update!()
|
||||
|
||||
populate_stats(site, 0, [
|
||||
build(:imported_visitors, date: ~D[2021-01-07])
|
||||
])
|
||||
|
||||
assert capture_io(fn ->
|
||||
assert :ok = SiteImports.run()
|
||||
end) =~ "Processing 1 sites"
|
||||
|
||||
assert [%{id: id, legacy: true}] = Imported.list_all_imports(site)
|
||||
assert id == 0
|
||||
end
|
||||
|
||||
test "does not set end date to latter than the current one" do
|
||||
site =
|
||||
insert(:site)
|
||||
|
Loading…
Reference in New Issue
Block a user