forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountryMappingSpec.js
37 lines (28 loc) · 1.11 KB
/
countryMappingSpec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* Copyright (c) 2014-2020 Bjoern Kimminich.
* SPDX-License-Identifier: MIT
*/
const sinon = require('sinon')
const chai = require('chai')
const sinonChai = require('sinon-chai')
const expect = chai.expect
chai.use(sinonChai)
describe('countryMapping', () => {
const countryMapping = require('../../routes/countryMapping')
beforeEach(() => {
this.req = {}
this.res = { send: sinon.spy(), status: sinon.stub().returns({ send: sinon.spy() }) }
})
it('should return configured country mappings', () => {
countryMapping({ get: sinon.stub().withArgs('ctf.countryMapping').returns('TEST') })(this.req, this.res)
expect(this.res.send).to.have.been.calledWith('TEST')
})
it('should return server error when configuration has no country mappings', () => {
countryMapping({ get: sinon.stub().withArgs('ctf.countryMapping').returns(null) })(this.req, this.res)
expect(this.res.status).to.have.been.calledWith(500)
})
it('should return server error for default configuration', () => {
countryMapping()(this.req, this.res)
expect(this.res.status).to.have.been.calledWith(500)
})
})