Scrubbing out test server --- going to use golang dev server

This commit is contained in:
Matthew Dillon 2015-06-28 19:58:42 -08:00
parent 5914360cc6
commit de15fd0a30
11 changed files with 11 additions and 872 deletions

View file

@ -41,30 +41,26 @@ module.exports = function(environment) {
}, },
}; };
var apiURL;
if (environment === 'development') { if (environment === 'development') {
ENV['simple-auth']['crossOriginWhitelist'] = ['http://127.0.0.1:4200']; apiURL = 'http://127.0.0.1:8901';
ENV['simple-auth-token']['serverTokenEndpoint'] = '/api/authenticate';
ENV.apiURL = 'http://127.0.0.1:4200';
ENV.contentSecurityPolicy['connect-src'] = "'self' http://127.0.0.1:4200";
} }
if (environment === 'test') { if (environment === 'test') {
ENV['simple-auth']['crossOriginWhitelist'] = ['https://bactdb-test.herokuapp.com']; apiURL = 'https://bactdb-test.herokuapp.com';
ENV['simple-auth-token']['serverTokenEndpoint'] = 'https://bactdb-test.herokuapp.com/api/authenticate';
ENV.apiURL = 'https://bactdb-test.herokuapp.com';
ENV.contentSecurityPolicy['connect-src'] = "'self' https://bactdb-test.herokuapp.com";
// keep test console output quieter
ENV.APP.LOG_ACTIVE_GENERATION = false; ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false; ENV.APP.LOG_VIEW_LOOKUPS = false;
} }
if (environment === 'production') { if (environment === 'production') {
ENV['simple-auth']['crossOriginWhitelist'] = ['https://bactdb.herokuapp.com']; apiURL = 'https://bactdb.herokuapp.com';
ENV['simple-auth-token']['serverTokenEndpoint'] = 'https://bactdb.herokuapp.com/api/authenticate';
ENV.apiURL = 'https://bactdb.herokuapp.com';
ENV.contentSecurityPolicy['connect-src'] = "'self' https://bactdb.herokuapp.com";
} }
ENV['simple-auth']['crossOriginWhitelist'] = [apiURL];
ENV['simple-auth-token']['serverTokenEndpoint'] = apiURL + '/api/authenticate';
ENV.apiURL = apiURL;
ENV.contentSecurityPolicy['connect-src'] = "'self' " + apiURL;
return ENV; return ENV;
}; };

View file

@ -19,7 +19,6 @@
"author": "", "author": "",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"body-parser": "^1.12.2",
"broccoli-asset-rev": "^2.0.2", "broccoli-asset-rev": "^2.0.2",
"ember-cli": "0.2.7", "ember-cli": "0.2.7",
"ember-cli-app-version": "0.3.3", "ember-cli-app-version": "0.3.3",
@ -40,9 +39,6 @@
"ember-export-application-global": "^1.0.2", "ember-export-application-global": "^1.0.2",
"ember-select-2": "1.3.0", "ember-select-2": "1.3.0",
"ember-table": "0.5.0", "ember-table": "0.5.0",
"express": "^4.12.4", "glob": "^4.5.3"
"glob": "^4.5.3",
"jsonwebtoken": "^5.0.0",
"morgan": "^1.6.0"
} }
} }

View file

@ -1,3 +0,0 @@
{
"node": true
}

View file

@ -1,42 +0,0 @@
// To use it create some files under `mocks/`
// e.g. `server/mocks/ember-hamsters.js`
//
// module.exports = function(app) {
// app.get('/ember-hamsters', function(req, res) {
// res.send('hello');
// });
// };
// http://stackoverflow.com/q/11001817
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
// intercept OPTIONS method
if ('OPTIONS' == req.method) {
res.sendStatus(200);
}
else {
next();
}
};
module.exports = function(app) {
var globSync = require('glob').sync;
var mocks = globSync('./mocks/**/*.js', { cwd: __dirname }).map(require);
var proxies = globSync('./proxies/**/*.js', { cwd: __dirname }).map(require);
// Log proxy requests
var morgan = require('morgan');
app.use(morgan('dev'));
app.use(allowCrossDomain);
// Parse json
var bodyParser = require('body-parser');
app.use(bodyParser.json());
mocks.forEach(function(route) { route(app); });
proxies.forEach(function(route) { route(app); });
};

