Setting up mock server (#6)

This commit is contained in:
Matthew Dillon 2015-02-28 09:31:30 -09:00
parent 6c58af7945
commit 258ce2269f
9 changed files with 545 additions and 5 deletions

View file

@ -0,0 +1,77 @@
module.exports = function(app) {
var express = require('express');
var characteristicsRouter = express.Router();
var CHARACTERISTICS = [
{
id: 1,
characteristicName: "Char01",
characteristicTypeId: 1,
createdAt: "2015-01-27T10:19:25.156836Z",
updatedAt: "2015-01-27T10:19:25.156836Z",
deletedAt: null,
measurements: [1,6]
},
{
id: 2,
characteristicName: "Char02",
characteristicTypeId: 1,
createdAt: "2015-01-27T10:19:25.156836Z",
updatedAt: "2015-01-27T10:19:25.156836Z",
deletedAt: null,
measurements: [2,7]
},
{
id: 3,
characteristicName: "Char03",
characteristicTypeId: 1,
createdAt: "2015-01-27T10:19:25.156836Z",
updatedAt: "2015-01-27T10:19:25.156836Z",
deletedAt: null,
measurements: [3,8]
},
{
id: 4,
characteristicName: "Char04",
characteristicTypeId: 1,
createdAt: "2015-01-27T10:19:25.156836Z",
updatedAt: "2015-01-27T10:19:25.156836Z",
deletedAt: null,
measurements: [4,5,9,10]
}
]
characteristicsRouter.get('/', function(req, res) {
res.send({
'characteristics': CHARACTERISTICS
});
});
characteristicsRouter.post('/', function(req, res) {
res.status(201).end();
});
characteristicsRouter.get('/:id', function(req, res) {
var characteristics = CHARACTERISTICS.filter(function(c) {
return req.params.id.indexOf(c.id.toString()) > -1;
});
res.send({
'characteristic': characteristics[0]
});
});
characteristicsRouter.put('/:id', function(req, res) {
var characteristics = CHARACTERISTICS.filter(function(c) {
return req.params.id.indexOf(c.id.toString()) > -1;
});
res.send({
'characteristic': characteristics[0]
});
});
characteristicsRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
app.use('/api/characteristics', characteristicsRouter);
};

65
server/mocks/genera.js Normal file
View file

@ -0,0 +1,65 @@
module.exports = function(app) {
var express = require('express');
var generaRouter = express.Router();
var GENERA = [
{
id: 1,
genusName: "Genus One",
species: [1,2],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
},
{
id: 2,
genusName: "Genus Two",
species: [3],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
},
{
id: 3,
genusName: "Genus Three",
species: [4],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
}
];
generaRouter.get('/', function(req, res) {
res.send({
'genera': GENERA
});
});
generaRouter.post('/', function(req, res) {
res.status(201).end();
});
generaRouter.get('/:id', function(req, res) {
var genus = GENERA.filter(function(g) {
return req.params.id.indexOf(g.id.toString()) > -1;
});
res.send({
'genus': genus[0]
});
});
generaRouter.put('/:id', function(req, res) {
var genus = GENERA.filter(function(g) {
return req.params.id.indexOf(g.id.toString()) > -1;
});
res.send({
'genus': genus[0]
});
});
generaRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
app.use('/api/genera', generaRouter);
};

View file

@ -0,0 +1,181 @@
module.exports = function(app) {
var express = require('express');
var measurementsRouter = express.Router();
var MEASUREMENTS = [
{
id: 1,
strain: 1,
characteristic: 1,
textMeasurementTypeId: 1,
txtValue: null,
numValue: null,
confidenceInterval: null,
unitTypeId: null,
notes: null,
testMethodId: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z"
},
{
id: 2,
strain: 1,
characteristic: 2,
textMeasurementTypeId: 1,
txtValue: null,
numValue: null,
confidenceInterval: null,
unitTypeId: null,
notes: null,
testMethodId: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z"
},
{
id: 3,
strain: 1,
characteristic: 3,
textMeasurementTypeId: null,
txtValue: "text value",
numValue: null,
confidenceInterval: null,
unitTypeId: null,
notes: "some notes",
testMethodId: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z"
},
{
id: 4,
strain: 1,
characteristic: 4,
textMeasurementTypeId: null,
txtValue: null,
numValue: 123.4,
confidenceInterval: null,
unitTypeId: 1,
notes: null,
testMethodId: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z"
},
{
id: 5,
strain: 1,
characteristic: 4,
textMeasurementTypeId: null,
txtValue: null,
numValue: 567.8,
confidenceInterval: 0.2,
unitTypeId: 1,
notes: null,
testMethodId: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z"
},
{
id: 6,
strain: 2,
characteristic: 1,
textMeasurementTypeId: 1,
txtValue: null,
numValue: null,
confidenceInterval: null,
unitTypeId: null,
notes: null,
testMethodId: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z"
},
{
id: 7,
strain: 2,
characteristic: 2,
textMeasurementTypeId: 1,
txtValue: null,
numValue: null,
confidenceInterval: null,
unitTypeId: null,
notes: null,
testMethodId: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z"
},
{
id: 8,
strain: 2,
characteristic: 3,
textMeasurementTypeId: null,
txtValue: "text value",
numValue: null,
confidenceInterval: null,
unitTypeId: null,
notes: "some notes",
testMethodId: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z"
},
{
id: 9,
strain: 2,
characteristic: 4,
textMeasurementTypeId: null,
txtValue: null,
numValue: 123.4,
confidenceInterval: null,
unitTypeId: 1,
notes: null,
testMethodId: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z"
},
{
id: 10,
strain: 2,
characteristic: 4,
textMeasurementTypeId: null,
txtValue: null,
numValue: 567.8,
confidenceInterval: 0.2,
unitTypeId: 1,
notes: null,
testMethodId: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z"
}
]
measurementsRouter.get('/', function(req, res) {
res.send({
'measurements': MEASUREMENTS
});
});
measurementsRouter.post('/', function(req, res) {
res.status(201).end();
});
measurementsRouter.get('/:id', function(req, res) {
var measurements = MEASUREMENTS.filter(function(m) {
return req.params.id.indexOf(m.id.toString()) > -1;
});
res.send({
'measurement': measurements[0]
});
});
measurementsRouter.put('/:id', function(req, res) {
var measurements = MEASUREMENTS.filter(function(m) {
return req.params.id.indexOf(m.id.toString()) > -1;
});
res.send({
'measurement': measurements[0]
});
});
measurementsRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
app.use('/api/measurements', measurementsRouter);
};

77
server/mocks/species.js Normal file
View file

@ -0,0 +1,77 @@
module.exports = function(app) {
var express = require('express');
var speciesRouter = express.Router();
var SPECIES = [
{
id: 1,
genus: 1,
speciesName: "Species One",
strains: [1],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
},
{
id: 2,
genus: 1,
speciesName: "Species Two",
strains: [2],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
},
{
id: 3,
genus: 2,
speciesName: "Species Three",
strains: [3],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
},
{
id: 4,
genus: 3,
speciesName: "Species Four",
strains: [4],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
}
];
speciesRouter.get('/', function(req, res) {
res.send({
'species': SPECIES
});
});
speciesRouter.post('/', function(req, res) {
res.status(201).end();
});
speciesRouter.get('/:id', function(req, res) {
var species = SPECIES.filter(function(s) {
return req.params.id.indexOf(s.id.toString()) > -1;
});
res.send({
'species': species[0]
});
});
speciesRouter.put('/:id', function(req, res) {
var species = SPECIES.filter(function(s) {
return req.params.id.indexOf(s.id.toString()) > -1;
});
res.send({
'species': species[0]
});
});
speciesRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
app.use('/api/species', speciesRouter);
};

97
server/mocks/strains.js Normal file
View file

@ -0,0 +1,97 @@
module.exports = function(app) {
var express = require('express');
var strainsRouter = express.Router();
var STRAINS = [
{
id: 1,
species: 1,
strainName: "Strain One",
strainType: "Test Type",
etymology: "Test Etymology",
accessionBanks: "Test Accession",
genbankEmblDdb: "Test Genbank",
isolatedFrom: null,
measurements: [1,2,3,4,5],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
},
{
id: 2,
species: 2,
strainName: "Strain Two",
strainType: "Test Type",
etymology: "Test Etymology",
accessionBanks: "Test Accession",
genbankEmblDdb: "Test Genbank",
isolatedFrom: null,
measurements: [6,7,8,9,10],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
},
{
id: 3,
species: 3,
strainName: "Strain Three",
strainType: "Test Type",
etymology: "Test Etymology",
accessionBanks: "Test Accession",
genbankEmblDdb: "Test Genbank",
isolatedFrom: null,
measurements: [],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
},
{
id: 4,
species: 4,
strainName: "Strain Four",
strainType: "Test Type",
etymology: "Test Etymology",
accessionBanks: "Test Accession",
genbankEmblDdb: "Test Genbank",
isolatedFrom: null,
measurements: [],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
}
];
strainsRouter.get('/', function(req, res) {
res.send({
'strains': STRAINS
});
});
strainsRouter.post('/', function(req, res) {
res.status(201).end();
});
strainsRouter.get('/:id', function(req, res) {
var strains = STRAINS.filter(function(s) {
return req.params.id.indexOf(s.id.toString()) > -1;
});
res.send({
'strain': strains[0]
});
});
strainsRouter.put('/:id', function(req, res) {
var strains = STRAINS.filter(function(s) {
return req.params.id.indexOf(s.id.toString()) > -1;
});
res.send({
'strain': strains[0]
});
});
strainsRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
app.use('/api/strains', strainsRouter);
};