Skip to content

Commit

Permalink
refactor tests for ctx.back
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0w committed Dec 28, 2017
1 parent 903f243 commit bc41f47
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
35 changes: 35 additions & 0 deletions test/response/back.js
Original file line number Diff line number Diff line change
@@ -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, '/');
});
});
});
28 changes: 0 additions & 28 deletions test/response/redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit bc41f47

Please sign in to comment.