2019-09-02 14:29:19 +03:00
|
|
|
defmodule Plausible.Factory do
|
|
|
|
use ExMachina.Ecto, repo: Plausible.Repo
|
2020-06-08 10:35:13 +03:00
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
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"),
|
2020-03-18 17:27:46 +03:00
|
|
|
password_hash: Plausible.Auth.Password.hash(pw),
|
2020-12-15 12:30:45 +03:00
|
|
|
trial_expiry_date: Timex.today() |> Timex.shift(days: 30),
|
|
|
|
email_verified: true
|
2019-09-02 14:29:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
merge_attributes(user, attrs)
|
|
|
|
end
|
|
|
|
|
2020-12-09 12:00:14 +03:00
|
|
|
def spike_notification_factory do
|
2020-12-09 16:59:41 +03:00
|
|
|
%Plausible.Site.SpikeNotification{
|
|
|
|
threshold: 10
|
|
|
|
}
|
2020-12-09 12:00:14 +03:00
|
|
|
end
|
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
def site_factory do
|
|
|
|
domain = sequence(:domain, &"example-#{&1}.com")
|
|
|
|
|
|
|
|
%Plausible.Site{
|
|
|
|
domain: domain,
|
2020-06-08 10:35:13 +03:00
|
|
|
timezone: "UTC"
|
2019-09-02 14:29:19 +03:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-06-16 15:00:07 +03:00
|
|
|
def site_membership_factory do
|
|
|
|
%Plausible.Site.Membership{}
|
|
|
|
end
|
|
|
|
|
2020-05-18 12:44:52 +03:00
|
|
|
def ch_session_factory do
|
|
|
|
hostname = sequence(:domain, &"example-#{&1}.com")
|
|
|
|
|
|
|
|
%Plausible.ClickhouseSession{
|
|
|
|
sign: 1,
|
2021-01-07 16:16:04 +03:00
|
|
|
session_id: SipHash.hash!(hash_key(), UUID.uuid4()),
|
|
|
|
user_id: SipHash.hash!(hash_key(), UUID.uuid4()),
|
2020-05-18 12:44:52 +03:00
|
|
|
hostname: hostname,
|
|
|
|
domain: hostname,
|
2020-09-17 16:36:01 +03:00
|
|
|
referrer: "",
|
|
|
|
referrer_source: "",
|
2020-09-18 11:37:32 +03:00
|
|
|
utm_medium: "",
|
|
|
|
utm_source: "",
|
|
|
|
utm_campaign: "",
|
2020-05-18 12:44:52 +03:00
|
|
|
entry_page: "/",
|
|
|
|
pageviews: 1,
|
|
|
|
events: 1,
|
|
|
|
duration: 0,
|
|
|
|
start: Timex.now(),
|
|
|
|
timestamp: Timex.now(),
|
2020-09-17 16:36:01 +03:00
|
|
|
is_bounce: false,
|
|
|
|
browser: "",
|
2020-11-10 16:18:59 +03:00
|
|
|
browser_version: "",
|
2020-09-17 16:36:01 +03:00
|
|
|
country_code: "",
|
|
|
|
screen_size: "",
|
2020-11-10 16:18:59 +03:00
|
|
|
operating_system: "",
|
|
|
|
operating_system_version: ""
|
2020-05-18 12:44:52 +03:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
def pageview_factory do
|
2019-10-25 09:06:11 +03:00
|
|
|
struct!(
|
|
|
|
event_factory(),
|
|
|
|
%{
|
|
|
|
name: "pageview"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def event_factory do
|
2019-09-02 14:29:19 +03:00
|
|
|
hostname = sequence(:domain, &"example-#{&1}.com")
|
|
|
|
|
2020-05-21 13:03:39 +03:00
|
|
|
%Plausible.ClickhouseEvent{
|
2019-09-02 14:29:19 +03:00
|
|
|
hostname: hostname,
|
2020-02-04 16:44:13 +03:00
|
|
|
domain: hostname,
|
2019-09-02 14:29:19 +03:00
|
|
|
pathname: "/",
|
2021-07-23 13:44:05 +03:00
|
|
|
timestamp: NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second),
|
2021-01-07 16:16:04 +03:00
|
|
|
user_id: SipHash.hash!(hash_key(), UUID.uuid4()),
|
|
|
|
session_id: SipHash.hash!(hash_key(), UUID.uuid4()),
|
2020-09-17 16:36:01 +03:00
|
|
|
referrer: "",
|
|
|
|
referrer_source: "",
|
2020-09-18 11:37:32 +03:00
|
|
|
utm_medium: "",
|
|
|
|
utm_source: "",
|
|
|
|
utm_campaign: "",
|
2020-09-17 16:36:01 +03:00
|
|
|
browser: "",
|
2020-11-10 16:18:59 +03:00
|
|
|
browser_version: "",
|
2020-09-17 16:36:01 +03:00
|
|
|
country_code: "",
|
|
|
|
screen_size: "",
|
2020-10-28 12:09:04 +03:00
|
|
|
operating_system: "",
|
2020-11-10 16:18:59 +03:00
|
|
|
operating_system_version: "",
|
2020-10-28 12:09:04 +03:00
|
|
|
"meta.key": [],
|
|
|
|
"meta.value": []
|
2019-09-02 14:29:19 +03:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-10-31 09:14:06 +03:00
|
|
|
def goal_factory do
|
|
|
|
%Plausible.Goal{}
|
|
|
|
end
|
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
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",
|
2021-05-13 12:42:01 +03:00
|
|
|
next_bill_date: Timex.today(),
|
2021-10-29 12:51:02 +03:00
|
|
|
last_bill_date: Timex.today(),
|
2021-05-13 12:42:01 +03:00
|
|
|
currency_code: "USD"
|
2019-09-02 14:29:19 +03:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-10-20 17:49:11 +03:00
|
|
|
def enterprise_plan_factory do
|
|
|
|
%Plausible.Billing.EnterprisePlan{
|
|
|
|
paddle_plan_id: sequence(:paddle_plan_id, &"plan-#{&1}"),
|
|
|
|
billing_interval: :monthly,
|
|
|
|
monthly_pageview_limit: 1_000_000,
|
2021-10-22 12:26:07 +03:00
|
|
|
hourly_api_request_limit: 3000,
|
|
|
|
site_limit: 100
|
2021-10-20 17:49:11 +03:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
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
|
2020-01-16 16:13:03 +03:00
|
|
|
|
2020-02-26 11:54:21 +03:00
|
|
|
def custom_domain_factory do
|
|
|
|
%Plausible.Site.CustomDomain{
|
|
|
|
domain: sequence(:custom_domain, &"domain-#{&1}.com")
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-01-22 12:16:53 +03:00
|
|
|
def weekly_report_factory do
|
|
|
|
%Plausible.Site.WeeklyReport{}
|
|
|
|
end
|
|
|
|
|
|
|
|
def monthly_report_factory do
|
|
|
|
%Plausible.Site.MonthlyReport{}
|
|
|
|
end
|
2020-01-29 12:29:11 +03:00
|
|
|
|
|
|
|
def shared_link_factory do
|
|
|
|
%Plausible.Site.SharedLink{
|
2021-04-06 14:32:38 +03:00
|
|
|
name: "Link name",
|
2020-01-29 12:29:11 +03:00
|
|
|
slug: Nanoid.generate()
|
|
|
|
}
|
|
|
|
end
|
2021-01-07 16:16:04 +03:00
|
|
|
|
2021-06-16 15:00:07 +03:00
|
|
|
def invitation_factory do
|
|
|
|
%Plausible.Auth.Invitation{
|
|
|
|
invitation_id: Nanoid.generate(),
|
|
|
|
email: sequence(:email, &"email-#{&1}@example.com"),
|
|
|
|
role: :admin
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-02-05 12:23:30 +03:00
|
|
|
def api_key_factory do
|
|
|
|
key = :crypto.strong_rand_bytes(64) |> Base.url_encode64() |> binary_part(0, 64)
|
|
|
|
|
|
|
|
%Plausible.Auth.ApiKey{
|
|
|
|
name: "api-key-name",
|
|
|
|
key: key,
|
|
|
|
key_hash: Plausible.Auth.ApiKey.do_hash(key),
|
|
|
|
key_prefix: binary_part(key, 0, 6)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-01-07 16:16:04 +03:00
|
|
|
defp hash_key() do
|
|
|
|
Keyword.fetch!(
|
|
|
|
Application.get_env(:plausible, PlausibleWeb.Endpoint),
|
|
|
|
:secret_key_base
|
|
|
|
)
|
|
|
|
|> binary_part(0, 16)
|
|
|
|
end
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|