Skip to content

Commit

Permalink
Updated redirect attribute so that it reflected correct yaml entry an…
Browse files Browse the repository at this point in the history
…d payload attribute to default to json

remove payload as request defeaults to json

remove payload as request defeaults to json
  • Loading branch information
RobBond-GDS committed Feb 4, 2020
1 parent e265339 commit da21d68
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
4 changes: 1 addition & 3 deletions app/assets/javascripts/webchat/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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 @@ -35,15 +34,14 @@

function handleOpenChat (evt) {
evt.preventDefault()
this.dataset.redirect =="true" ? window.location.href = openUrl : 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 Down
3 changes: 1 addition & 2 deletions app/models/webchat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ class Webchat

validates_presence_of :base_path, :open_url, :availability_url

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

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
2 changes: 1 addition & 1 deletion app/views/shared/_webchat.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +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' %>"
data-redirect="<%= @content_item.webchat.open_url_redirect.present? ? 'true': 'false' %>"
>
<% if webchat_unavailable? %>
<%= unavailability_message %>
Expand Down
4 changes: 2 additions & 2 deletions spec/javascripts/webchat.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Webchat', function () {
GOVUK.analytics.trackEvent = function () {}
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">' +
var INSERTION_HOOK = '<div class="js-webchat" data-availability-url="' + CHILD_BENEFIT_API_URL + '" data-open-url="' + CHILD_BENEFIT_API_URL + '" data-redirect="true">' +
'<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', dataType: "jsonp" ,timeout: jasmine.any(Number), success: jasmine.any(Function), error: jasmine.any(Function) })
).toHaveBeenCalledWith({ url: CHILD_BENEFIT_API_URL, type: 'GET' ,timeout: jasmine.any(Number), success: jasmine.any(Function), error: jasmine.any(Function) })
})

it('should inform user whether advisors are available', function () {
Expand Down

0 comments on commit da21d68

Please sign in to comment.