Skip to content

Commit

Permalink
Ensure the URN is validated correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
benlovell committed Dec 7, 2024
1 parent 616cb61 commit cf010ac
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/controllers/appointment_summaries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def create

def download
@appointment_summary = AppointmentSummary.new(appointment_summary_params)

return head :unprocessable_entity unless @appointment_summary.valid?

output_document = OutputDocument.new(@appointment_summary, 'generic')

send_data output_document.pdf,
Expand Down
2 changes: 1 addition & 1 deletion app/models/appointment_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(params = {})
end

validates :appointment_type, inclusion: { in: %w[standard 50_54] }
validates :urn, format: { with: /P[A-Z]{2}\d-\d[A-Z]{3}/ }, allow_blank: true
validates :urn, format: { with: /\AP[A-Z]{2}\d-\d[A-Z]{3}\z/ }, allow_blank: true

def appointment_type
@appointment_type
Expand Down
3 changes: 3 additions & 0 deletions spec/models/appointment_summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
it 'requires a valid form' do
subject.urn = 'This would really suck if it were to get through!'
expect(subject).to be_invalid

subject.urn = 'PMY9-0GCUwhoopsie'
expect(subject).to be_invalid
end
end
end
Expand Down
50 changes: 50 additions & 0 deletions spec/requests/downloading_a_pension_wise_digital_summary_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
RSpec.describe 'Generating a Pension Wise Digital summary download', type: :request do
specify 'Successfully generating the download without a URN' do
post '/en/summary-document/download', params: {
appointment_summary: {
appointment_type: 'standard',
supplementary_benefits: true,
supplementary_debt: true,
supplementary_ill_health: true,
supplementary_defined_benefit_pensions: true,
supplementary_pension_transfers: true
}
}

expect(response.status).to eq(200)
expect(response.content_type).to eq('application/pdf')
end

specify 'Successfully generating the download with a valid URN' do
post '/en/summary-document/download', params: {
appointment_summary: {
urn: 'PMY9-0GCU',
appointment_type: 'standard',
supplementary_benefits: true,
supplementary_debt: true,
supplementary_ill_health: true,
supplementary_defined_benefit_pensions: true,
supplementary_pension_transfers: true
}
}

expect(response.status).to eq(200)
expect(response.content_type).to eq('application/pdf')
end

specify 'Attempting a download with an invalid URN' do
post '/en/summary-document/download', params: {
appointment_summary: {
urn: 'PMY9-0GCUwhoopsies',
appointment_type: 'standard',
supplementary_benefits: true,
supplementary_debt: true,
supplementary_ill_health: true,
supplementary_defined_benefit_pensions: true,
supplementary_pension_transfers: true
}
}

expect(response.status).to eq(422)
end
end

0 comments on commit cf010ac

Please sign in to comment.