Fix up Purge tests (#2364)

This commit is contained in:
Adam Rutkowski 2022-10-24 12:15:18 +02:00 committed by GitHub
parent e48851a9ed
commit 3ddfda94a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,16 +5,16 @@ defmodule Plausible.PurgeTest do
site = insert(:site, stats_start_date: ~D[2020-01-01])
populate_stats(site, [
build(:pageview, domain: site.domain),
build(:imported_visitors, site_id: site.id),
build(:imported_sources, site_id: site.id),
build(:imported_pages, site_id: site.id),
build(:imported_entry_pages, site_id: site.id),
build(:imported_exit_pages, site_id: site.id),
build(:imported_locations, site_id: site.id),
build(:imported_devices, site_id: site.id),
build(:imported_browsers, site_id: site.id),
build(:imported_operating_systems, site_id: site.id)
build(:pageview),
build(:imported_visitors),
build(:imported_sources),
build(:imported_pages),
build(:imported_entry_pages),
build(:imported_exit_pages),
build(:imported_locations),
build(:imported_devices),
build(:imported_browsers),
build(:imported_operating_systems)
])
{:ok, %{site: site}}
@ -32,6 +32,11 @@ defmodule Plausible.PurgeTest do
end
test "delete_imported_stats!/1 deletes imported data", %{site: site} do
Enum.each(Plausible.Imported.tables(), fn table ->
query = from(imported in table, where: imported.site_id == ^site.id)
assert_count(query, 1)
end)
assert :ok == Plausible.Purge.delete_imported_stats!(site)
Enum.each(Plausible.Imported.tables(), fn table ->
@ -46,12 +51,15 @@ defmodule Plausible.PurgeTest do
end
test "delete_native_stats!/1 deletes native stats", %{site: site} do
assert :ok == Plausible.Purge.delete_native_stats!(site)
events_query = from(s in Plausible.ClickhouseSession, where: s.domain == ^site.domain)
assert_count(events_query, 0)
events_query = from(s in Plausible.ClickhouseEvent, where: s.domain == ^site.domain)
assert_count(events_query, 1)
sessions_query = from(s in Plausible.ClickhouseSession, where: s.domain == ^site.domain)
assert_count(sessions_query, 1)
assert :ok == Plausible.Purge.delete_native_stats!(site)
assert_count(events_query, 0)
assert_count(sessions_query, 0)
end
@ -61,13 +69,16 @@ defmodule Plausible.PurgeTest do
end
test "delete_site!/1 deletes the site and all stats", %{site: site} do
events_query = from(s in Plausible.ClickhouseEvent, where: s.domain == ^site.domain)
assert_count(events_query, 1)
sessions_query = from(s in Plausible.ClickhouseSession, where: s.domain == ^site.domain)
assert_count(sessions_query, 1)
assert :ok == Plausible.Purge.delete_site!(site)
assert nil == Plausible.Repo.reload(site)
events_query = from(s in Plausible.ClickhouseSession, where: s.domain == ^site.domain)
assert_count(events_query, 0)
sessions_query = from(s in Plausible.ClickhouseSession, where: s.domain == ^site.domain)
assert_count(sessions_query, 0)
Enum.each(Plausible.Imported.tables(), fn table ->