View file

@ -1,66 +0,0 @@
module.exports = function(app) {
var express = require('express');
var jwt = require('jsonwebtoken');
var authenticateRouter = express.Router();
var USERS = [
{
id: 1,
email: 'testA',
name: 'Test Admin User',
role: 'A',
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null
},
{
id: 2,
email: 'testR',
name: 'Test Read User',
role: 'R',
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null
},
{
id: 3,
email: 'testW',
name: 'Test Write User',
role: 'W',
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null
}
]
authenticateRouter.post('/', function(req, res) {
// wait for a bit to simulate cold boot of heroku api
var ms = 1000 + new Date().getTime();
while (new Date() < ms){}
if ((req.body.email === 'testA' || req.body.email === 'testR' || req.body.email === 'testW' )
&& req.body.password === 'test') {
var user = USERS.filter(function(u) {
if (u.email == req.body.email) {
return u;
}
})[0];
var token = jwt.sign({
'name': user.name,
'role': user.role
}, 'secret',
{
expiresInMinutes: 60,
issuer: 'bactdb',
subject: user.id,
});
res.send({
'token': token
});
} else {
res.status(401).send({'error':'Invalid username or password'});
}
});
app.use('/api/authenticate', authenticateRouter);
};

View file

@ -1,84 +0,0 @@
module.exports = function(app) {
var express = require('express');
var characteristicTypesRouter = express.Router();
var CHARACTERISTIC_TYPES = [
{
id: 1,
characteristicTypeName: 'Type 1',
characteristics: [1,4],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 1,
updatedBy: 1,
deletedBy: null,
sortOrder: 1,
},
{
id: 2,
characteristicTypeName: 'Type 2',
characteristics: [2,5],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 1,
updatedBy: 1,
deletedBy: null,
sortOrder: 2,
},
{
id: 3,
characteristicTypeName: 'Type 3',
characteristics: [3],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 1,
updatedBy: 1,
deletedBy: null,
sortOrder: 3,
},
]
characteristicTypesRouter.get('/', function(req, res) {
var characteristics;
if (req.query.ids) {
characteristic_types = CHARACTERISTIC_TYPES.filter(function(c) {
return req.query.ids.indexOf(c.id.toString()) > -1;
});
} else {
characteristic_types = CHARACTERISTIC_TYPES;
}
res.send({
'characteristicTypes': characteristic_types
});
});
characteristicTypesRouter.post('/', function(req, res) {
res.status(201).end();
});
characteristicTypesRouter.get('/:id', function(req, res) {
var characteristic_type = CHARACTERISTIC_TYPES.filter(function(c) {
return c.id == req.params.id;
});
res.send({
'characteristicType': characteristic_type
});
});
characteristicTypesRouter.put('/:id', function(req, res) {
res.send({
'characteristicTypes': {
id: req.params.id
}
});
});
characteristicTypesRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
app.use('/api/hymenobacter/characteristicTypes', characteristicTypesRouter);
};

View file

