mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
Fixed CORS middleware unit test
refs https://github.com/TryGhost/Toolbox/issues/461 - The unit test was never using the "OPTIONS" request method, which did not actually trigger the full logic of the "cors" module used under the hood. - Using the correct request method triggers all the right pathways and tests the state that's closer to the real world - for example the response does get "ended" instead of calling the "next" middleware.
This commit is contained in:
parent
c5ad1b0531
commit
9b2e36e4fb
@ -13,6 +13,7 @@ describe('cors', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
req = {
|
||||
method: 'OPTIONS',
|
||||
headers: {
|
||||
origin: null
|
||||
},
|
||||
@ -26,7 +27,8 @@ describe('cors', function () {
|
||||
vary: sinon.spy(),
|
||||
setHeader: function (h, v) {
|
||||
this.headers[h] = v;
|
||||
}
|
||||
},
|
||||
end: sinon.spy()
|
||||
};
|
||||
|
||||
next = sinon.spy();
|
||||
@ -58,7 +60,7 @@ describe('cors', function () {
|
||||
|
||||
cors(req, res, next);
|
||||
|
||||
next.called.should.be.true();
|
||||
res.end.called.should.be.true();
|
||||
res.headers['Access-Control-Allow-Origin'].should.equal(origin);
|
||||
|
||||
done();
|
||||
@ -73,7 +75,7 @@ describe('cors', function () {
|
||||
|
||||
cors(req, res, next);
|
||||
|
||||
next.called.should.be.true();
|
||||
res.end.called.should.be.true();
|
||||
res.headers['Access-Control-Allow-Origin'].should.equal(origin);
|
||||
|
||||
done();
|
||||
@ -105,7 +107,7 @@ describe('cors', function () {
|
||||
|
||||
cors(req, res, next);
|
||||
|
||||
next.called.should.be.true();
|
||||
res.end.called.should.be.true();
|
||||
res.headers['Access-Control-Allow-Origin'].should.equal(origin);
|
||||
|
||||
done();
|
||||
@ -127,7 +129,7 @@ describe('cors', function () {
|
||||
|
||||
cors(req, res, next);
|
||||
|
||||
next.called.should.be.true();
|
||||
res.end.called.should.be.true();
|
||||
res.headers['Access-Control-Allow-Origin'].should.equal(origin);
|
||||
|
||||
done();
|
||||
|
Loading…
Reference in New Issue
Block a user