tests: add tests for res.location('back')

closes #3292
closes #3293
This commit is contained in:
Colin Richardson 2017-04-27 19:51:38 +01:00 committed by Douglas Christopher Wilson
parent 1b6e7004b7
commit a13938eed7

View File

@ -42,5 +42,63 @@ describe('res', function(){
.expect('Location', 'https://google.com?q=%A710')
.expect(200, done)
})
describe('when url is "back"', function () {
it('should set location from "Referer" header', function (done) {
var app = express()
app.use(function (req, res) {
res.location('back').end()
})
request(app)
.get('/')
.set('Referer', '/some/page.html')
.expect('Location', '/some/page.html')
.expect(200, done)
})
it('should set location from "Referrer" header', function (done) {
var app = express()
app.use(function (req, res) {
res.location('back').end()
})
request(app)
.get('/')
.set('Referrer', '/some/page.html')
.expect('Location', '/some/page.html')
.expect(200, done)
})
it('should prefer "Referrer" header', function (done) {
var app = express()
app.use(function (req, res) {
res.location('back').end()
})
request(app)
.get('/')
.set('Referer', '/some/page1.html')
.set('Referrer', '/some/page2.html')
.expect('Location', '/some/page2.html')
.expect(200, done)
})
it('should set the header to "/" without referrer', function (done) {
var app = express()
app.use(function (req, res) {
res.location('back').end()
})
request(app)
.get('/')
.expect('Location', '/')
.expect(200, done)
})
})
})
})