diff --git a/test/response/back.js b/test/response/back.js new file mode 100644 index 000000000..7348453bb --- /dev/null +++ b/test/response/back.js @@ -0,0 +1,35 @@ + +'use strict'; + +const assert = require('assert'); +const context = require('../helpers/context'); + +describe('ctx.back([alt])', () => { + describe('with "back"', () => { + it('should redirect to Referrer', () => { + const ctx = context(); + ctx.req.headers.referrer = '/login'; + ctx.back(); + assert.equal(ctx.response.header.location, '/login'); + }); + + it('should redirect to Referer', () => { + const ctx = context(); + ctx.req.headers.referer = '/login'; + ctx.back(); + assert.equal(ctx.response.header.location, '/login'); + }); + + it('should default to alt', () => { + const ctx = context(); + ctx.back('/index.html'); + assert.equal(ctx.response.header.location, '/index.html'); + }); + + it('should default redirect to /', () => { + const ctx = context(); + ctx.back(); + assert.equal(ctx.response.header.location, '/'); + }); + }); +}); diff --git a/test/response/redirect.js b/test/response/redirect.js index cadd2884a..ccc0b3f0b 100644 --- a/test/response/redirect.js +++ b/test/response/redirect.js @@ -12,34 +12,6 @@ describe('ctx.redirect(url)', () => { assert.equal(ctx.status, 302); }); - describe('with "back"', () => { - it('should redirect to Referrer', () => { - const ctx = context(); - ctx.req.headers.referrer = '/login'; - ctx.back(); - assert.equal(ctx.response.header.location, '/login'); - }); - - it('should redirect to Referer', () => { - const ctx = context(); - ctx.req.headers.referer = '/login'; - ctx.back(); - assert.equal(ctx.response.header.location, '/login'); - }); - - it('should default to alt', () => { - const ctx = context(); - ctx.back('/index.html'); - assert.equal(ctx.response.header.location, '/index.html'); - }); - - it('should default redirect to /', () => { - const ctx = context(); - ctx.back(); - assert.equal(ctx.response.header.location, '/'); - }); - }); - describe('when html is accepted', () => { it('should respond with html', () => { const ctx = context();