v3: port static pages, make routes lib more flexible, share middlewares between v2 and v3, port v1, simplify server.js
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/* eslint-disable global-require */
|
||||
import {
|
||||
generateRes,
|
||||
generateReq,
|
||||
generateNext,
|
||||
} from '../../../../helpers/api-unit.helper';
|
||||
import cors from '../../../../../website/src/middlewares/api-v3/cors';
|
||||
|
||||
describe('cors middleware', () => {
|
||||
let res, req, next;
|
||||
|
||||
beforeEach(() => {
|
||||
req = generateReq();
|
||||
res = generateRes();
|
||||
next = generateNext();
|
||||
});
|
||||
|
||||
it('sets the correct headers', () => {
|
||||
cors(req, res, next);
|
||||
expect(res.set).to.have.been.calledWith({
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'OPTIONS,GET,POST,PUT,HEAD,DELETE',
|
||||
'Access-Control-Allow-Headers': 'Content-Type,Accept,Content-Encoding,X-Requested-With,x-api-user,x-api-key',
|
||||
});
|
||||
expect(res.sendStatus).to.not.have.been.called;
|
||||
expect(next).to.have.been.called.once;
|
||||
});
|
||||
|
||||
it('responds immediately if method is OPTIONS', () => {
|
||||
req.method = 'OPTIONS';
|
||||
cors(req, res, next);
|
||||
expect(res.set).to.have.been.calledWith({
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'OPTIONS,GET,POST,PUT,HEAD,DELETE',
|
||||
'Access-Control-Allow-Headers': 'Content-Type,Accept,Content-Encoding,X-Requested-With,x-api-user,x-api-key',
|
||||
});
|
||||
expect(res.sendStatus).to.have.been.calledWith(200);
|
||||
expect(next).to.not.have.been.called;
|
||||
});
|
||||
});
|
||||
@@ -119,6 +119,9 @@ describe('getUserLanguage', () => {
|
||||
context('request with session', () => {
|
||||
it('uses the user preferred language if avalaible', (done) => {
|
||||
sandbox.stub(User, 'findOne').returns({
|
||||
lean () {
|
||||
return this;
|
||||
},
|
||||
exec () {
|
||||
return Q.resolve({
|
||||
preferences: {
|
||||
|
||||
Reference in New Issue
Block a user