-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backfill onboarding status and ensure set on user create (#624)
We currently default this to nil, when we should be setting the status to :new by default
- Loading branch information
1 parent
cad1f71
commit 3509335
Showing
6 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule Core.Backfill.Users do | ||
alias Core.{Schema.User} | ||
|
||
def onboarding() do | ||
User | ||
|> User.ordered(asc: :id) | ||
|> Core.Repo.stream(method: :keyset) | ||
|> Core.throttle() | ||
|> Enum.each(fn user -> | ||
# don't show onboarding to existing users | ||
{:ok, _} = User.changeset(user, %{onboarding_checklist: %{dismissed: true, status: :finished}}) | ||
|> Core.Repo.update() | ||
end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Botanist | ||
|
||
seed do | ||
Core.Backfill.Users.onboarding() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule Core.Backfill.UsersTest do | ||
use Core.SchemaCase, async: true | ||
alias Core.Backfill.Users | ||
|
||
describe "#onboarding/0" do | ||
test "it will set onboarding_checklist structs" do | ||
users = insert_list(3, :user) | ||
|
||
Users.onboarding() | ||
|
||
for user <- users do | ||
assert refetch(user).onboarding_checklist.dismissed | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ defmodule Core.Services.UsersTest do | |
assert user.name == "some user" | ||
assert user.email == "[email protected]" | ||
assert user.password_hash | ||
assert user.onboarding_checklist.status == :new | ||
assert Timex.after?(user.email_confirm_by, Timex.now()) | ||
|
||
%{account: account} = Core.Repo.preload(user, [:account]) | ||
|