Skip to content

Commit

Permalink
add gladys.house.userSeen function
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles committed Mar 6, 2017
1 parent 50297a5 commit b6e9791
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
14 changes: 14 additions & 0 deletions api/core/house/house.userSeen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

module.exports = function userSeen(options) {

// see if user is at home
return gladys.house.isUserAtHome(options)
.then((atHome) => {

// if yes, do nothing
if(atHome) return null;

// if no, save event "back-at-home"
return gladys.event.create({code: 'back-at-home', user: options.user, house: options.house});
});
};
3 changes: 2 additions & 1 deletion api/core/house/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ module.exports.getUsers = require('./house.getUsers.js');
module.exports.getAll = require('./house.getAll.js');
module.exports.isEmpty = require('./house.isEmpty.js');
module.exports.isUserAtHome = require('./house.isUserAtHome.js');
module.exports.update = require('./house.update.js');
module.exports.update = require('./house.update.js');
module.exports.userSeen = require('./house.userSeen.js');
24 changes: 24 additions & 0 deletions test/unit/api/core/house/house.userSeen.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var should = require('should');
var validateHouse = require('../../validator/houseValidator.js');

describe('House', function() {

describe('userSeen', function() {

it('should create a back-at-home event', function (done) {

var options = {
house: 1,
user: 2
};

gladys.house.userSeen(options)
.then(function(result){
should.exist(result);

done();
}).catch(done);
});

});
});

0 comments on commit b6e9791

Please sign in to comment.