2015-06-10 22:18:31 +03:00
|
|
|
/*globals describe, beforeEach, afterEach, it*/
|
|
|
|
var sinon = require('sinon'),
|
2015-09-24 16:40:48 +03:00
|
|
|
should = require('should'),
|
2015-06-10 22:18:31 +03:00
|
|
|
uncapitalise = require('../../../server/middleware/uncapitalise');
|
2016-02-08 00:27:01 +03:00
|
|
|
require('should-sinon');
|
2015-06-10 22:18:31 +03:00
|
|
|
|
2015-09-24 16:40:48 +03:00
|
|
|
should.equal(true, true);
|
|
|
|
|
2015-06-10 22:18:31 +03:00
|
|
|
describe('Middleware: uncapitalise', function () {
|
|
|
|
var sandbox,
|
|
|
|
res,
|
|
|
|
req,
|
|
|
|
next;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
|
|
|
|
res = sinon.spy();
|
|
|
|
req = sinon.spy();
|
|
|
|
next = sinon.spy();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('A signup or reset request', function () {
|
|
|
|
it('does nothing if there are no capital letters', function (done) {
|
|
|
|
req.path = '/ghost/signup';
|
|
|
|
uncapitalise(req, res, next);
|
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
next.should.be.calledOnce();
|
2015-06-10 22:18:31 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects to the lower case slug if there are capital letters', function (done) {
|
|
|
|
req.path = '/ghost/SignUP';
|
|
|
|
req.url = 'http://localhost' + req.path;
|
|
|
|
res = {
|
|
|
|
redirect: sinon.spy(),
|
|
|
|
set: sinon.spy()
|
|
|
|
};
|
|
|
|
|
|
|
|
uncapitalise(req, res, next);
|
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
next.should.not.be.called();
|
|
|
|
res.redirect.should.be.calledOnce();
|
|
|
|
res.redirect.calledWith(301, 'http://localhost/ghost/signup').should.be.true();
|
2015-06-10 22:18:31 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('An API request', function () {
|
|
|
|
it('does nothing if there are no capital letters', function (done) {
|
|
|
|
req.path = '/ghost/api/v0.1';
|
|
|
|
uncapitalise(req, res, next);
|
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
next.should.be.calledOnce();
|
2015-06-10 22:18:31 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects to the lower case slug if there are capital letters', function (done) {
|
|
|
|
req.path = '/ghost/api/v0.1/ASDfJ';
|
|
|
|
req.url = 'http://localhost' + req.path;
|
|
|
|
res = {
|
|
|
|
redirect: sinon.spy(),
|
|
|
|
set: sinon.spy()
|
|
|
|
};
|
|
|
|
|
|
|
|
uncapitalise(req, res, next);
|
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
next.should.not.be.called();
|
|
|
|
res.redirect.should.be.calledOnce();
|
|
|
|
res.redirect.calledWith(301, 'http://localhost/ghost/api/v0.1/asdfj').should.be.true();
|
2015-06-10 22:18:31 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Any other request', function () {
|
|
|
|
it('does nothing if there are no capital letters', function (done) {
|
|
|
|
req.path = '/this-is-my-blog-post';
|
|
|
|
uncapitalise(req, res, next);
|
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
next.should.be.calledOnce();
|
2015-06-10 22:18:31 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects to the lower case slug if there are capital letters', function (done) {
|
|
|
|
req.path = '/THis-iS-my-BLOg-poSt';
|
|
|
|
req.url = 'http://localhost' + req.path;
|
|
|
|
res = {
|
|
|
|
redirect: sinon.spy(),
|
|
|
|
set: sinon.spy()
|
|
|
|
};
|
|
|
|
|
|
|
|
uncapitalise(req, res, next);
|
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
next.should.not.be.called();
|
|
|
|
res.redirect.should.be.calledOnce();
|
|
|
|
res.redirect.calledWith(301, 'http://localhost/this-is-my-blog-post').should.be.true();
|
2015-06-10 22:18:31 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|