-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup user, apiToken, project, creds via iex (#2370)
* concept * wip * names * create user via iex * cl
- Loading branch information
1 parent
070d447
commit 3623008
Showing
3 changed files
with
128 additions
and
2 deletions.
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
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 |
---|---|---|
|
@@ -4,7 +4,9 @@ defmodule Lightning.SetupUtilsTest do | |
import Swoosh.TestAssertions | ||
|
||
alias Lightning.{Accounts, Projects, Workflows, Jobs, SetupUtils} | ||
alias Lightning.Accounts.User | ||
alias Lightning.Projects.{Project, ProjectUser, ProjectCredential} | ||
alias Lightning.Accounts.{User, UserToken} | ||
alias Lightning.Credentials.{Credential} | ||
|
||
describe "Setup demo site seed data" do | ||
setup do | ||
|
@@ -34,7 +36,7 @@ defmodule Lightning.SetupUtilsTest do | |
User.valid_password?(super_user, "welcome123") | ||
|
||
user_token = | ||
Lightning.Repo.all(Lightning.Accounts.UserToken) | ||
Lightning.Repo.all(UserToken) | ||
|> List.first() | ||
|
||
assert user_token.user_id == super_user.id | ||
|
@@ -648,6 +650,68 @@ defmodule Lightning.SetupUtilsTest do | |
end | ||
end | ||
|
||
describe "setup_user/4" do | ||
test "creates a user, an api token, projects, and credentials" do | ||
assert :ok == | ||
Lightning.SetupUtils.setup_user( | ||
%{ | ||
first_name: "Taylor", | ||
last_name: "Downs", | ||
email: "[email protected]", | ||
password: "shh12345678!" | ||
}, | ||
"abc123", | ||
["project-a", "project-b"], | ||
[ | ||
%{ | ||
name: "openmrs", | ||
schema: "raw", | ||
body: %{"a" => "secret"} | ||
}, | ||
%{ | ||
name: "dhis2", | ||
schema: "raw", | ||
body: %{"b" => "safe"} | ||
} | ||
] | ||
) | ||
|
||
# check that the user and the API token has been created | ||
assert %User{id: user_id} = Repo.get_by(User, email: "[email protected]") | ||
assert %UserToken{} = Repo.get_by(UserToken, token: "abc123") | ||
|
||
# check that both projects are there | ||
assert [%Project{id: p1_id}, %Project{id: p2_id}] = Repo.all(Project) | ||
|
||
# check that the user has owner access to both | ||
assert [ | ||
%ProjectUser{project_id: ^p1_id, user_id: ^user_id, role: :owner}, | ||
%ProjectUser{project_id: ^p2_id, user_id: ^user_id, role: :owner} | ||
] = | ||
Repo.all(ProjectUser) | ||
|
||
credentials = | ||
Repo.all(Credential) |> Repo.preload(:project_credentials) | ||
|
||
assert [ | ||
%Credential{ | ||
name: "openmrs", | ||
project_credentials: [ | ||
%ProjectCredential{project_id: ^p1_id}, | ||
%ProjectCredential{project_id: ^p2_id} | ||
] | ||
}, | ||
%Credential{ | ||
name: "dhis2", | ||
project_credentials: [ | ||
%ProjectCredential{project_id: ^p1_id}, | ||
%ProjectCredential{project_id: ^p2_id} | ||
] | ||
} | ||
] = credentials | ||
end | ||
end | ||
|
||
defp get_dataclip_body(dataclip_id) do | ||
from(d in Lightning.Invocation.Dataclip, | ||
select: type(d.body, :string), | ||
|