mirror of
https://github.com/plausible/analytics.git
synced 2024-11-29 14:04:12 +03:00
d94a8dbc7e
* Get stats from clickhosue * Pull stats from clickhouse * Use correct Query namespace * Use Clickhouse in unit tests * Use Clickhouse in stats controller tests * Use fixtures for unit tests * Add Clickhouse to travis * Use Clickhouse session store for sessions * Add garbage collection to session store * Reload session state from Clickhouse on server restart * Query from sessions table * Trap exits in event write buffer * Run hydration without starting the whole app * Make session length 30 minutes * Revert changes to fingerprint schema * Remove clickhouse from fingerprint sessions * Flush buffers before shutdown * Use old stats when merging * Remove old session schema * Fix tests with CH sessions * Add has_pageviews? to Stats * Use CH in staging * Update schema * Fix test setup
136 lines
3.1 KiB
Elixir
136 lines
3.1 KiB
Elixir
defmodule Plausible.Factory do
|
|
use ExMachina.Ecto, repo: Plausible.Repo
|
|
@hash_key Keyword.fetch!(Application.get_env(:plausible, PlausibleWeb.Endpoint), :secret_key_base) |> binary_part(0, 16)
|
|
|
|
def user_factory(attrs) do
|
|
pw = Map.get(attrs, :password, "password")
|
|
|
|
user = %Plausible.Auth.User{
|
|
name: "Jane Smith",
|
|
email: sequence(:email, &"email-#{&1}@example.com"),
|
|
password_hash: Plausible.Auth.Password.hash(pw),
|
|
trial_expiry_date: Timex.today() |> Timex.shift(days: 30)
|
|
}
|
|
|
|
merge_attributes(user, attrs)
|
|
end
|
|
|
|
def site_factory do
|
|
domain = sequence(:domain, &"example-#{&1}.com")
|
|
|
|
%Plausible.Site{
|
|
domain: domain,
|
|
timezone: "UTC",
|
|
}
|
|
end
|
|
|
|
def ch_session_factory do
|
|
hostname = sequence(:domain, &"example-#{&1}.com")
|
|
|
|
%Plausible.ClickhouseSession{
|
|
sign: 1,
|
|
session_id: UUID.uuid4(),
|
|
hostname: hostname,
|
|
domain: hostname,
|
|
entry_page: "/",
|
|
pageviews: 1,
|
|
events: 1,
|
|
duration: 0,
|
|
user_id: UUID.uuid4(),
|
|
start: Timex.now(),
|
|
timestamp: Timex.now(),
|
|
is_bounce: false
|
|
}
|
|
end
|
|
|
|
def session_factory do
|
|
hostname = sequence(:domain, &"example-#{&1}.com")
|
|
|
|
%Plausible.FingerprintSession{
|
|
hostname: hostname,
|
|
domain: hostname,
|
|
entry_page: "/",
|
|
fingerprint: UUID.uuid4(),
|
|
start: Timex.now(),
|
|
is_bounce: false
|
|
}
|
|
end
|
|
|
|
def pageview_factory do
|
|
struct!(
|
|
event_factory(),
|
|
%{
|
|
name: "pageview"
|
|
}
|
|
)
|
|
end
|
|
|
|
def event_factory do
|
|
hostname = sequence(:domain, &"example-#{&1}.com")
|
|
|
|
%Plausible.ClickhouseEvent{
|
|
hostname: hostname,
|
|
domain: hostname,
|
|
pathname: "/",
|
|
timestamp: Timex.now(),
|
|
user_id: SipHash.hash!(@hash_key, UUID.uuid4())
|
|
}
|
|
end
|
|
|
|
def goal_factory do
|
|
%Plausible.Goal{}
|
|
end
|
|
|
|
def subscription_factory do
|
|
%Plausible.Billing.Subscription{
|
|
paddle_subscription_id: sequence(:paddle_subscription_id, &"subscription-#{&1}"),
|
|
paddle_plan_id: sequence(:paddle_plan_id, &"plan-#{&1}"),
|
|
cancel_url: "cancel.com",
|
|
update_url: "cancel.com",
|
|
status: "active",
|
|
next_bill_amount: "6.00",
|
|
next_bill_date: Timex.today()
|
|
}
|
|
end
|
|
|
|
def google_auth_factory do
|
|
%Plausible.Site.GoogleAuth{
|
|
email: sequence(:google_auth_email, &"email-#{&1}@email.com"),
|
|
refresh_token: "123",
|
|
access_token: "123",
|
|
expires: Timex.now() |> Timex.shift(days: 1)
|
|
}
|
|
end
|
|
|
|
def custom_domain_factory do
|
|
%Plausible.Site.CustomDomain{
|
|
domain: sequence(:custom_domain, &"domain-#{&1}.com")
|
|
}
|
|
end
|
|
|
|
def tweet_factory do
|
|
%Plausible.Twitter.Tweet{
|
|
tweet_id: UUID.uuid4(),
|
|
author_handle: "author-handle",
|
|
author_name: "author-name",
|
|
author_image: "pic.twitter.com/author.png",
|
|
text: "tweet-text",
|
|
created: Timex.now()
|
|
}
|
|
end
|
|
|
|
def weekly_report_factory do
|
|
%Plausible.Site.WeeklyReport{}
|
|
end
|
|
|
|
def monthly_report_factory do
|
|
%Plausible.Site.MonthlyReport{}
|
|
end
|
|
|
|
def shared_link_factory do
|
|
%Plausible.Site.SharedLink{
|
|
slug: Nanoid.generate()
|
|
}
|
|
end
|
|
end
|