Skip to content

Commit

Permalink
add more tests for version control
Browse files Browse the repository at this point in the history
  • Loading branch information
midigofrank committed Sep 27, 2023
1 parent e528c55 commit 5d3922d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/lightning/version_control/github_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,20 @@ defmodule Lightning.VersionControl.GithubClient do
])}

{:ok, %{status: 404, body: body}} ->
Logger.error("Unexpected Github Response: #{inspect(body)}")

error =
GithubError.installation_not_found(
"Github Installation APP ID is misconfigured",
body
)

Sentry.capture_exception(error)
Logger.error(inspect(body, label: "Unexpected Github Response: "))

{:error, error}

{:ok, %{status: 401, body: body}} ->
Logger.error(inspect(body, label: "Unexpected Github Response: "))
Logger.error("Unexpected Github Response: #{inspect(body)}")

error =
GithubError.invalid_certificate(
Expand Down
44 changes: 44 additions & 0 deletions test/lightning_web/live/project_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,27 @@ defmodule LightningWeb.ProjectLiveTest do
assert view |> render_click("install_app", %{})
end

@tag role: :admin
test "Flashes an error when APP Name is missing during installation", %{
conn: conn,
project: project
} do
put_temporary_env(:lightning, :github_app,
cert: @cert,
app_id: nil,
app_name: nil
)

{:ok, view, _html} =
live(
conn,
~p"/projects/#{project.id}/settings#vcs"
)

assert view |> render_click("install_app", %{}) =~
"Sorry, it seems that the GitHub App Name has not been properly configured for this instance of Lighting. Please contact the instance administrator"
end

@tag role: :admin
test "can reinstall github app", %{
conn: conn,
Expand All @@ -618,6 +639,29 @@ defmodule LightningWeb.ProjectLiveTest do
assert view |> render_click("reinstall_app", %{})
end

@tag role: :admin
test "Flashes an error when APP Name is missing during reinstallation", %{
conn: conn,
project: project
} do
put_temporary_env(:lightning, :github_app,
cert: @cert,
app_id: nil,
app_name: nil
)

insert(:project_repo_connection, %{project_id: project.id, project: nil})

{:ok, view, _html} =
live(
conn,
~p"/projects/#{project.id}/settings#vcs"
)

assert view |> render_click("reinstall_app", %{}) =~
"Sorry, it seems that the GitHub App Name has not been properly configured for this instance of Lighting. Please contact the instance administrator"
end

@tag role: :admin
test "can delete github repo connection", %{
conn: conn,
Expand Down

0 comments on commit 5d3922d

Please sign in to comment.