<commit_before>const expect = require('chai').expect
const sinon = require('sinon')
const expensesUrlRouter = require('../../../../app/services/routing/expenses-url-router')
const paramBuilder = require('../../../../app/services/routing/param-builder')

describe('services/routing/expenses-url-router', function () {
  describe('parseParams', function () {
    var buildFormatted

    before(function () {
      buildFormatted = sinon.stub(paramBuilder, 'buildFormatted')
    })

    after(function () {
      buildFormatted.restore()
    })

    it('should call buildFormatted to build and format the params parameter', function () {
      expensesUrlRouter.parseParams([])
      sinon.assert.calledOnce(buildFormatted)
    })
  })

  describe('getRedirectUrl', function () {
    const VALID_PARAM_ONE = 'bus'
    const VALID_PARAM_TWO = 'hire'
    const CLAIM_TYPE = 'first-time'
    const REFERENCEID = 'URLROUT-123'
    const CLAIM_ID = '456'
    const ORIGINAL_URL = 'some-url'
    var validRequest = {
      body: {
        expenses: [
          VALID_PARAM_ONE,
          VALID_PARAM_TWO
        ]
      },
      originalUrl: ORIGINAL_URL,
      query: {},
      params: {
        claimType: CLAIM_TYPE,
        referenceId: REFERENCEID,
        claimId: CLAIM_ID
      }
    }
    const VALID_REQUEST_OUTPUT = `/apply/first-time/eligibility/${REFERENCEID}/claim/${CLAIM_ID}/${VALID_PARAM_ONE}?${VALID_PARAM_TWO}=`

    it('should throw an error if req is invalid', function (done) {
      expect(function () {
        expensesUrlRouter.getRedirectUrl(
          null)
      }).to.throw(Error)
      done()
    })

    it('should throw an error if req.body is invalid', function (done) {
      expect(function () {
        expensesUrlRouter.getRedirectUrl({
          body: null
        })
      }).to.throw(Error)
      done()
    })

    it('should throw an error if req.params is invalid', function (done) {
      expect(function () {
        expensesUrlRouter.getRedirectUrl({
          params: null
        })
      }).to.throw(Error)
      done()
    })

    it('should throw an error if req.params.referenceId is invalid', function (done) {
      expect(function () {
        expensesUrlRouter.getRedirectUrl({
          params: {
            referenceId: null
          }
        })
      }).to.throw(Error)
      done()
    })

    it('should throw an error if req.params.claimId is invalid', function (done) {
      expect(function () {
        expensesUrlRouter.getRedirectUrl({
          params: {
            claimId: null
          }
        })
      }).to.throw(Error)
      done()
    })

    it('should throw an error if req.originalUrl is invalid', function (done) {
      expect(function () {
        expensesUrlRouter.getRedirectUrl({
          originalUrl: null
        })
      }).to.throw(Error)
      done()
    })

    it('should throw an error if req.query is invalid', function (done) {
      expect(function () {
        expensesUrlRouter.getRedirectUrl({
          query: null
        })
      }).to.throw(Error)
      done()
    })

    it('should return a url path if passed a valid request and add-another-journey was not set', function (done) {
      var result = expensesUrlRouter.getRedirectUrl(validRequest)
      expect(result).to.be.equal(VALID_REQUEST_OUTPUT)
      done()
    })

    it('should return the originalUrl if passed a valid request with add-another-journey set', function (done) {
      validRequest.body['add-another-journey'] = 'on'
      var result = expensesUrlRouter.getRedirectUrl(validRequest)
      expect(result).to.be.equal(ORIGINAL_URL)
      done()
    })
  })
})<commit_msg>Chore/update expenses url router unit tests (#416)<commit_after>const expect = require('chai').expect
const sinon = require('sinon')
const expensesUrlRouter = require('../../../../app/services/routing/expenses-url-router')
const paramBuilder = require('../../../../app/services/routing/param-builder')

describe('services/routing/expenses-url-router', function () {
  describe('parseParams', function () {
    var buildFormatted

    before(function () {
      buildFormatted = sinon.stub(paramBuilder, 'buildFormatted')
    })

    after(function () {
      buildFormatted.restore()
    })

    it('should call buildFormatted to build and format the params parameter', function () {
      expensesUrlRouter.parseParams([])
      sinon.assert.calledOnce(buildFormatted)
    })
  })

  describe('getRedirectUrl', function () {
    const VALID_PARAM_ONE = 'bus'
    const VALID_PARAM_TWO = 'hire'
    const CLAIM_TYPE = 'first-time'
    const REFERENCE_ID = 'URLROUT-123'
    const CLAIM_ID = '456'
    const ORIGINAL_URL = 'some-url'
    const SUMMARY_URL = `/apply/first-time/eligibility/${REFERENCE_ID}/claim/${CLAIM_ID}/summary`

    var VALID_REQUEST = {
      body: {
        expenses: [
          VALID_PARAM_ONE,
          VALID_PARAM_TWO
        ]
      },
      originalUrl: ORIGINAL_URL,
      query: {},
      params: {
        claimType: CLAIM_TYPE,
        referenceId: REFERENCE_ID,
        claimId: CLAIM_ID
      }
    }
    const VALID_REQUEST_OUTPUT = `/apply/first-time/eligibility/${REFERENCE_ID}/claim/${CLAIM_ID}/${VALID_PARAM_ONE}?${VALID_PARAM_TWO}=`

    const NO_EXPENSE_REQUEST = {
      body: {
        expenses: []
      },
      originalUrl: ORIGINAL_URL,
      query: {},
      params: {
        claimType: CLAIM_TYPE,
        referenceId: REFERENCE_ID,
        claimId: CLAIM_ID
      }
    }

    const QUERY_PARAMATER_EXPENSE_REQUEST = {
      body: {
        expenses: []
      },
      originalUrl: ORIGINAL_URL,
      query: {
        'bus': ''
      },
      params: {
        claimType: CLAIM_TYPE,
        referenceId: REFERENCE_ID,
        claimId: CLAIM_ID
      }
    }

    it('should throw an error if req is invalid', function () {
      expect(function () {
        expensesUrlRouter.getRedirectUrl(null)
      }).to.throw(Error)
    })

    it('should throw an error if req.body is invalid', function () {
      expect(function () {
        expensesUrlRouter.getRedirectUrl({
          body: null
        })
      }).to.throw(Error)
    })

    it('should throw an error if req.params is invalid', function () {
      expect(function () {
        expensesUrlRouter.getRedirectUrl({
          params: null
        })
      }).to.throw(Error)
    })

    it('should throw an error if req.params.referenceId is invalid', function () {
      expect(function () {
        expensesUrlRouter.getRedirectUrl({
          params: {
            referenceId: null
          }
        })
      }).to.throw(Error)
    })

    it('should throw an error if req.params.claimId is invalid', function () {
      expect(function () {
        expensesUrlRouter.getRedirectUrl({
          params: {
            claimId: null
          }
        })
      }).to.throw(Error)
    })

    it('should throw an error if req.originalUrl is invalid', function () {
      expect(function () {
        expensesUrlRouter.getRedirectUrl({
          originalUrl: null
        })
      }).to.throw(Error)
    })

    it('should throw an error if req.query is invalid', function () {
      expect(function () {
        expensesUrlRouter.getRedirectUrl({
          query: null
        })
      }).to.throw(Error)
    })

    it('should return a url path to the summary page if no expenses are set', function () {
      var result = expensesUrlRouter.getRedirectUrl(NO_EXPENSE_REQUEST)
      expect(result).to.be.equal(SUMMARY_URL)
    })

    it('should return a url path built from the query parameters if they are set', function () {
      var result = expensesUrlRouter.getRedirectUrl(QUERY_PARAMATER_EXPENSE_REQUEST)
      expect(result).to.be.equal(`/apply/first-time/eligibility/${REFERENCE_ID}/claim/${CLAIM_ID}/bus`)
    })

    it('should return a url path if passed a valid request and add-another-journey was not set', function () {
      var result = expensesUrlRouter.getRedirectUrl(VALID_REQUEST)
      expect(result).to.be.equal(VALID_REQUEST_OUTPUT)
    })

    it('should return the originalUrl if passed a valid request with add-another-journey set', function () {
      VALID_REQUEST.body['add-another-journey'] = 'on'
      var result = expensesUrlRouter.getRedirectUrl(VALID_REQUEST)
      expect(result).to.be.equal(ORIGINAL_URL)
    })
  })
})
{'fraction_non_alphanumeric': 0.12330248768176902, 'fraction_numerical': 0.0018026679485638746, 'mean_word_length': 2.427512355848435, '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': '2364961', 'n_tokens_mistral': 2503, 'n_tokens_neox': 2436, 'n_words': 521}