Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
youennPennarun committed Mar 7, 2016
1 parent 69300a3 commit 7194a46
Show file tree
Hide file tree
Showing 19 changed files with 601 additions and 473 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["es2015", "stage-0"],
"plugins": ["transform-object-rest-spread", "transform-es2015-destructuring"]
}
53 changes: 29 additions & 24 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,35 @@
},

"plugins": ["react"],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",

"ecmaFeatures": {
"arrowFunctions": true,
"binaryLiterals": true,
"blockBindings": true,
"classes": true,
"defaultParams": true,
"destructuring": true,
"forOf": true,
"generators": true,
"modules": true,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": true,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"octalLiterals": true,
"regexUFlag": true,
"regexYFlag": true,
"spread": true,
"superInFunctions": true,
"templateStrings": true,
"unicodeCodePointEscapes": true,
"globalReturn": true,
"jsx": true
"ecmaFeatures": {
"arrowFunctions": true,
"binaryLiterals": true,
"blockBindings": true,
"classes": true,
"defaultParams": true,
"destructuring": true,
"forOf": true,
"generators": true,
"modules": true,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": true,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"octalLiterals": true,
"regexUFlag": true,
"regexYFlag": true,
"spread": true,
"superInFunctions": true,
"templateStrings": true,
"unicodeCodePointEscapes": true,
"globalReturn": true,
"jsx": true,
"sourceType": "module"
}
},

"rules": {
Expand Down Expand Up @@ -73,7 +78,7 @@
"block-scoped-var": 0, // treat var statements as if they were block scoped (off by default). 0: deep destructuring is not compatible https://github.com/eslint/eslint/issues/1863
"complexity": 0, // specify the maximum cyclomatic complexity allowed in a program (off by default)
"consistent-return": 2, // require return statements to either always or never specify values
"curly": 2, // specify curly brace conventions for all control statements
"curly": 0, // specify curly brace conventions for all control statements
"default-case": 2, // require default case in switch statements (off by default)
"dot-notation": 2, // encourages use of dot notation whenever possible
"eqeqeq": 2, // require the use of === and !==
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"material-ui-sass": "^0.7.5",
"mongoose": "^4.1.7",
"mosca": "^1.0.2",
"mqtt": "^1.7.3",
"node-env-file": "^0.1.7",
"node-gcm": "^0.12.0",
"object-assign": "^4.0.1",
Expand Down Expand Up @@ -91,7 +92,7 @@
]
},
"scripts": {
"test": "mocha ./src/server/test --timeout 10000 -r ./src/server/test/init",
"test": "./node_modules/.bin/mocha --compilers js:babel-core/register ./src/server/test --timeout 10000 -r ./src/server/test/init",
"start": "gulp buildClient; npm run server",
"server": "node src/server/start.js",
"postinstall": "",
Expand Down
2 changes: 1 addition & 1 deletion src/public/src/js/actions/ServiceActionCreator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ export default {

});
}
}
}
145 changes: 72 additions & 73 deletions src/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ import MqttServer from "./modules/mqttServer";
import setEvents from "./socket/events";

var config = require("./data/private/config.js");
var express = require('express');
var express = require("express");
var routes = require("./routes");

var ModuleManager = require("./modules/ModuleManager");
ModuleManager.init();

var schema = require('./models/mongoose/mongoose-schema.js')(ModuleManager);
var models = require('./models/mongoose/mongoose-models.js');
var schema = require("./models/mongoose/mongoose-schema.js")(ModuleManager);
var models = require("./models/mongoose/mongoose-models.js");

var Raspberry = require("./models/Raspberry");
// var Raspberry = require("./models/Raspberry");

