Ghost/core/test/unit/middleware/uncapitalise_spec.js
Hannah Wolfe e4a1797085 Remove should-sinon dependency
no issue

- removes should-sinon dependency from package.json
- rewrites all usages of should-sinon to use normal should assertions

Unfortunately, should-sinon has very minimal documentation  and therefore it is hard to discern what is considered a correctly-written assertion:
- in some cases, refactoring to use should-sinon causes false positives
- in other cases, assertions that work written in the normal way fail when written using should-sinon (e.g. getters, combos with rewire)
The additional overhead created by these issues outweigh any benefit from the easier-to-read assertions
2016-03-14 16:52:22 +00:00

104 lines
3.1 KiB
JavaScript

/*globals describe, beforeEach, afterEach, it*/
var sinon = require('sinon'),
should = require('should'),
uncapitalise = require('../../../server/middleware/uncapitalise');
should.equal(true, true);
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);
next.calledOnce.should.be.true();
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);
next.called.should.be.false();
res.redirect.calledOnce.should.be.true();
res.redirect.calledWith(301, 'http://localhost/ghost/signup').should.be.true();
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);
next.calledOnce.should.be.true();
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);
next.called.should.be.false();
res.redirect.calledOnce.should.be.true();
res.redirect.calledWith(301, 'http://localhost/ghost/api/v0.1/asdfj').should.be.true();
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);
next.calledOnce.should.be.true();
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);
next.called.should.be.false();
res.redirect.calledOnce.should.be.true();
res.redirect.calledWith(301, 'http://localhost/this-is-my-blog-post').should.be.true();
done();
});
});
});