From 5ced5c895fb729f6adee08bfb693b0ea0bc5cf64 Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Fri, 11 May 2018 16:28:16 +0100 Subject: [PATCH] Add HMRC webchat unavailability message --- app/helpers/webchat_availability_helper.rb | 20 ++++++++++ app/views/shared/_webchat.html.erb | 40 ++++++++++--------- .../webchat_availability_helper_test.rb | 17 ++++++++ 3 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 app/helpers/webchat_availability_helper.rb create mode 100644 test/helpers/webchat_availability_helper_test.rb diff --git a/app/helpers/webchat_availability_helper.rb b/app/helpers/webchat_availability_helper.rb new file mode 100644 index 000000000..fce3978f2 --- /dev/null +++ b/app/helpers/webchat_availability_helper.rb @@ -0,0 +1,20 @@ +module WebchatAvailabilityHelper + UNAVAILABILITY_MESSAGE = "This service will be unavailable from 4pm on Saturday 12 May to 9am on Monday 14 May.".freeze + HMRC_WEBCHAT_CONTACT_PATHS = %w( + /government/organisations/hm-revenue-customs/contact/online-services-helpdesk + /government/organisations/hm-revenue-customs/contact/income-tax-enquiries-for-individuals-pensioners-and-employees + /government/organisations/hm-revenue-customs/contact/self-assessment + /government/organisations/hm-revenue-customs/contact/tax-credits-enquiries + ).freeze + UNAVAILABILITY_START = Time.parse("2018-05-12 16:00 BST").freeze + UNAVAILABILITY_END = Time.parse("2018-05-14 09:00 BST").freeze + + def webchat_unavailable?(now = Time.zone.now) + show_unavailability = now >= UNAVAILABILITY_START && now < UNAVAILABILITY_END + show_unavailability && HMRC_WEBCHAT_CONTACT_PATHS.include?(@content_item.base_path) + end + + def unavailability_message + UNAVAILABILITY_MESSAGE + end +end diff --git a/app/views/shared/_webchat.html.erb b/app/views/shared/_webchat.html.erb index 9c8888632..2e9a4cf14 100644 --- a/app/views/shared/_webchat.html.erb +++ b/app/views/shared/_webchat.html.erb @@ -1,25 +1,29 @@ - <% if @content_item.base_path == '/government/organisations/hm-revenue-customs/contact/tax-credits-enquiries' %> - Advisers can only talk to you about Child Tax Credit and Working Tax Credit. - They won't be able to transfer you to another webchat team. -
-
+ <% if webchat_unavailable? %> + <%= unavailability_message %> + <% else %> + <% if @content_item.base_path == '/government/organisations/hm-revenue-customs/contact/tax-credits-enquiries' %> + Advisers can only talk to you about Child Tax Credit and Working Tax Credit. + They won't be able to transfer you to another webchat team. +
+
+ <% end %> + + Webchat is unavailable at the moment because of technical problems. + + + + <% end %> - - Webchat is unavailable at the moment because of technical problems. - - - -
<% # This is inline in the source however slimmer will optimize this. %> <%= javascript_include_tag "webchat", integrity: true, crossorigin: 'anonymous' %> diff --git a/test/helpers/webchat_availability_helper_test.rb b/test/helpers/webchat_availability_helper_test.rb new file mode 100644 index 000000000..4003d4d06 --- /dev/null +++ b/test/helpers/webchat_availability_helper_test.rb @@ -0,0 +1,17 @@ +require 'test_helper' + +class WebchatAvailabilityHelperTest < ActionView::TestCase + tests WebchatAvailabilityHelper + + setup do + @content_item = Object.new + @content_item.stubs(:base_path).returns(HMRC_WEBCHAT_CONTACT_PATHS.first) + end + + test "webchat_unavailable? indicates unavailability" do + refute webchat_unavailable?(Time.parse("2018-05-12 15:59 BST")) + assert webchat_unavailable?(Time.parse("2018-05-12 16:00 BST")) + assert webchat_unavailable?(Time.parse("2018-05-14 08:59 BST")) + refute webchat_unavailable?(Time.parse("2018-05-14 09:00 BST")) + end +end