@ -37,14 +37,6 @@ RSpec.describe SchemesController, type: :request do
get " /schemes "
get " /schemes "
end
end
context " when params scheme_id is present " do
it " shows a success banner " do
get " /schemes " , params : { scheme_id : schemes . first . id }
follow_redirect!
expect ( page ) . to have_css ( " .govuk-notification-banner.govuk-notification-banner--success " )
end
end
it " redirects to the organisation schemes path " do
it " redirects to the organisation schemes path " do
follow_redirect!
follow_redirect!
expect ( path ) . to match ( " /organisations/ #{ user . organisation . id } /schemes " )
expect ( path ) . to match ( " /organisations/ #{ user . organisation . id } /schemes " )
@ -93,13 +85,6 @@ RSpec.describe SchemesController, type: :request do
expect ( CGI . unescape_html ( response . body ) ) . to match ( " <strong> #{ schemes . count } </strong> total schemes " )
expect ( CGI . unescape_html ( response . body ) ) . to match ( " <strong> #{ schemes . count } </strong> total schemes " )
end
end
context " when params scheme_id is present " do
it " shows a success banner " do
get " /schemes " , params : { scheme_id : schemes . first . id }
expect ( page ) . to have_css ( " .govuk-notification-banner.govuk-notification-banner--success " )
end
end
context " when paginating over 20 results " do
context " when paginating over 20 results " do
let ( :total_schemes_count ) { Scheme . count }
let ( :total_schemes_count ) { Scheme . count }
@ -884,9 +869,11 @@ RSpec.describe SchemesController, type: :request do
context " when signed in as a support " do
context " when signed in as a support " do
let ( :user ) { FactoryBot . create ( :user , :support ) }
let ( :user ) { FactoryBot . create ( :user , :support ) }
let ( :scheme_to_update ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation ) }
let ( :scheme_to_update ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation , confirmed : nil ) }
# let!(:location) { FactoryBot.create(:location, scheme: scheme_to_update) }
before do
before do
FactoryBot . create ( :location , scheme : scheme_to_update )
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
sign_in user
sign_in user
patch " /schemes/ #{ scheme_to_update . id } " , params :
patch " /schemes/ #{ scheme_to_update . id } " , params :
@ -939,6 +926,21 @@ RSpec.describe SchemesController, type: :request do
expect ( scheme_to_update . reload . primary_client_group ) . to eq ( " Homeless families with support needs " )
expect ( scheme_to_update . reload . primary_client_group ) . to eq ( " Homeless families with support needs " )
end
end
end
end
context " when saving a scheme " do
let ( :params ) { { scheme : { page : " check-answers " , confirmed : " true " } } }
it " marks the scheme as confirmed " do
expect ( scheme_to_update . reload . confirmed? ) . to eq ( true )
end
it " marks all the scheme locations as confirmed " do
expect ( scheme_to_update . locations . count > 0 ) . to eq ( true )
scheme_to_update . locations . each do | location |
expect ( location . confirmed? ) . to eq ( true )
end
end
end
end
end
context " when updating primary client group " do
context " when updating primary client group " do
@ -1175,7 +1177,7 @@ RSpec.describe SchemesController, type: :request do
context " when signed in as a data coordinator " do
context " when signed in as a data coordinator " do
let ( :user ) { FactoryBot . create ( :user , :data_coordinator ) }
let ( :user ) { FactoryBot . create ( :user , :data_coordinator ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation , confirmed : nil ) }
let! ( :another_scheme ) { FactoryBot . create ( :scheme ) }
let! ( :another_scheme ) { FactoryBot . create ( :scheme ) }
before do
before do
@ -1202,7 +1204,7 @@ RSpec.describe SchemesController, type: :request do
context " when signed in as a support user " do
context " when signed in as a support user " do
let ( :user ) { FactoryBot . create ( :user , :support ) }
let ( :user ) { FactoryBot . create ( :user , :support ) }
let! ( :scheme ) { FactoryBot . create ( :scheme ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , confirmed : nil ) }
before do
before do
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
@ -1214,6 +1216,21 @@ RSpec.describe SchemesController, type: :request do
expect ( response ) . to have_http_status ( :ok )
expect ( response ) . to have_http_status ( :ok )
expect ( page ) . to have_content ( " What client group is this scheme intended for? " )
expect ( page ) . to have_content ( " What client group is this scheme intended for? " )
end
end
context " and the scheme is confirmed " do
before do
scheme . update! ( confirmed : true )
get " /schemes/ #{ scheme . id } /primary-client-group "
end
it " redirects to a view scheme page " do
follow_redirect!
expect ( response ) . to have_http_status ( :ok )
expect ( path ) . to match ( " /schemes/ #{ scheme . id } " )
expect ( page ) . to have_content ( scheme . service_name )
assert_select " a " , text : / Change / , count : 3
end
end
end
end
end
end
@ -1241,7 +1258,7 @@ RSpec.describe SchemesController, type: :request do
context " when signed in as a data coordinator " do
context " when signed in as a data coordinator " do
let ( :user ) { FactoryBot . create ( :user , :data_coordinator ) }
let ( :user ) { FactoryBot . create ( :user , :data_coordinator ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation , confirmed : nil ) }
let! ( :another_scheme ) { FactoryBot . create ( :scheme ) }
let! ( :another_scheme ) { FactoryBot . create ( :scheme ) }
before do
before do
@ -1268,7 +1285,7 @@ RSpec.describe SchemesController, type: :request do
context " when signed in as a support user " do
context " when signed in as a support user " do
let ( :user ) { FactoryBot . create ( :user , :support ) }
let ( :user ) { FactoryBot . create ( :user , :support ) }
let! ( :scheme ) { FactoryBot . create ( :scheme ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , confirmed : nil ) }
before do
before do
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
@ -1280,6 +1297,21 @@ RSpec.describe SchemesController, type: :request do
expect ( response ) . to have_http_status ( :ok )
expect ( response ) . to have_http_status ( :ok )
expect ( page ) . to have_content ( " Does this scheme provide for another client group? " )
expect ( page ) . to have_content ( " Does this scheme provide for another client group? " )
end
end
context " and the scheme is confirmed " do
before do
scheme . update! ( confirmed : true )
get " /schemes/ #{ scheme . id } /confirm-secondary-client-group "
end
it " redirects to a view scheme page " do
follow_redirect!
expect ( response ) . to have_http_status ( :ok )
expect ( path ) . to match ( " /schemes/ #{ scheme . id } " )
expect ( page ) . to have_content ( scheme . service_name )
assert_select " a " , text : / Change / , count : 3
end
end
end
end
end
end
@ -1307,7 +1339,7 @@ RSpec.describe SchemesController, type: :request do
context " when signed in as a data coordinator " do
context " when signed in as a data coordinator " do
let ( :user ) { FactoryBot . create ( :user , :data_coordinator ) }
let ( :user ) { FactoryBot . create ( :user , :data_coordinator ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation , confirmed : nil ) }
let! ( :another_scheme ) { FactoryBot . create ( :scheme ) }
let! ( :another_scheme ) { FactoryBot . create ( :scheme ) }
before do
before do
@ -1334,7 +1366,7 @@ RSpec.describe SchemesController, type: :request do
context " when signed in as a support user " do
context " when signed in as a support user " do
let ( :user ) { FactoryBot . create ( :user , :support ) }
let ( :user ) { FactoryBot . create ( :user , :support ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , primary_client_group : Scheme :: PRIMARY_CLIENT_GROUP [ :" Homeless families with support needs " ] ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , confirmed : nil , primary_client_group : Scheme :: PRIMARY_CLIENT_GROUP [ :" Homeless families with support needs " ] ) }
before do
before do
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
@ -1347,6 +1379,21 @@ RSpec.describe SchemesController, type: :request do
expect ( page ) . to have_content ( " What is the other client group? " )
expect ( page ) . to have_content ( " What is the other client group? " )
end
end
context " and the scheme is confirmed " do
before do
scheme . update! ( confirmed : true )
get " /schemes/ #{ scheme . id } /secondary-client-group "
end
it " redirects to a view scheme page " do
follow_redirect!
expect ( response ) . to have_http_status ( :ok )
expect ( path ) . to match ( " /schemes/ #{ scheme . id } " )
expect ( page ) . to have_content ( scheme . service_name )
assert_select " a " , text : / Change / , count : 3
end
end
it " does not show the primary client group as an option " do
it " does not show the primary client group as an option " do
expect ( scheme . primary_client_group ) . not_to be_nil
expect ( scheme . primary_client_group ) . not_to be_nil
expect ( page ) . not_to have_content ( " Homeless families with support needs " )
expect ( page ) . not_to have_content ( " Homeless families with support needs " )
@ -1378,7 +1425,7 @@ RSpec.describe SchemesController, type: :request do
context " when signed in as a data coordinator " do
context " when signed in as a data coordinator " do
let ( :user ) { FactoryBot . create ( :user , :data_coordinator ) }
let ( :user ) { FactoryBot . create ( :user , :data_coordinator ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation , confirmed : nil ) }
let! ( :another_scheme ) { FactoryBot . create ( :scheme ) }
let! ( :another_scheme ) { FactoryBot . create ( :scheme ) }
before do
before do
@ -1401,11 +1448,26 @@ RSpec.describe SchemesController, type: :request do
expect ( response ) . to have_http_status ( :not_found )
expect ( response ) . to have_http_status ( :not_found )
end
end
end
end
context " and the scheme is confirmed " do
before do
scheme . update! ( confirmed : true )
get " /schemes/ #{ scheme . id } /support "
end
it " redirects to a view scheme page " do
follow_redirect!
expect ( response ) . to have_http_status ( :ok )
expect ( path ) . to match ( " /schemes/ #{ scheme . id } " )
expect ( page ) . to have_content ( scheme . service_name )
assert_select " a " , text : / Change / , count : 2
end
end
end
end
context " when signed in as a support user " do
context " when signed in as a support user " do
let ( :user ) { FactoryBot . create ( :user , :support ) }
let ( :user ) { FactoryBot . create ( :user , :support ) }
let! ( :scheme ) { FactoryBot . create ( :scheme ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , confirmed : nil ) }
before do
before do
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
@ -1510,7 +1572,7 @@ RSpec.describe SchemesController, type: :request do
context " when signed in as a data coordinator " do
context " when signed in as a data coordinator " do
let ( :user ) { FactoryBot . create ( :user , :data_coordinator ) }
let ( :user ) { FactoryBot . create ( :user , :data_coordinator ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation , confirmed : nil ) }
let! ( :another_scheme ) { FactoryBot . create ( :scheme ) }
let! ( :another_scheme ) { FactoryBot . create ( :scheme ) }
before do
before do
@ -1533,11 +1595,26 @@ RSpec.describe SchemesController, type: :request do
expect ( response ) . to have_http_status ( :not_found )
expect ( response ) . to have_http_status ( :not_found )
end
end
end
end
context " and the scheme is confirmed " do
before do
scheme . update! ( confirmed : true )
get " /schemes/ #{ scheme . id } /details "
end
it " redirects to a view scheme page " do
follow_redirect!
expect ( response ) . to have_http_status ( :ok )
expect ( path ) . to match ( " /schemes/ #{ scheme . id } " )
expect ( page ) . to have_content ( scheme . service_name )
assert_select " a " , text : / Change / , count : 2
end
end
end
end
context " when signed in as a support user " do
context " when signed in as a support user " do
let ( :user ) { FactoryBot . create ( :user , :support ) }
let ( :user ) { FactoryBot . create ( :user , :support ) }
let! ( :scheme ) { FactoryBot . create ( :scheme ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , confirmed : nil ) }
before do
before do
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )
allow ( user ) . to receive ( :need_two_factor_authentication? ) . and_return ( false )