Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New hmrc provdier yaml #1622

Merged
merged 15 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions app/assets/javascripts/webchat/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"BUSY",
"UNAVAILABLE",
"AVAILABLE",
"ERROR"
"ERROR",
"OFFLINE",
"ONLINE"
]
var $el = $(options.$el)
var openUrl = $el.attr('data-open-url')
Expand All @@ -22,6 +24,7 @@
var webchatStateClass = 'js-webchat-advisers-'
var intervalID = null
var lastRecordedState = null
var response_datatype = $el.attr('data-redirect')

function init () {
if (!availabilityUrl || !openUrl) throw 'urls for webchat not defined'
Expand All @@ -32,14 +35,15 @@

function handleOpenChat (evt) {
evt.preventDefault()
global.open(openUrl, 'newwin', 'width=366,height=516')
this.dataset.redirect =="true" ? window.location.href = openUrl : global.open(openUrl, 'newwin', 'width=366,height=516')
trackEvent('opened')
}

function checkAvailability () {
var ajaxConfig = {
url: availabilityUrl,
type: 'GET',
dataType: response_datatype,
timeout: AJAX_TIMEOUT,
success: apiSuccess,
error: apiError
Expand All @@ -48,8 +52,31 @@
}

function apiSuccess (result) {
var validState = API_STATES.indexOf(result.response) != -1
var state = validState ? result.response : "ERROR"

if(result.hasOwnProperty('inHOP')){
var validState = API_STATES.indexOf(result.status.toUpperCase()) != -1
var state = validState ? result.status : "ERROR"
if (result.inHOP == "true"){
if(result.availability == "true"){
if(result.status == "online"){
state="AVAILABLE"
}
if (result.status == "busy"){
state="BUSY"
}
if (result.status == "offline"){
state="UNAVAILABLE"
}
}else{
state="UNAVAILABLE"
}
}else{
state = "UNAVAILABLE"
}
}else{
var validState = API_STATES.indexOf(result.response) != -1
var state = validState ? result.response : "ERROR"
}
advisorStateChange(state)
}

Expand Down
5 changes: 3 additions & 2 deletions app/models/webchat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ class Webchat

validates_presence_of :base_path, :open_url, :availability_url

attr_reader :base_path, :open_url, :availability_url
attr_reader :base_path, :open_url, :availability_url, :open_url_redirect, :availability_payload_format

def initialize(attrs)
@base_path = attrs["base_path"] if attrs["base_path"].present?
@open_url = attrs["open_url"] if attrs["open_url"].present?
@availability_url = attrs["availability_url"] if attrs["availability_url"].present?

@open_url_redirect = attrs.fetch("open_url_redirect", nil)
@availability_payload_format = attrs.fetch("availability_payload_format", nil)
validate!
end

Expand Down
3 changes: 2 additions & 1 deletion app/views/shared/_webchat.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<span class="js-webchat"
data-availability-url="<%= @content_item.webchat.availability_url %>"
data-open-url="<%= @content_item.webchat.open_url %>"
data-redirect="<%= @content_item.webchat.availability_payload_format.present? ? @content_item.webchat.availability_payload_format : 'jsonp' %>"
>
<% if webchat_unavailable? %>
<%= unavailability_message %>
Expand All @@ -19,7 +20,7 @@
</span>
<span class="js-webchat-advisers-available hidden">
Advisers are available to chat.
<a href="#" rel="external" class="js-webchat-open-button">Speak to an adviser now</a>.
<a href="#" data-redirect="<%= @content_item.webchat.open_url_redirect.present? ? 'true' : 'false' %>" rel="external" class="js-webchat-open-button">Speak to an adviser now</a>.
</span>
<% end %>
</span>
Expand Down
65 changes: 30 additions & 35 deletions lib/webchat.yaml
Original file line number Diff line number Diff line change
@@ -1,45 +1,40 @@
- base_path: /government/organisations/hm-revenue-customs/contact/child-benefit
open_url: https://www.tax.service.gov.uk/csp-partials/open/1027
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1027
open_url: https://tax.service.gov.uk/ask-hmrc/webchat/child-benefit
availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006859&siteID=10006719&businessUnitID=19001235
open_url_redirect: true
- base_path: /government/organisations/hm-revenue-customs/contact/income-tax-enquiries-for-individuals-pensioners-and-employees
open_url: https://www.tax.service.gov.uk/csp-partials/open/1030
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1030
open_url: https://tax.service.gov.uk/ask-hmrc/webchat/income-tax-enquiries-for-individuals-pensioners-and-employees
availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006852&siteID=10006719&businessUnitID=19001235
open_url_redirect: true
- base_path: /government/organisations/hm-revenue-customs/contact/vat-online-services-helpdesk
open_url: https://www.tax.service.gov.uk/csp-partials/open/1026
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1026
open_url: https://tax.service.gov.uk/ask-hmrc/webchat/vat-online-services-helpdesk
availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006860&siteID=10006719&businessUnitID=19001235
open_url_redirect: true
- base_path: /government/organisations/hm-revenue-customs/contact/national-insurance-numbers
open_url: https://www.tax.service.gov.uk/csp-partials/open/1021
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1021
open_url: https://tax.service.gov.uk/ask-hmrc/webchat/national-insurance-numbers
availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006855&siteID=10006719&businessUnitID=19001235
open_url_redirect: true
- base_path: /government/organisations/hm-revenue-customs/contact/self-assessment
open_url: https://www.tax.service.gov.uk/csp-partials/open/1004
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1004
open_url: https://tax.service.gov.uk/ask-hmrc/webchat/self-assessment
availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006851&siteID=10006719&businessUnitID=19001235
open_url_redirect: true
- base_path: /government/organisations/hm-revenue-customs/contact/tax-credits-enquiries
open_url: https://www.tax.service.gov.uk/csp-partials/open/1016
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1016
open_url: https://tax.service.gov.uk/ask-hmrc/webchat/tax-credits-enquiries
availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006858&siteID=10006719&businessUnitID=19001235
open_url_redirect: true
- base_path: /government/organisations/hm-revenue-customs/contact/vat-enquiries
open_url: https://www.tax.service.gov.uk/csp-partials/open/1028
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1028
open_url: https://tax.service.gov.uk/ask-hmrc/webchat/vat-enquiries
availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006860&siteID=10006719&businessUnitID=19001235
open_url_redirect: true
- base_path: /government/organisations/hm-revenue-customs/contact/customs-international-trade-and-excise-enquiries
open_url: https://www.tax.service.gov.uk/csp-partials/open/1034
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1034
open_url: https://tax.service.gov.uk/ask-hmrc/webchat/customs-international-trade-and-excise-enquiries
availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006861&siteID=10006719&businessUnitID=19001235
open_url_redirect: true
- base_path: /government/organisations/hm-revenue-customs/contact/employer-enquiries
open_url: https://www.tax.service.gov.uk/csp-partials/open/1023
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1023
open_url: https://tax.service.gov.uk/ask-hmrc/webchat/employer-enquiries
availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006854&siteID=10006719&businessUnitID=19001235
open_url_redirect: true
- base_path: /government/organisations/hm-revenue-customs/contact/online-services-helpdesk
open_url: https://www.tax.service.gov.uk/csp-partials/open/1003
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1003
- base_path: /government/organisations/hm-revenue-customs/contact/charities-and-community-amateur-sports-clubs-cascs
open_url: https://www.tax.service.gov.uk/csp-partials/open/1087
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1087
- base_path: /government/organisations/hm-revenue-customs/contact/enquiries-from-employers-with-expatriate-employees
open_url: https://www.tax.service.gov.uk/csp-partials/open/1089
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1089
- base_path: /government/organisations/hm-revenue-customs/contact/share-schemes-for-employees
open_url: https://www.tax.service.gov.uk/csp-partials/open/1088
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1088
- base_path: /government/organisations/hm-revenue-customs/contact/non-uk-expatriate-employees-expats
open_url: https://www.tax.service.gov.uk/csp-partials/open/1089
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1089
- base_path: /government/organisations/hm-revenue-customs/contact/non-resident-landlords
open_url: https://www.tax.service.gov.uk/csp-partials/open/1086
availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1086
open_url: https://tax.service.gov.uk/ask-hmrc/webchat/online-services-helpdesk
availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006856&siteID=10006719&businessUnitID=19001235
open_url_redirect: true
8 changes: 4 additions & 4 deletions spec/javascripts/webchat.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ describe('Webchat', function () {
// Stub analytics.
GOVUK.analytics = GOVUK.analytics || {}
GOVUK.analytics.trackEvent = function () {}
var CHILD_BENEFIT_API_URL = 'https://www.tax.service.gov.uk/csp-partials/open/' +
1027
var INSERTION_HOOK = '<div class="js-webchat" data-availability-url="' + CHILD_BENEFIT_API_URL + '" data-open-url="' + CHILD_BENEFIT_API_URL + '">' +
var CHILD_BENEFIT_API_URL = 'https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006859&siteID=10006719&businessUnitID=19001235'

var INSERTION_HOOK = '<div class="js-webchat" data-availability-url="' + CHILD_BENEFIT_API_URL + '" data-open-url="' + CHILD_BENEFIT_API_URL + '" data-redirect="jsonp">' +
'<div class="js-webchat-advisers-error">Error</div>' +
'<div class="js-webchat-advisers-unavailable hidden">Unavailable</div>' +
'<div class="js-webchat-advisers-busy hidden">Busy</div>' +
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('Webchat', function () {
mount()
expect(
$.ajax
).toHaveBeenCalledWith({ url: CHILD_BENEFIT_API_URL, type: 'GET', timeout: jasmine.any(Number), success: jasmine.any(Function), error: jasmine.any(Function) })
).toHaveBeenCalledWith({ url: CHILD_BENEFIT_API_URL, type: 'GET', dataType: "jsonp" ,timeout: jasmine.any(Number), success: jasmine.any(Function), error: jasmine.any(Function) })
})

it('should inform user whether advisors are available', function () {
Expand Down
4 changes: 2 additions & 2 deletions test/presenters/contact_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def schema_name
schema = schema_item("contact_with_webchat")
presented = present_example(schema)
assert_equal true, presented.show_webchat?
assert_equal presented.webchat.availability_url, "https://www.tax.service.gov.uk/csp-partials/availability/1030"
assert_equal presented.webchat.open_url, "https://www.tax.service.gov.uk/csp-partials/open/1030"
assert_equal presented.webchat.availability_url, "https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006852&siteID=10006719&businessUnitID=19001235"
assert_equal presented.webchat.open_url, "https://tax.service.gov.uk/ask-hmrc/webchat/income-tax-enquiries-for-individuals-pensioners-and-employees"
end
end
end