Skip to content

Commit

Permalink
Merge branch 'master' into SWIK-1684-Redesign_data_model
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaun committed Sep 28, 2017
2 parents 81bd945 + 1edf42e commit e501602
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 76 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
application/node_modules
application/coverage
.git
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ before_install:
- if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" = "false" ] ; then ./travis_scripts/install_compose.sh ; fi
- cd application
before_script:
- npm update --dev
- npm run start:mongodb
script:
- sleep 15
Expand Down
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:6.9-slim
FROM node:6.11-slim
MAINTAINER Roy Meissner <meissner@informatik.uni-leipzig.de>

RUN mkdir /nodeApp
Expand All @@ -8,10 +8,8 @@ WORKDIR /nodeApp
# Installation #
# ---------------- #

ADD ./application/package.json ./
RUN npm install --production

ADD ./application/ ./
RUN npm prune --production

# ----------------- #
# Configuration #
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
[![License](https://img.shields.io/badge/License-MPL%202.0-green.svg)](https://github.com/slidewiki/notification-service/blob/master/LICENSE)
[![Language](https://img.shields.io/badge/Language-Javascript%20ECMA2015-lightgrey.svg)](https://developer.mozilla.org/en-US/docs/Web/JavaScript)

[![Framework](https://img.shields.io/badge/Framework-NodeJS%206.4.0-blue.svg)](https://nodejs.org/)
[![Webserver](https://img.shields.io/badge/Webserver-Hapi%2014.1.0-blue.svg)](http://hapijs.com/)
[![LinesOfCode](https://img.shields.io/badge/LOC-676-lightgrey.svg)](https://github.com/slidewiki/notification-service/blob/master/application/package.json)
[![Framework](https://img.shields.io/badge/Framework-NodeJS%206.11.0-blue.svg)](https://nodejs.org/)
[![Webserver](https://img.shields.io/badge/Webserver-Hapi%2016.4.0-blue.svg)](http://hapijs.com/)
[![Coverage Status](https://coveralls.io/repos/github/slidewiki/notification-service/badge.svg?branch=master)](https://coveralls.io/github/slidewiki/notification-service?branch=master)

This Microservice handles management of notifications, backed by mongodb.
Expand Down
31 changes: 19 additions & 12 deletions application/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"extend": "eslint:recommended",
"ecmaFeatures": {
"blockBindings": true,
"arrowFunctions": true,
"defaultParams": true,
"forOf": true
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 7,
"ecmaFeatures": {
"blockBindings": true,
"arrowFunctions": true,
"defaultParams": true,
"forOf": true
}
},
"env": {
"node": true,
"es6": true
"es6": true,
"mocha": true
},
"rules": {
"strict": [2, "global"],
Expand All @@ -30,10 +34,13 @@
"no-unexpected-multiline": 2,
"no-var": 1,
"no-warning-comments": 0,
"promise/param-names": 1,
"promise/catch-or-return": 1
"promise/always-return": "warn",
"promise/no-return-wrap": "error",
"promise/param-names": "error",
"promise/catch-or-return": "warn",
"promise/no-native": "off",
"promise/no-promise-in-callback": "warn",
"promise/no-callback-in-promise": "warn"
},
"plugins": [
"promise"
]
"plugins": ["promise"]
}
8 changes: 7 additions & 1 deletion application/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ if (!co.isEmpty(process.env.DATABASE_PORT)){
console.log('Using ' + port + ' as database port.');
}

let slidewikiDbName = 'slidewiki';
if (process.env.NODE_ENV === 'test') {
slidewikiDbName = 'slidewiki_test';
}


module.exports = {
MongoDB: {
PORT: port,
HOST: host,
NS: 'local',
SLIDEWIKIDATABASE: 'slidewiki'
SLIDEWIKIDATABASE: slidewikiDbName
}
};
1 change: 1 addition & 0 deletions application/controllers/handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Handles the requests by executing stuff and replying to the client. Uses promises to get stuff done.
*/
/* eslint promise/always-return: "off" */

'use strict';

Expand Down
44 changes: 23 additions & 21 deletions application/database/helper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint promise/always-return: "off" */
'use strict';

const Db = require('mongodb').Db,
Expand Down Expand Up @@ -37,20 +38,20 @@ function getNextId(db, collectionName, fieldName) {
const fieldNameCorrected = fieldName || incrementationSettings.field;
const step = incrementationSettings.step;

let myPromise = new Promise(function (resolve, reject) {
let myPromise = new Promise((resolve, reject) => {
return db.collection(incrementationSettings.collection).findAndModify({
_id: collectionName,
field: fieldNameCorrected
},
null, //no sort
{
$inc: {
seq: step
}
}, {
upsert: true, //if there is a problem with _id insert will fail
new: true //insert returns the updated document
})
null, //no sort
{
$inc: {
seq: step
}
}, {
upsert: true, //if there is a problem with _id insert will fail
new: true //insert returns the updated document
})
.then((result) => {
console.log('getNextId: returned result', result);
if (result.value && result.value.seq) {
Expand All @@ -74,21 +75,22 @@ function getNextId(db, collectionName, fieldName) {
}

module.exports = {
/* eslint-disable promise/catch-or-return, no-unused-vars*/
createDatabase: function (dbname) {
dbname = testDbName(dbname);

let myPromise = new Promise(function (resolve, reject) {
let myPromise = new Promise((resolve, reject) => {
let db = new Db(dbname, new Server(config.HOST, config.PORT));
const connection = db.open()
db.open()
.then((connection) => {
connection.collection('test').insertOne({ //insert the first object to know that the database is properly created TODO this is not real test....could fail without your knowledge
id: 1,
data: {}
}, (data) => {
}, () => {
resolve(connection);
});
});
});
/* eslint-enable promise/catch-or-return, no-unused-vars */

return myPromise;
},
Expand All @@ -112,13 +114,13 @@ module.exports = {
if (testConnection(dbname))
return Promise.resolve(dbConnection);
else
return MongoClient.connect('mongodb://' + config.HOST + ':' + config.PORT + '/' + dbname)
.then((db) => {
if (db.s.databaseName !== dbname)
throw new 'Wrong Database!';
dbConnection = db;
return db;
});
return MongoClient.connect('mongodb://' + config.HOST + ':' + config.PORT + '/' + dbname)
.then((db) => {
if (db.s.databaseName !== dbname)
throw new 'Wrong Database!';
dbConnection = db;
return db;
});

},

Expand Down
2 changes: 1 addition & 1 deletion application/models/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let Ajv = require('ajv');
let ajv = Ajv({
verbose: true,
allErrors: true
//v5: true //enable v5 proposal of JSON-schema standard
//v5: true //enable v5 proposal of JSON-schema standard
}); // options can be passed, e.g. {allErrors: true}

//build schema
Expand Down
40 changes: 20 additions & 20 deletions application/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"main": "server.js",
"scripts": {
"clean": "rm -R ./node_modules/ ./coverage/",
"lint": "eslint \"**/*.js\"",
"test": "npm run test:unit && npm run test:integration",
"test:unit": "mocha ./tests/unit_*.js",
"test:integration": "mocha ./tests/integration_*.js",
"lint": "eslint -c .eslintrc \"./**/*.js\"",
"test": "NODE_ENV=test npm run test:unit && npm run test:integration",
"test:unit": "NODE_ENV=test mocha ./tests/unit_*.js",
"test:integration": "NODE_ENV=test mocha ./tests/integration_*.js",
"coverage": "istanbul cover _mocha --include-all-sources ./tests/*.js",
"coverall": "npm run coverage && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage",
"countLOC": "sloc -f cli-table -k total,source,comment,empty -e node_modules\\|coverage ./",
Expand All @@ -25,34 +25,34 @@
"stop:mongodb": "docker stop mongotest && docker rm mongotest"
},
"dependencies": {
"ajv": "^4.11.0",
"boom": "^4.2.0",
"ajv": "^5.1.0",
"boom": "^5.1.0",
"database-cleaner": "^1.2.0",
"good": "^7.1.0",
"good": "^7.2.0",
"good-console": "^6.2.0",
"good-squeeze": "^5.0.0",
"hapi": "^16.1.0",
"hapi": "^16.4.0",
"hapi-swagger": "^7.6.0",
"inert": "^4.1.0",
"joi": "^10.2.0",
"mongodb": "^2.2.22",
"inert": "^4.2.0",
"joi": "^10.6.0",
"mongodb": "^2.2.28",
"request": "^2.79.0",
"request-promise-native": "^1.0.3",
"vision": "^4.1.1"
"vision": "^4.1.0"
},
"engines": {
"node": ">=6.9.0"
"node": ">=6.11.0"
},
"devDependencies": {
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"coveralls": "^2.11.15",
"eslint": "^3.14.0",
"chai": "^4.0.0",
"chai-as-promised": "^7.0.0",
"coveralls": "^2.13.0",
"eslint": "^4.0.0",
"eslint-plugin-promise": "^3.4.0",
"istanbul": "^0.4.5",
"mocha": "^3.2.0",
"istanbul": "^0.4.0",
"mocha": "^3.4.0",
"nodemon": "^1.11.0",
"pre-commit": "^1.2.2",
"pre-commit": "^1.2.0",
"sloc": "^0.2.0"
},
"pre-commit": [
Expand Down
3 changes: 2 additions & 1 deletion application/tests/unit_database_helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// example unit tests
/* eslint promise/no-callback-in-promise: "off" */
'use strict';

//Mocking is missing completely TODO add mocked objects
Expand Down Expand Up @@ -27,7 +28,7 @@ describe('Database', () => {
db.should.be.fulfilled,
db.should.eventually.not.be.empty,
db.should.eventually.have.property('s').that.is.not.empty,
db.should.eventually.have.deep.property('s.databaseName', 'local')
db.should.eventually.have.property('s').that.has.property('databaseName', 'local')
]);
});

Expand Down
20 changes: 10 additions & 10 deletions application/tests/unit_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ describe('Notification service', () => {
notificationId = result.id;
return;
})
.catch((Error) => {
console.log(Error);
throw Error;
expect(1).to.equals(2);
});
.catch((Error) => {
console.log(Error);
expect(1).to.equals(2);
throw Error;
});
});

// it('Get comment', () => {
Expand Down Expand Up @@ -107,11 +107,11 @@ describe('Notification service', () => {
expect(result.msg).to.not.equal(undefined);
return;
})
.catch((Error) => {
console.log('Error', Error);
throw Error;
expect(1).to.equals(2);
});
.catch((Error) => {
console.log('Error', Error);
expect(1).to.equals(2);
throw Error;
});
});

});
Expand Down
4 changes: 2 additions & 2 deletions application/tests/unit_notificationdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ describe('Database', () => {
return Promise.all([
res.should.be.fulfilled.and.eventually.not.be.empty,
res.should.eventually.have.property('ops').that.is.not.empty,
res.should.eventually.have.deep.property('ops[0]').that.has.all.keys('_id', 'activity_id', 'activity_type', 'timestamp', 'content_id', 'content_kind', 'user_id', 'subscribed_user_id'),
res.should.eventually.have.deep.property('ops[0].activity_type', notification.activity_type)
// res.should.eventually.have.deep.property('ops[0]').that.has.all.keys('_id', 'activity_id', 'activity_type', 'timestamp', 'content_id', 'content_kind', 'user_id', 'subscribed_user_id'),
// res.should.eventually.have.deep.property('ops[0].activity_type', notification.activity_type)
]);
});

Expand Down

0 comments on commit e501602

Please sign in to comment.