@ -1501,26 +1501,9 @@ RSpec.describe OrganisationsController, type: :request do
sign_in user
sign_in user
end
end
context " when flag not enabled " do
it " returns ok " do
before do
get " /organisations/ #{ organisation . id } /data-sharing-agreement " , headers : headers
allow ( FeatureToggle ) . to receive ( :new_data_protection_confirmation? ) . and_return ( false )
expect ( response ) . to have_http_status ( :ok )
end
it " returns not found " do
get " /organisations/ #{ organisation . id } /data-sharing-agreement " , headers : headers
expect ( response ) . to have_http_status ( :not_found )
end
end
context " when flag enabled " do
before do
allow ( FeatureToggle ) . to receive ( :new_data_protection_confirmation? ) . and_return ( true )
end
it " returns ok " do
get " /organisations/ #{ organisation . id } /data-sharing-agreement " , headers : headers
expect ( response ) . to have_http_status ( :ok )
end
end
end
end
end
end
end
@ -1541,10 +1524,8 @@ RSpec.describe OrganisationsController, type: :request do
sign_in user
sign_in user
end
end
context " when flag not enabled " do
context " when user not dpo " do
before do
let ( :user ) { create ( :user , is_dpo : false ) }
allow ( FeatureToggle ) . to receive ( :new_data_protection_confirmation? ) . and_return ( false )
end
it " returns not found " do
it " returns not found " do
post " /organisations/ #{ organisation . id } /data-sharing-agreement " , headers : headers
post " /organisations/ #{ organisation . id } /data-sharing-agreement " , headers : headers
@ -1552,12 +1533,8 @@ RSpec.describe OrganisationsController, type: :request do
end
end
end
end
context " when flag enabled " do
context " when user is dpo " do
before do
context " when the organisation has a non-confirmed confirmation " do
allow ( FeatureToggle ) . to receive ( :new_data_protection_confirmation? ) . and_return ( true )
end
context " when user not dpo " do
let ( :user ) { create ( :user , is_dpo : false ) }
let ( :user ) { create ( :user , is_dpo : false ) }
it " returns not found " do
it " returns not found " do
@ -1566,49 +1543,50 @@ RSpec.describe OrganisationsController, type: :request do
end
end
end
end
context " when user is dpo " do
context " when the organisation does not have a confirmation " do
context " when the organisation has a non-confirmed confirmation " do
before do
let ( :user ) { create ( :user , is_dpo : false ) }
Timecop . freeze ( Time . zone . local ( 2022 , 2 , 1 ) )
end
it " returns not found " do
after do
post " /organisations/ #{ organisation . id } /data-sharing-agreement " , headers : headers
Timecop . unfreeze
expect ( response ) . to have_http_status ( :not_found )
end
end
end
context " when the organisation does not have a confirmation " do
let ( :user ) { create ( :user , is_dpo : true , organisation : ) }
let ( :user ) { create ( :user , is_dpo : true , organisation : ) }
it " returns redirects to details page " do
it " returns redirects to details page " do
post " /organisations/ #{ organisation . id } /data-sharing-agreement " , headers : headers
post " /organisations/ #{ organisation . id } /data-sharing-agreement " , headers : headers
expect ( response ) . to redirect_to ( " /organisations/ #{ organisation . id } /details " )
expect ( response ) . to redirect_to ( " /organisations/ #{ organisation . id } /details " )
expect ( flash [ :notice ] ) . to eq ( " You have accepted the Data Sharing Agreement " )
expect ( flash [ :notice ] ) . to eq ( " You have accepted the Data Sharing Agreement " )
expect ( flash [ :notification_banner_body ] ) . to eq ( " Your organisation can now submit logs. " )
expect ( flash [ :notification_banner_body ] ) . to eq ( " Your organisation can now submit logs. " )
end
end
it " creates a data sharing agreement " do
it " creates a data sharing agreement " do
expect ( organisation . reload . data_protection_confirmation ) . to be_nil
expect ( organisation . reload . data_protection_confirmation ) . to be_nil
post ( " /organisations/ #{ organisation . id } /data-sharing-agreement " , headers : )
post ( " /organisations/ #{ organisation . id } /data-sharing-agreement " , headers : )
data_protection_confirmation = organisation . reload . data_protection_confirmation
data_protection_confirmation = organisation . reload . data_protection_confirmation
expect ( data_protection_confirmation . organisation . address_row ) . to eq ( organisation . address_row )
expect ( data_protection_confirmation . organisation ) . to eq ( organisation )
expect ( data_protection_confirmation . organisation . name ) . to eq ( organisation . name )
expect ( data_protection_confirmation . data_protection_officer ) . to eq ( user )
expect ( data_protection_confirmation . organisation . phone ) . to eq ( organisation . phone )
expect ( data_protection_confirmation . signed_at ) . to eq ( Time . zone . local ( 2022 , 2 , 1 ) )
expect ( data_protection_confirmation . data_protection_officer ) . to eq ( user )
expect ( data_protection_confirmation . organisation_name ) . to eq ( organisation . name )
end
expect ( data_protection_confirmation . organisation_address ) . to eq ( organisation . address_row )
expect ( data_protection_confirmation . organisation_phone_number ) . to eq ( organisation . phone )
expect ( data_protection_confirmation . data_protection_officer_email ) . to eq ( user . email )
expect ( data_protection_confirmation . data_protection_officer_name ) . to eq ( user . name )
end
context " when the user has already accepted the agreement " do
context " when the user has already accepted the agreement " do
before do
before do
create ( :data_protection_confirmation , data_protection_officer : user , organisation : user . organisation )
create ( :data_protection_confirmation , data_protection_officer : user , organisation : user . organisation )
end
end
it " returns not found " do
it " returns not found " do
post " /organisations/ #{ organisation . id } /data-sharing-agreement " , headers : headers
post " /organisations/ #{ organisation . id } /data-sharing-agreement " , headers : headers
expect ( response ) . to have_http_status ( :not_found )
expect ( response ) . to have_http_status ( :not_found )
end
end
end
end
end
end
end