<commit_before>var requirejs = require('requirejs');

var controllerMap = require('../../../app/server/controller_map')();
var get_dashboard_and_render = require('../../../app/server/mixins/get_dashboard_and_render');
var StagecraftApiClient = requirejs('stagecraft_api_client');

describe('get_dashboard_and_render', function () {
  var fakeRenderContent,
      fake_request,
      fake_response,
      fakeStatusCall,
      api_client_initialize_spy;
  beforeEach(function (){
    api_client_initialize_spy = spyOn(StagecraftApiClient.prototype, 'initialize').andCallThrough();
    fakeRenderContent = jasmine.createSpy('fakiefakefakefake');
    var request_attrs = {
      'port': 8989,
      'stagecraftUrl': 'urlURL'
    };
    fake_request = {
      get: function(key) {
        return {
          'Request-Id':'Xb35Gt',
          'GOVUK-Request-Id': '1231234123'
        }[key];
      },
      'app': {
        'get': function(key) {
          return request_attrs[key];
        }
      },
      originalUrl: ''
    };
    fakeStatusCall = jasmine.createSpy('status');
    fake_response = {status: fakeStatusCall};
  });
  it('should set up the correct client_instance', function(){
    var client_instance = get_dashboard_and_render(fake_request, fake_response, fakeRenderContent);
    expect(StagecraftApiClient.prototype.initialize).toHaveBeenCalledWith(
      {
        params: {}
      },<commit_msg>Add test to check query params are sanitize<commit_after>var requirejs = require('requirejs');

var controllerMap = require('../../../app/server/controller_map')();
var get_dashboard_and_render = require('../../../app/server/mixins/get_dashboard_and_render');
var StagecraftApiClient = requirejs('stagecraft_api_client');

describe('get_dashboard_and_render', function () {
  var fakeRenderContent,
      fake_request,
      fake_response,
      fakeStatusCall,
      api_client_initialize_spy;
  beforeEach(function (){
    api_client_initialize_spy = spyOn(StagecraftApiClient.prototype, 'initialize').andCallThrough();
    fakeRenderContent = jasmine.createSpy('fakiefakefakefake');
    var request_attrs = {
      'port': 8989,
      'stagecraftUrl': 'urlURL'
    };
    fake_request = {
      get: function(key) {
        return {
          'Request-Id':'Xb35Gt',
          'GOVUK-Request-Id': '1231234123'
        }[key];
      },
      'app': {
        'get': function(key) {
          return request_attrs[key];
        }
      },
      originalUrl: ''
    };

    fakeStatusCall = jasmine.createSpy('status');
    fake_response = {status: fakeStatusCall};
  });
  it('should set up the correct client_instance', function(){
    var client_instance = get_dashboard_and_render(fake_request, fake_response, fakeRenderContent);
    expect(StagecraftApiClient.prototype.initialize).toHaveBeenCalledWith(
      {
        params: {}
      },
      {
        ControllerMap: controllerMap,
        requestId: 'Xb35Gt',
        govukRequestId: '1231234123'
      });
    expect(client_instance.stagecraftUrlRoot).toEqual('urlURL/public/dashboards');
  });
  it('should escape XSS attempts in queries', function(){
    fake_request.originalUrl = 'http://localhost:3057/performance/central-government-websites?sortby=percentOfTotal(count:sum)%22%27--!%3E%3C/Title/%3C/Style/%3C/script/%3C/Textarea/%3C/Noscr%20ipt/%3C/Pre/%3C/Xmp%3E%3CSvg/Onload=confirm`OPENBUGBOUNTY`%3E&sortorder=descending';
    var client_instance = get_dashboard_and_render(fake_request, fake_response, fakeRenderContent);
    expect(StagecraftApiClient.prototype.initialize).toHaveBeenCalledWith(
      {
        params: {
          sortby: 'percentOfTotal(count:sum)&#34;\'--!&gt;&lt;/Title/&lt;/Style/&lt;/script/&lt;/Textarea/&lt;/Noscr ipt/&lt;/Pre/&lt;/Xmp&gt;&lt;Svg/Onload=confirm`OPENBUGBOUNTY`&gt;',
          sortorder: 'descending'
        }
      },
{'fraction_non_alphanumeric': 0.13973458235753317, 'fraction_numerical': 0.017434296122820714, 'mean_word_length': 3.538370720188902, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '11159', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1210, 'n_words': 165}