Enable downloads for all

This commit is contained in:
Fergal Moran
2018-10-26 21:23:25 +01:00
parent aeda96acc8
commit f3b40713ae
29 changed files with 1308 additions and 29 deletions

10
server/api/thing/index.js Normal file
View File

@@ -0,0 +1,10 @@
'use strict';
var express = require('express');
var controller = require('./thing.controller');
var router = express.Router();
router.get('/', controller.index);
module.exports = router;

View File

@@ -0,0 +1,35 @@
'use strict';
var proxyquire = require('proxyquire').noPreserveCache();
var thingCtrlStub = {
index: 'thingCtrl.index'
};
var routerStub = {
get: sinon.spy()
};
// require the index with our stubbed out modules
var thingIndex = proxyquire('./index.js', {
express: {
Router() {
return routerStub;
}
},
'./thing.controller': thingCtrlStub
});
describe('Thing API Router:', function() {
it('should return an express router instance', function() {
expect(thingIndex).to.equal(routerStub);
});
describe('GET /api/things', function() {
it('should route to thing.controller.index', function() {
expect(routerStub.get
.withArgs('/', 'thingCtrl.index')
).to.have.been.calledOnce;
});
});
});

View File

@@ -0,0 +1,11 @@
/**
* Using Rails-like standard naming convention for endpoints.
* GET /api/things -> index
*/
'use strict';
// Gets a list of Things
export function index(req, res) {
res.json([]);
}

View File

@@ -0,0 +1,28 @@
'use strict';
var app = require('../..');
import request from 'supertest';
describe('Thing API:', function() {
describe('GET /api/things', function() {
var things;
beforeEach(function(done) {
request(app)
.get('/api/things')
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if(err) {
return done(err);
}
things = res.body;
done();
});
});
it('should respond with JSON array', function() {
expect(things).to.be.instanceOf(Array);
});
});
});