@ -1,118 +0,0 @@
module.exports = function(app) {
var express = require('express');
var characteristicsRouter = express.Router();
var CHARACTERISTICS = [
{
id: 1,
characteristicName: 'α-fucosidase (API ZYM)',
characteristicType: 1,
strains: [1,2],
measurements: [1,6],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 1,
updatedBy: 1,
deletedBy: null,
sortOrder: 1,
},
{
id: 2,
characteristicName: 'α-glucosidase',
characteristicType: 2,
strains: [1,2],
measurements: [2,7],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 1,
updatedBy: 1,
deletedBy: null,
sortOrder: 2,
},
{
id: 3,
characteristicName: 'Chloramphenicol',
characteristicType: 3,
strains: [1,2],
measurements: [3,8],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 1,
updatedBy: 1,
deletedBy: null,
sortOrder: 3,
},
{
id: 4,
characteristicName: 'Bacitracin',
characteristicType: 1,
strains: [1,2],
measurements: [4,9],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 1,
updatedBy: 1,
deletedBy: null,
sortOrder: 4,
},
{
id: 5,
characteristicName: 'Indole',
characteristicType: 2,
strains: [1,2],
measurements: [5,10],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 1,
updatedBy: 1,
deletedBy: null,
sortOrder: 5,
}
]
characteristicsRouter.get('/', function(req, res) {
var characteristics;
if (req.query.ids) {
characteristics = CHARACTERISTICS.filter(function(c) {
return req.query.ids.indexOf(c.id.toString()) > -1;
});
} else {
characteristics = CHARACTERISTICS;
}
res.send({
'characteristics': characteristics
});
});
characteristicsRouter.post('/', function(req, res) {
res.status(201).end();
});
characteristicsRouter.get('/:id', function(req, res) {
var characteristic = CHARACTERISTICS.filter(function(c) {
return c.id == req.params.id;
});
res.send({
'characteristic': characteristic
});
});
characteristicsRouter.put('/:id', function(req, res) {
res.send({
'characteristics': {
id: req.params.id
}
});
});
characteristicsRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
app.use('/api/hymenobacter/characteristics', characteristicsRouter);
};

View file

@ -1,209 +0,0 @@
module.exports = function(app) {
var express = require('express');
var measurementsRouter = express.Router();
var MEASUREMENTS = [
{
id: 1,
strain: 1,
characteristic: 1,
textMeasurementType: 'Meas. Type 1',
txtValue: null,
numValue: null,
confidenceInterval: null,
unitType: null,
notes: null,
testMethod: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
createdBy: 1,
updatedBy: 1
},
{
id: 2,
strain: 1,
characteristic: 2,
textMeasurementType: 'Meas. Type 1',
txtValue: null,
numValue: null,
confidenceInterval: null,
unitType: null,
notes: null,
testMethod: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
createdBy: 1,
updatedBy: 1
},
{
id: 3,
strain: 1,
characteristic: 3,
textMeasurementType: null,
txtValue: "text value",
numValue: null,
confidenceInterval: null,
unitType: null,
notes: "some notes",
testMethod: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
createdBy: 1,
updatedBy: 1
},
{
id: 4,
strain: 1,
characteristic: 4,
textMeasurementType: null,
txtValue: null,
numValue: 123.4,
confidenceInterval: null,
unitType: 'Unit 1',
notes: null,
testMethod: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
createdBy: 1,
updatedBy: 1
},
{
id: 5,
strain: 1,
characteristic: 5,
textMeasurementType: null,
txtValue: null,
numValue: 567.8,
confidenceInterval: 0.2,
unitType: 'Unit 1',
notes: null,
testMethod: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
createdBy: 1,
updatedBy: 1
},
{
id: 6,
strain: 2,
characteristic: 1,
textMeasurementType: 'Meas. Type 1',
txtValue: null,
numValue: null,
confidenceInterval: null,
unitType: null,
notes: null,
testMethod: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
createdBy: 1,
updatedBy: 1
},
{
id: 7,
strain: 2,
characteristic: 2,
textMeasurementType: 'Meas. Type 1',
txtValue: null,
numValue: null,
confidenceInterval: null,
unitType: null,
notes: null,
testMethod: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
createdBy: 1,
updatedBy: 1
},
{
id: 8,
strain: 2,
characteristic: 3,
textMeasurementType: null,
txtValue: "text value",
numValue: null,
confidenceInterval: null,
unitType: null,
notes: "some notes",
testMethod: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
createdBy: 1,
updatedBy: 1
},
{
id: 9,
strain: 2,
characteristic: 4,
textMeasurementType: null,
txtValue: null,
numValue: 123.4,
confidenceInterval: null,
unitType: 'Unit 1',
notes: null,
testMethod: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
createdBy: 1,
updatedBy: 1
},
{
id: 10,
strain: 2,
characteristic: 5,
textMeasurementType: null,
txtValue: null,
numValue: 567.8,
confidenceInterval: 0.2,
unitType: 'Unit 1',
notes: null,
testMethod: null,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
createdBy: 1,
updatedBy: 1
}
]
measurementsRouter.get('/', function(req, res) {
var measurements;
if (req.query.ids) {
measurements = MEASUREMENTS.filter(function(m) {
return req.query.ids.indexOf(m.id.toString()) > -1;
});
} else {
measurements = MEASUREMENTS;
}
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 m.id == req.params.id;
});
res.send({
'measurement': measurements
});
});
measurementsRouter.put('/:id', function(req, res) {
var measurements = MEASUREMENTS.filter(function(m) {
return m.id == req.params.id;
});
res.send({
'measurement': measurements[0]
});
});
measurementsRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
app.use('/api/hymenobacter/measurements', measurementsRouter);
};

