Skip to content

Commit

Permalink
Support request specs in the sign_in_as helper
Browse files Browse the repository at this point in the history
I've updated the `sign_in_as` test helper method so it can be used for
both system specs and request specs.

Since they're both operating under different contexts, authentication
needs to be mocked differently depending on the type of test.
  • Loading branch information
ollietreend committed Jul 4, 2024
1 parent eb7b0ac commit 11f785d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 22 deletions.
4 changes: 1 addition & 3 deletions spec/requests/placements/providers/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
let(:current_user) { create(:placements_user, providers: [provider]) }

before do
user_exists_in_dfe_sign_in(user: current_user)
get "/auth/dfe/callback"
follow_redirect!
sign_in_as current_user
end

describe "DELETE" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

before do
user = create(:placements_user, schools: [school])
user_exists_in_dfe_sign_in(user:)

get "/auth/dfe/callback"

follow_redirect!
sign_in_as user
end

context "when editing mentors" do
Expand Down
4 changes: 1 addition & 3 deletions spec/requests/placements/schools/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
let(:current_user) { create(:placements_user, schools: [school]) }

before do
user_exists_in_dfe_sign_in(user: current_user)
get "/auth/dfe/callback"
follow_redirect!
sign_in_as current_user
end

describe "DELETE" do
Expand Down
4 changes: 1 addition & 3 deletions spec/requests/placements/support/support_users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
let(:support_users) { Placements::SupportUser.all }

before do
user_exists_in_dfe_sign_in(user: current_user)
get "/auth/dfe/callback"
follow_redirect!
sign_in_as current_user
end

describe "DELETE" do
Expand Down
6 changes: 0 additions & 6 deletions spec/requests/placements/support/user_authorisation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,4 @@
end
end
end

def sign_in_as(user)
user_exists_in_dfe_sign_in(user:)
get "/auth/dfe/callback"
follow_redirect!
end
end
11 changes: 9 additions & 2 deletions spec/support/dfe_sign_in_user_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
module DfESignInUserHelper
def sign_in_as(user)
user_exists_in_dfe_sign_in(user:)
visit sign_in_path
click_on "Sign in using DfE Sign In"

case RSpec.current_example.metadata[:type]
when :system
visit sign_in_path
click_on "Sign in using DfE Sign In"
when :request
get "/auth/dfe/callback"
follow_redirect!
end
end
alias_method :given_i_sign_in_as, :sign_in_as

Expand Down

0 comments on commit 11f785d

Please sign in to comment.