Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ and this project adheres to

### Added

- `Lightning.SetupUtils.setup_demo/1` now seeds three sandboxes (one nested)
under the existing demo projects.
[#4774](https://github.com/OpenFn/lightning/issues/4774)

### Changed

### Fixed
Expand Down
24 changes: 24 additions & 0 deletions lib/lightning/setup_utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule Lightning.SetupUtils do
alias Lightning.Credentials
alias Lightning.Jobs
alias Lightning.Projects
alias Lightning.Projects.Sandboxes
alias Lightning.Repo
alias Lightning.Runs
alias Lightning.Workflows
Expand Down Expand Up @@ -41,6 +42,7 @@ defmodule Lightning.SetupUtils do
@spec setup_demo(nil | maybe_improper_list | map) :: %{
jobs: [...],
projects: [atom | %{:id => any, optional(any) => any}, ...],
sandboxes: [atom | %{:id => any, optional(any) => any}, ...],
users: [atom | %{:id => any, optional(any) => any}, ...],
workflows: [atom | %{:id => any, optional(any) => any}, ...],
workorders: [atom | %{:id => any, optional(any) => any}, ...]
Expand Down Expand Up @@ -75,10 +77,13 @@ defmodule Lightning.SetupUtils do
%{user_id: admin.id, role: :owner}
])

sandboxes = create_demo_sandboxes(openhie_project, dhis2_project, admin)

%{
jobs: openhie_jobs ++ dhis2_jobs,
users: [super_user, admin, editor, viewer],
projects: [openhie_project, dhis2_project],
sandboxes: sandboxes,
workflows: [openhie_workflow, dhis2_workflow],
workorders: [
openhie_workorder,
Expand All @@ -87,6 +92,25 @@ defmodule Lightning.SetupUtils do
}
end

defp create_demo_sandboxes(openhie_project, dhis2_project, admin) do
{:ok, openhie_dev} =
Sandboxes.provision(openhie_project, admin, %{
name: "openhie-dev"
})

{:ok, dhis2_dev} =
Sandboxes.provision(dhis2_project, admin, %{
name: "dhis2-dev"
})

{:ok, dhis2_feature_x} =
Sandboxes.provision(dhis2_dev, admin, %{
name: "dhis2-feature-x"
})

[openhie_dev, dhis2_dev, dhis2_feature_x]
end

defp to_log_lines(log) do
log
|> String.split("\n")
Expand Down
16 changes: 10 additions & 6 deletions test/lightning/setup_utils_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,11 @@ defmodule Lightning.SetupUtilsTest do

test "all initial data gets wiped out of database" do
assert Lightning.Accounts.list_users() |> Enum.count() > 0
assert Lightning.Projects.list_projects() |> Enum.count() == 2
assert Lightning.Workflows.list_workflows() |> Enum.count() == 2
assert Lightning.Jobs.list_jobs() |> Enum.count() == 6
# 2 root projects + 3 demo sandboxes
assert Lightning.Projects.list_projects() |> Enum.count() == 5
# 2 root workflows + 3 cloned into the demo sandboxes
assert Lightning.Workflows.list_workflows() |> Enum.count() == 5
assert Lightning.Jobs.list_jobs() |> Enum.count() == 14
assert Repo.all(Lightning.Invocation.Step) |> Enum.count() == 5

assert Repo.all(Lightning.Invocation.LogLine)
Expand All @@ -630,9 +632,11 @@ defmodule Lightning.SetupUtilsTest do

test "all initial data gets wiped out of database except superusers" do
assert Lightning.Accounts.list_users() |> Enum.count() > 1
assert Lightning.Projects.list_projects() |> Enum.count() == 2
assert Lightning.Workflows.list_workflows() |> Enum.count() == 2
assert Lightning.Jobs.list_jobs() |> Enum.count() == 6
# 2 root projects + 3 demo sandboxes
assert Lightning.Projects.list_projects() |> Enum.count() == 5
# 2 root workflows + 3 cloned into the demo sandboxes
assert Lightning.Workflows.list_workflows() |> Enum.count() == 5
assert Lightning.Jobs.list_jobs() |> Enum.count() == 14
assert Repo.all(Lightning.Invocation.Step) |> Enum.count() == 5

assert Repo.all(Lightning.Invocation.LogLine)
Expand Down