analytics/test/workers/clean_email_verification_codes_test.exs
Uku Taht 81c12884cd
Add elixir action (#526)
* Add elixir action

* Format the codebase

* Add postgresql

* Postgres config

* Run postgres on localhost

* Add clickhouse to CI
2020-12-29 15:17:27 +02:00

35 lines
1.1 KiB
Elixir

defmodule Plausible.Workers.CleanEmailVerificationCodesTest do
use Plausible.DataCase
alias Plausible.Workers.CleanEmailVerificationCodes
defp issue_code(user, issued_at) do
code =
Repo.one(
from(c in "email_verification_codes", where: is_nil(c.user_id), select: c.code, limit: 1)
)
Repo.update_all(from(c in "email_verification_codes", where: c.code == ^code),
set: [user_id: user.id, issued_at: issued_at]
)
end
test "cleans codes that are more than 4 hours old" do
user = insert(:user)
issue_code(user, Timex.now() |> Timex.shift(hours: -5))
issue_code(user, Timex.now() |> Timex.shift(days: -5))
CleanEmailVerificationCodes.perform(nil, nil)
refute Repo.exists?(from c in "email_verification_codes", where: c.user_id == ^user.id)
end
test "does not clean code from 2 hours ago" do
user = insert(:user)
issue_code(user, Timex.now() |> Timex.shift(hours: -2))
CleanEmailVerificationCodes.perform(nil, nil)
assert Repo.exists?(from c in "email_verification_codes", where: c.user_id == ^user.id)
end
end