diff --git a/spec/system/claims/sampling/claims/provider_user_downloads_sampling_csv_with_expired_token_spec.rb b/spec/system/claims/sampling/claims/provider_user_downloads_sampling_csv_with_expired_token_spec.rb new file mode 100644 index 000000000..d8e3fa2a7 --- /dev/null +++ b/spec/system/claims/sampling/claims/provider_user_downloads_sampling_csv_with_expired_token_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" + +RSpec.describe "Provider user downloads a sampling CSV with expired token", service: :claims, type: :system do + scenario do + given_one_of_my_claims_has_been_sampled + and_the_token_has_expired + + when_i_visit_the_download_link_in_the_email + then_i_see_the_error_page + end + + private + + def given_one_of_my_claims_has_been_sampled + @provider_sampling = create(:provider_sampling) + end + + def and_the_token_has_expired + @token = Rails.application.message_verifier(:sampling).generate(@provider_sampling.id, expires_at: 1.day.ago) + end + + def when_i_visit_the_download_link_in_the_email + visit claims_sampling_claims_path(token: @token) + end + + def then_i_see_the_error_page + expect(page).to have_h1("Sorry, there is a problem with the download link") + expect(page).to have_element(:p, text: "You are seeing this page because the download link is not working. It may have timed out or contained an invalid security token.", class: "govuk-body") + expect(page).to have_element(:p, text: "Email ittmentor.funding@education.gov.uk to request a new download link.", class: "govuk-body") + end +end diff --git a/spec/system/claims/sampling/claims/provider_user_downloads_sampling_csv_with_invalid_record_token_spec.rb b/spec/system/claims/sampling/claims/provider_user_downloads_sampling_csv_with_invalid_record_token_spec.rb new file mode 100644 index 000000000..ae9b32dda --- /dev/null +++ b/spec/system/claims/sampling/claims/provider_user_downloads_sampling_csv_with_invalid_record_token_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" + +RSpec.describe "Provider user downloads a sampling CSV with invalid record token", service: :claims, type: :system do + scenario do + given_one_of_my_claims_has_been_sampled + and_the_token_has_expired + + when_i_visit_the_download_link_in_the_email + then_i_see_the_error_page + end + + private + + def given_one_of_my_claims_has_been_sampled + @provider_sampling = create(:provider_sampling) + end + + def and_the_token_has_expired + @token = Rails.application.message_verifier(:sampling).generate("invalid_token", expires_in: 7.days) + end + + def when_i_visit_the_download_link_in_the_email + visit claims_sampling_claims_path(token: @token) + end + + def then_i_see_the_error_page + expect(page).to have_h1("Sorry, there is a problem with the download link") + expect(page).to have_element(:p, text: "You are seeing this page because the download link is not working. It may have timed out or contained an invalid security token.", class: "govuk-body") + expect(page).to have_element(:p, text: "Email ittmentor.funding@education.gov.uk to request a new download link.", class: "govuk-body") + end +end diff --git a/spec/system/claims/sampling/claims/provider_user_downloads_sampling_csv_with_invalid_token_spec.rb b/spec/system/claims/sampling/claims/provider_user_downloads_sampling_csv_with_invalid_token_spec.rb new file mode 100644 index 000000000..38a34cd1e --- /dev/null +++ b/spec/system/claims/sampling/claims/provider_user_downloads_sampling_csv_with_invalid_token_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" + +RSpec.describe "Provider user downloads a sampling CSV with invalid token", service: :claims, type: :system do + scenario do + given_one_of_my_claims_has_been_sampled + and_the_token_is_invalid + + when_i_visit_the_download_link_in_the_email + then_i_see_the_error_page + end + + private + + def given_one_of_my_claims_has_been_sampled + @provider_sampling = create(:provider_sampling) + end + + def and_the_token_is_invalid + @token = Rails.application.message_verifier(:bobs_burgers).generate(@provider_sampling.id, expires_in: 7.days) + end + + def when_i_visit_the_download_link_in_the_email + visit claims_sampling_claims_path(token: @token) + end + + def then_i_see_the_error_page + expect(page).to have_h1("Sorry, there is a problem with the download link") + expect(page).to have_element(:p, text: "You are seeing this page because the download link is not working. It may have timed out or contained an invalid security token.", class: "govuk-body") + expect(page).to have_element(:p, text: "Email ittmentor.funding@education.gov.uk to request a new download link.", class: "govuk-body") + end +end diff --git a/spec/system/claims/sampling/claims/provider_user_downloads_sampling_csv_with_valid_token_spec.rb b/spec/system/claims/sampling/claims/provider_user_downloads_sampling_csv_with_valid_token_spec.rb new file mode 100644 index 000000000..6fcc8cc1e --- /dev/null +++ b/spec/system/claims/sampling/claims/provider_user_downloads_sampling_csv_with_valid_token_spec.rb @@ -0,0 +1,45 @@ +require "rails_helper" + +RSpec.describe "Provider user downloads sampling CSV with valid token", service: :claims, type: :system do + scenario do + given_one_of_my_claims_has_been_sampled + and_the_token_is_valid + + when_i_visit_the_download_link_in_the_email + then_i_see_the_download_page + + when_i_click_on_the_download_button + then_the_csv_is_downloaded + end + + private + + def given_one_of_my_claims_has_been_sampled + @provider_sampling = create(:provider_sampling) + end + + def and_the_token_is_valid + @token = Rails.application.message_verifier(:sampling).generate(@provider_sampling.id, expires_in: 7.days) + end + + def when_i_visit_the_download_link_in_the_email + visit claims_sampling_claims_path(token: @token) + end + + def then_i_see_the_download_page + expect(page).to have_h1("Download the sampling CSV") + expect(page).to have_element(:p, text: "Download the Claim funding for mentor training sampling CSV file.", class: "govuk-body") + expect(page).to have_element(:p, text: "If you have any questions, email ittmentor.funding@education.gov.uk", class: "govuk-body") + expect(page).to have_element(:a, text: "Download", class: "govuk-button") + end + + def when_i_click_on_the_download_button + click_on "Download" + end + + def then_the_csv_is_downloaded + current_time = Time.zone.now.utc.strftime("%Y-%m-%dT%H%%3A%M%%3A%SZ") + expect(page.response_headers["Content-Type"]).to eq("text/csv") + expect(page.response_headers["Content-Disposition"]).to eq("attachment; filename=\"sampling-claims-#{current_time}.csv\"; filename*=UTF-8''sampling-claims-#{current_time}.csv") + end +end diff --git a/spec/system/claims/support/claims/sampling/upload_data/support_user_uploads_sampling_data_spec.rb b/spec/system/claims/support/claims/sampling/upload_data/support_user_uploads_sampling_data_spec.rb index b9a0de2e0..c8e79ae6f 100644 --- a/spec/system/claims/support/claims/sampling/upload_data/support_user_uploads_sampling_data_spec.rb +++ b/spec/system/claims/support/claims/sampling/upload_data/support_user_uploads_sampling_data_spec.rb @@ -57,11 +57,15 @@ def given_claims_exist current_claim_window = create(:claim_window, academic_year: @current_academic_year, starts_on: @current_academic_year.starts_on, ends_on: @current_academic_year.starts_on + 2.days) + + provider = create(:claims_provider, email_address: "provider@example.com") + @current_claim = create(:claim, :submitted, status: :paid, claim_window: current_claim_window, - reference: 11_111_111) + reference: 11_111_111, + provider:) end def and_i_am_signed_in