View file

@ -1,109 +0,0 @@
module.exports = function(app) {
var express = require('express');
var speciesRouter = express.Router();
var SPECIES = [
{
id: 1,
genusName: "Hymenobacter",
speciesName: "One",
typeSpecies: true,
etymology: "Test Etymology",
strains: [1,2],
totalStrains: 1,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 1,
updatedBy: 1,
deletedBy: null,
sortOrder: 1,
},
{
id: 2,
genusName: "Hymenobacter",
speciesName: "Two",
typeSpecies: true,
etymology: "Test Etymology",
strains: [3],
totalStrains: 1,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 1,
updatedBy: 1,
deletedBy: null,
sortOrder: 2,
},
{
id: 3,
genusName: "Hymenobacter",
speciesName: "Three",
typeSpecies: true,
etymology: "Test Etymology",
strains: [4],
totalStrains: 1,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 1,
updatedBy: 1,
deletedBy: null,
sortOrder: 3,
},
{
id: 4,
genusName: "Hymenobacter",
speciesName: "Four",
typeSpecies: true,
etymology: "Test Etymology",
strains: [4],
totalStrains: 1,
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 1,
updatedBy: 1,
deletedBy: null,
sortOrder: 4,
}
];
speciesRouter.get('/', function(req, res) {
var species;
if (req.query.ids) {
species = SPECIES.filter(function(s) {
return req.query.ids.indexOf(s.id.toString()) > -1;
});
} else {
species = SPECIES;
}
res.send({
'species': species
});
});
speciesRouter.post('/', function(req, res) {
req.body.species.id = Math.max.apply(Math, SPECIES.map(function(o){return o.id;})) + 1;
res.status(201).send(req.body);
});
speciesRouter.get('/:id', function(req, res) {
var species = SPECIES.filter(function(s) {
return s.id == req.params.id;
});
res.send({
'species': species[0]
});
});
speciesRouter.put('/:id', function(req, res) {
res.send(req.body);
});
speciesRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
app.use('/api/hymenobacter/species', speciesRouter);
};

View file

