From b6e9791b7fc8ae180359c5a5335138cc33015387 Mon Sep 17 00:00:00 2001 From: Pierre-Gilles Leymarie Date: Mon, 6 Mar 2017 16:02:55 +0100 Subject: [PATCH] add gladys.house.userSeen function --- api/core/house/house.userSeen.js | 14 +++++++++++ api/core/house/index.js | 3 ++- .../api/core/house/house.userSeen.test.js | 24 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 api/core/house/house.userSeen.js create mode 100644 test/unit/api/core/house/house.userSeen.test.js diff --git a/api/core/house/house.userSeen.js b/api/core/house/house.userSeen.js new file mode 100644 index 0000000000..c55dd3b423 --- /dev/null +++ b/api/core/house/house.userSeen.js @@ -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}); + }); +}; \ No newline at end of file diff --git a/api/core/house/index.js b/api/core/house/index.js index 7180ba864a..8ed11b448c 100644 --- a/api/core/house/index.js +++ b/api/core/house/index.js @@ -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'); \ No newline at end of file +module.exports.update = require('./house.update.js'); +module.exports.userSeen = require('./house.userSeen.js'); \ No newline at end of file diff --git a/test/unit/api/core/house/house.userSeen.test.js b/test/unit/api/core/house/house.userSeen.test.js new file mode 100644 index 0000000000..fd62d604a0 --- /dev/null +++ b/test/unit/api/core/house/house.userSeen.test.js @@ -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); + }); + + }); +}); \ No newline at end of file