Skip to content

Commit

Permalink
Test that the users can download their CSV and that support users can…
Browse files Browse the repository at this point in the history
… still upload the sampling CSV
  • Loading branch information
Kizr committed Dec 24, 2024
1 parent 5541e12 commit 6375577
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6375577

Please sign in to comment.