Skip to content

Commit

Permalink
Fix authentication specs with new routing
Browse files Browse the repository at this point in the history
Move host ENV setup into a `.env.test` file for more simple setup.

Use the placements service for auth specs.
  • Loading branch information
Nitemaeric committed Dec 14, 2023
1 parent c453198 commit d4cb351
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PLACEMENTS_HOST=placements.localhost
CLAIMS_HOST=claims.localhost
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ApplicationController < ActionController::Base
include ApplicationHelper

default_form_builder(GOVUKDesignSystemFormBuilder::FormBuilder)

helper_method :current_user
Expand Down
7 changes: 7 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ def current_service
:placements
end
end

def root_path
case current_service
when :claims then claims_root_path
when :placements then placements_root_path
end
end
end
6 changes: 6 additions & 0 deletions spec/features/personas/sign_in_as_persona_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
require "rails_helper"

feature "Sign In as Persona" do
around do |example|
Capybara.app_host = "https://#{ENV["PLACEMENTS_HOST"]}"
example.run
Capybara.app_host = nil
end

scenario "I sign in as persona Anne" do
given_there_is_an_existing_persona_for("Anne")
when_i_visit_the_personas_page
Expand Down
8 changes: 7 additions & 1 deletion spec/requests/sessions_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
require "rails_helper"

RSpec.describe "Sessions", type: :request do
around do |example|
host! ENV["PLACEMENTS_HOST"]
example.run
host! nil
end

describe "POST /auth/developer/callback" do
it "returns http success" do
post auth_developer_callback_path,
Expand All @@ -14,7 +20,7 @@
expect(response).to have_http_status(:success)
# TODO: Change render_template once redirect to service specific
# roots implemented
expect(response).to render_template("pages/home")
expect(response).to render_template("placements/pages/index")
end
end
end
2 changes: 0 additions & 2 deletions spec/system/home_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
private

def given_i_am_on_the_claims_site
ENV["CLAIMS_HOST"] = "claims.localhost"
Capybara.app_host = "http://#{ENV["CLAIMS_HOST"]}"
end

def given_i_am_on_the_placements_site
ENV["PLACEMENTS_HOST"] = "placements.localhost"
Capybara.app_host = "http://#{ENV["PLACEMENTS_HOST"]}"
end

Expand Down

0 comments on commit d4cb351

Please sign in to comment.