From bc41f476ff72e2feff3cad47439ec57a2fcee1bd Mon Sep 17 00:00:00 2001 From: Martin fl0w Iwanowski Date: Thu, 28 Dec 2017 10:40:11 +0100 Subject: [PATCH] refactor tests for ctx.back --- test/response/back.js | 35 +++++++++++++++++++++++++++++++++++ test/response/redirect.js | 28 ---------------------------- 2 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 test/response/back.js 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();