var connection = require('./models/mongoose/mongoose-connection')(config, function() {
var connection = require("./models/mongoose/mongoose-connection")(config, function () {

});

var winston = require('winston');
var expressWinston = require('express-winston');
var bodyParser = require('body-parser');
var bearerToken = require('express-bearer-token');
var winston = require("winston");
var expressWinston = require("express-winston");
var bodyParser = require("body-parser");
var bearerToken = require("express-bearer-token");
var jwt = require("jwt-simple");
var path = require("path");

Expand All @@ -35,84 +35,83 @@ var app = express();



var server = require('http').createServer(app);
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE');
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With, Authorization, Content-Type");
res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
var server = require("http").createServer(app);
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE");
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With, Authorization, Content-Type");
res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
next();
});
app.use(express.static(path.join(__dirname, '../public/dist')));
app.use(express.static(path.join(__dirname, '../../node_modules')));
app.use(express.static(path.join(__dirname, "../public/dist")));
app.use(express.static(path.join(__dirname, "../../node_modules")));
app.use(bearerToken());
app.use(bodyParser());
app.use(function(req, res, next) {
req.user = null;
var user = null;
try {
user = jwt.decode(req.token, config.jwtSecret);
} catch(e) {
return next();
}
console.log("get user");
userModel.findOne({username: user.username}, function(err, userInfo) {
console.log("got user");
req.user = userInfo;
return next();
});
req.user = null;
var user = null;
try {
user = jwt.decode(req.token, config.jwtSecret);
} catch (e) {
return next();
}
console.log("get user");
userModel.findOne({username: user.username}, function (err, userInfo) {
console.log("got user");
req.user = userInfo;
return next();
});
});



app.use(expressWinston.logger({
transports: [new winston.transports.Console({
json: true,
colorize: true
})],
meta: true, // optional: control whether you want to log the meta data about the request (default to true)
msg: "HTTP {{req.method}} {{req.url}}", // optional: customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}"
expressFormat: true, // Use the default Express/morgan request formatting, with the same colors. Enabling this will override any msg and colorStatus if true. Will only output colors on transports with colorize set to true
colorStatus: true, // Color the status code, using the Express/morgan color palette (default green, 3XX cyan, 4XX yellow, 5XX red). Will not be recognized if expressFormat is true
ignoreRoute: function ignoreRoute(req, res) {
return false;
} // optional: allows to skip some log messages based on request and/or response
transports: [new winston.transports.Console({
json: true,
colorize: true
})],
meta: true,
msg: "HTTP {{req.method}} {{req.url}}",
expressFormat: true,
colorStatus: true,
ignoreRoute: function ignoreRoute(req, res) {
return false;
}
}));

process.messager = new MqttServer(server);
setEvents(process.messager);
process.messager.start().then(()=> console.log("started"));

ModuleManager.load(process.messager).then(function() {
routes(app, server);
app.get('*', function(req, res, next) {
var err = {};
err.status = 404;
next(err);
});

// handling 404 errors
app.use(function(err, req, res, next) {
console.error(err.stack);
if(err.status !== 404) {
return next();
}
res.status(404)
res.json(err);
});
// handling 500 errors
app.use(function(err, req, res, next) {
console.error(err.stack);
if(err.status !== 500) {
return next();
}
res.status(500);
});
//Raspberry.stopAll();
server.listen(process.env.PORT || 3000, function () {

var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
routes(app, server);
app.get("*", function (req, res, next) {
var err = {};
err.status = 404;
next(err);
});

// handling 404 errors
app.use(function (err, req, res, next) {
console.error(err.stack);
if (err.status !== 404) {
return next();
}
res.status(404)
res.json(err);
});
// handling 500 errors
app.use(function (err, req, res, next) {
console.error(err.stack);
if(err.status !== 500) {
return next();
}
res.status(500);
});
//Raspberry.stopAll();
server.listen(process.env.PORT || 3000, function () {

var host = server.address().address;
var port = server.address().port;
console.log("Example app listening at http://%s:%s", host, port);
});
})
Loading

0 comments on commit 7194a46

Please sign in to comment.