@ -1,138 +0,0 @@
module.exports = function(app) {
var express = require('express');
var strainsRouter = express.Router();
var STRAINS = [
{
id: 1,
species: 1,
strainName: "ABC",
typeStrain: true,
accessionNumbers: "Test Accession",
genbank: "Test Genbank",
wholeGenomeSequence: "Seq123",
isolatedFrom: "Location 1",
measurements: [1,2,3,4,5],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 1,
updatedBy: 1,
deletedBy: null,
totalMeasurements: 5,
notes: "Test notes",
sortOrder: 1,
},
{
id: 2,
species: 1,
strainName: "XYZ",
typeStrain: false,
accessionNumbers: "Test Accession",
genbank: "Test Genbank",
wholeGenomeSequence: null,
isolatedFrom: "Location 2",
measurements: [6,7,8,9,10],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 3,
updatedBy: 3,
deletedBy: null,
totalMeasurements: 5,
notes: "Test notes",
sortOrder: 2,
},
{
id: 3,
species: 2,
strainName: "QRS",
typeStrain: true,
accessionNumbers: "Test Accession",
genbank: "Test Genbank",
wholeGenomeSequence: "Seq123",
isolatedFrom: "Location 1",
measurements: [],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 1,
updatedBy: 1,
deletedBy: null,
totalMeasurements: 0,
notes: "Test notes",
sortOrder: 3,
},
{
id: 4,
species: 3,
strainName: "LMN",
typeStrain: true,
accessionNumbers: "Test Accession",
genbank: "Test Genbank",
wholeGenomeSequence: "Seq123",
isolatedFrom: "Location 2",
measurements: [],
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null,
createdBy: 3,
updatedBy: 3,
deletedBy: null,
totalMeasurements: 0,
notes: "Test notes",
sortOrder: 4.
}
];
strainsRouter.get('/', function(req, res) {
var strains;
if (req.query.ids) {
strains = STRAINS.filter(function(s) {
return req.query.ids.indexOf(s.id.toString()) > -1;
});
} else {
strains = STRAINS;
}
res.send({
'strains': strains
});
});
strainsRouter.post('/', function(req, res) {
req.body.strain.id = Math.max.apply(Math, STRAINS.map(function(o){return o.id;})) + 1;
res.status(201).send(req.body);
});
strainsRouter.get('/:id', function(req, res) {
var strains = STRAINS.filter(function(s) {
return s.id == req.params.id;
});
res.send({
'strain': strains[0]
});
});
strainsRouter.put('/:id', function(req, res) {
var strains = STRAINS.filter(function(s) {
return s.id == req.params.id;
});
if (strains.length === 0) {
res.status(422).send({
'errors':{
"strainName": ["error1"],
"typeStrain": ["error2", "error3"],
"isolatedFrom": ["error4"]
}
}).end();
} else {
res.status(204).end();
}
});
strainsRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
app.use('/api/hymenobacter/strains', strainsRouter);
};

View file

@ -1,84 +0,0 @@
module.exports = function(app) {
var express = require('express');
var usersRouter = express.Router();
var USERS = [
{
id: 1,
email: 'testA',
name: 'Test Admin User',
role: 'A',
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null
},
{
id: 2,
email: 'testR',
name: 'Test Read User',
role: 'R',
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null
},
{
id: 3,
email: 'testW',
name: 'Test Write User',
role: 'W',
createdAt: "0001-01-01T00:00:00Z",
updatedAt: "0001-01-01T00:00:00Z",
deletedAt: null
}
]
usersRouter.get('/', function(req, res) {
var users;
if (req.query.ids) {
users = USERS.filter(function(u) {
return req.query.ids.indexOf(u.id.toString()) > -1;
});
} else {
users = USERS;
}
res.send({
'users': users
});
});
usersRouter.post('/', function(req, res) {
req.body.user.id = Math.max.apply(Math, USERS.map(function(o){return o.id;})) + 1;
res.status(201).send(req.body);
// // NOTE - use the following for testing errors
// res.status(422).send({
// 'errors':{
// "name": ["Must provide a value"],
// "email": ["Must provide a value"],
// "password": ["Must provide a value"],
// }
// }).end();
});
usersRouter.get('/:id', function(req, res) {
var user = USERS.filter(function(u) {
return u.id == req.params.id;
});
res.send({
'user': user
});
});
usersRouter.put('/:id', function(req, res) {
res.send({
'users': {
id: req.params.id
}
});
});
usersRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
app.use('/api/users', usersRouter);
};