[CORD-2277] Sending event when model is deleted

Change-Id: I4ff5376dc4d707e0b59b5c852c89b98f940c7e40
diff --git a/.eslintrc.txt b/.eslintrc
similarity index 100%
rename from .eslintrc.txt
rename to .eslintrc
diff --git a/.gitignore b/.gitignore
index d1f6870..5c29422 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@
 npm-debug.log
 .nyc_output
 coverage
+.idea
diff --git a/spec/redis.spec.js b/spec/redis.spec.js
index e1d0178..05ddadc 100644
--- a/spec/redis.spec.js
+++ b/spec/redis.spec.js
@@ -91,13 +91,14 @@
       client.unsubscribe(channelName);
       client.subscribe(channelName);
       publisher.flushdb();
+      socketSpy.reset();
     });
 
     it('should send a websocket event when it receive a redis event that is not JSON', (done) => {
       publisher.publish(channelName, 'I am sending a message.');
       setTimeout(() => {
         expect(socketSpy).to.have.been.called;
-        expect(socketSpy).to.have.been.calledWith('event', {
+        expect(socketSpy).to.have.been.calledWith('update', {
           model: channelName,
           msg: 'I am sending a message.'
         });
@@ -109,12 +110,37 @@
       publisher.publish(channelName, JSON.stringify({msg: 'Json Message'}));
       setTimeout(() => {
         expect(socketSpy).to.have.been.called;
-        expect(socketSpy).to.have.been.calledWith('event', {
+        expect(socketSpy).to.have.been.calledWith('update', {
           model: channelName,
           msg: {msg: 'Json Message'}
         });
         done();
       }, 1000)
     });
+
+    it('should send a websocket event when an object has been removed', (done) => {
+      publisher.publish(channelName, JSON.stringify({msg: 'Deleted', deleted: true}));
+      setTimeout(() => {
+        expect(socketSpy).to.have.been.called;
+        expect(socketSpy).to.have.been.calledWith('remove', {
+          model: channelName,
+          msg: {
+            msg: 'Deleted',
+            deleted: true
+          },
+          deleted: true
+        });
+
+        done();
+      }, 1000)
+    });
+
+  it('should not send a websocket event if the channel is Diag', (done) => {
+    publisher.publish('Diag', JSON.stringify({msg: 'Json Message'}));
+    setTimeout(() => {
+      expect(socketSpy).not.to.have.been.called;
+      done();
+    }, 1000)
+    });
   });
 })();
\ No newline at end of file
diff --git a/src/controllers/redis.js b/src/controllers/redis.js
index a051e36..7e86000 100644
--- a/src/controllers/redis.js
+++ b/src/controllers/redis.js
@@ -46,18 +46,28 @@
   });
 
   client.on('pmessage', function (pattern, channel, message) {
-    logger.log('warn', 'sub channel ' + channel + ': ' + message);
+    if (channel === 'Diag') {
+      return;
+    }
+
 
     let msg;
     try {
       msg = JSON.parse(message);
       // TODO find the user that needs to be notified for msg.object update
-      socket.emit('event', {model: channel, msg: msg});
     }
     catch(e) {
       // send the event also if it is not JSON
       msg = message;
-      socket.emit('event', {model: channel, msg: msg});
+    }
+
+    if (msg.deleted) {
+      logger.log('warn', 'Remove on: ' + channel + ': ' + message);
+      socket.emit('remove', {model: channel, msg: msg, deleted: true});
+    }
+    else {
+      logger.log('warn', 'Update on: ' + channel + ': ' + message);
+      socket.emit('update', {model: channel, msg: msg});
     }
   });