-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dependabot/bundler/pry-byebug-3.9.0
- Loading branch information
Showing
13 changed files
with
358 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ntrollers/waste_carriers_engine/registration_received_pending_payment_forms_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module WasteCarriersEngine | ||
class RegistrationReceivedPendingPaymentFormsController < FormsController | ||
def new | ||
return unless super(RegistrationReceivedPendingPaymentForm, "registration_received_pending_payment_form") | ||
|
||
begin | ||
@registration = RegistrationCompletionService.run(@transient_registration) | ||
rescue StandardError => e | ||
Airbrake.notify(e, reg_identifier: @transient_registration.reg_identifier) | ||
Rails.logger.error e | ||
end | ||
end | ||
|
||
# Overwrite create and go_back as you shouldn't be able to submit or go back | ||
def create; end | ||
|
||
def go_back; end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
app/forms/waste_carriers_engine/registration_received_pending_payment_form.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module WasteCarriersEngine | ||
class RegistrationReceivedPendingPaymentForm < BaseForm | ||
include CannotSubmit | ||
|
||
def self.can_navigate_flexibly? | ||
false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
app/services/waste_carriers_engine/registration_completion_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# frozen_string_literal: true | ||
|
||
module WasteCarriersEngine | ||
class RegistrationCompletionService < BaseService | ||
attr_reader :transient_registration | ||
|
||
def run(transient_registration) | ||
@transient_registration = transient_registration | ||
|
||
transient_registration.with_lock do | ||
copy_names_to_contact_address | ||
copy_data_from_transient_registration | ||
|
||
set_reg_identifier | ||
set_expiry_date | ||
|
||
update_meta_data | ||
|
||
registration.save! | ||
|
||
delete_transient_registration | ||
send_confirmation_email | ||
|
||
begin | ||
RegistrationActivationService.run(registration: registration) | ||
rescue StandardError => e | ||
Airbrake.notify(e, reg_identifier: @transient_registration.reg_identifier) | ||
Rails.logger.error e | ||
end | ||
end | ||
|
||
registration | ||
end | ||
|
||
private | ||
|
||
def registration | ||
@_registration ||= Registration.new | ||
end | ||
|
||
def copy_names_to_contact_address | ||
transient_registration.contact_address.first_name = transient_registration.first_name | ||
transient_registration.contact_address.last_name = transient_registration.last_name | ||
end | ||
|
||
def update_meta_data | ||
registration.metaData.route = transient_registration.metaData.route | ||
registration.metaData.date_registered = Time.current | ||
end | ||
|
||
def set_expiry_date | ||
registration.expires_on = Rails.configuration.expires_after.years.from_now | ||
end | ||
|
||
def delete_transient_registration | ||
transient_registration.delete | ||
end | ||
|
||
def send_confirmation_email | ||
# TODO | ||
# Note that we will only send emails here if the registration has pending convictions or pending payments. | ||
# In the case when the registration can be completed, the registration activation email is sent from | ||
# the RegistrationActivationService. | ||
rescue StandardError => e | ||
Airbrake.notify(e, registration_no: registration.reg_identifier) if defined?(Airbrake) | ||
end | ||
|
||
def set_reg_identifier | ||
registration.reg_identifier = transient_registration.reg_identifier | ||
end | ||
|
||
def copy_data_from_transient_registration | ||
new_attributes = transient_registration.attributes.except( | ||
"_id", | ||
"reg_identifier", | ||
"token", | ||
"created_at", | ||
"temp_cards", | ||
"temp_company_postcode", | ||
"temp_start_option", | ||
"temp_contact_postcode", | ||
"temp_os_places_error", | ||
"temp_payment_method", | ||
"temp_tier_check", | ||
"_type", | ||
"workflow_state", | ||
"locking_name", | ||
"locked_at" | ||
) | ||
|
||
registration.write_attributes(new_attributes) | ||
end | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
app/views/waste_carriers_engine/registration_received_pending_payment_forms/new.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<div class="column-two-thirds"> | ||
<div class="govuk-box-highlight govuk-box-highlight_blue"> | ||
<h1 class="heading-xlarge"><%= t(".heading") %></h1> | ||
<h2 class="heading-large"><%= t(".highlight_text") %><br> | ||
<span class="strong"><%= @registration.reg_identifier %></span></p> | ||
</div> | ||
|
||
<p><%= t(".paragraph_1", email: @registration.contact_email) %></p> | ||
<p><%= t(".paragraph_2") %></p> | ||
|
||
<ul class="list list-bullet"> | ||
<% t(".list_1").each do |list_item| %> | ||
<li><%= list_item %></li> | ||
<% end %> | ||
</ul> | ||
|
||
<div class="panel"> | ||
<p> | ||
<%= t(".contact.paragraph_1") %> | ||
<a href="mailto:<%= t(".contact.email") %>nccc-carrierbroker@environment-agency.gov.uk"><%= t(".contact.email") %></a> | ||
<%= t(".contact.text") %> | ||
</p> | ||
</div> | ||
|
||
<p><%= link_to(t(".survey_link_text"), t("layouts.application.feedback_url")) %> <%= t(".survey_link_hint") %></p> | ||
</div> |
20 changes: 20 additions & 0 deletions
20
config/locales/forms/registration_received_pending_payment_forms/en.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
en: | ||
waste_carriers_engine: | ||
registration_received_pending_payment_forms: | ||
new: | ||
title: "You must now pay by bank transfer" | ||
heading: "You must now pay by bank transfer." | ||
highlight_text: "Then email us your registration number:" | ||
paragraph_1: "We’ve sent an email to %{email} with the payment details and instructions." | ||
paragraph_2: "We will not register you until your payment clears." | ||
list_1: | ||
- "You’re not legally entitled to operate as a waste carrier until we have received your payment and confirmed your registration." | ||
- "Please allow 5 working days for your payment to reach us." | ||
- "Alternatively, contact us to pay by credit or debit card." | ||
contact: | ||
paragraph_1: "Contact the Environment Agency on" | ||
email: "nccc-carrierbroker@environment-agency.gov.uk" | ||
text: "or 03708 506506 within 28 days if your details change." | ||
survey_link_text: What did you think of the service? | ||
survey_link_hint: (takes 30 seconds) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
spec/requests/waste_carriers_engine/registration_received_pending_payment_forms_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
module WasteCarriersEngine | ||
RSpec.describe "RenewalCompleteForms", type: :request do | ||
describe "GET new_registration_received_pending_payment_form_path" do | ||
context "when no new registration exists" do | ||
it "redirects to the invalid page" do | ||
get new_registration_received_pending_payment_form_path("wibblewobblejellyonaplate") | ||
|
||
expect(response).to redirect_to(page_path("invalid")) | ||
end | ||
end | ||
|
||
context "when a valid new registration exists" do | ||
let(:transient_registration) do | ||
create( | ||
:new_registration, | ||
:has_required_data, | ||
workflow_state: "registration_received_pending_payment_form" | ||
) | ||
end | ||
|
||
context "when the workflow_state is correct" do | ||
it "returns a 200 status, renders the :new template, creates a new registration and deletes the transient registration" do | ||
reg_identifier = transient_registration.reg_identifier | ||
new_registrations_count = WasteCarriersEngine::NewRegistration.count | ||
|
||
get new_registration_received_pending_payment_form_path(transient_registration.token) | ||
|
||
registration = WasteCarriersEngine::Registration.find_by(reg_identifier: reg_identifier) | ||
|
||
expect(response).to have_http_status(200) | ||
expect(response).to render_template(:new) | ||
expect(registration).to be_valid | ||
expect(WasteCarriersEngine::NewRegistration.count).to eq(new_registrations_count - 1) | ||
end | ||
end | ||
|
||
context "when the workflow_state is not correct" do | ||
before do | ||
transient_registration.update_attributes(workflow_state: "payment_summary_form") | ||
end | ||
|
||
it "redirects to the correct page and does not creates a new registration nor delete the transient object" do | ||
new_registrations_count = WasteCarriersEngine::NewRegistration.count | ||
|
||
get new_registration_received_pending_payment_form_path(transient_registration.token) | ||
|
||
registration_scope = WasteCarriersEngine::Registration.where(reg_identifier: transient_registration.reg_identifier) | ||
|
||
expect(response).to redirect_to(new_payment_summary_form_path(transient_registration.token)) | ||
expect(WasteCarriersEngine::NewRegistration.count).to eq(new_registrations_count) | ||
expect(registration_scope).to be_empty | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.