Example #1
0
 Promise.resolve(runtime.users[0]).then(function(user) {
   // this is the default paging limit
   return db.notifications.latest(user.id, { type: 'message', limit: 1 })
   .then(function(notifications) {
     expect(notifications).to.exist;
     expect(notifications).to.have.length(1);
   })
   .then(function() {
     return db.notifications.latest(user.id, { type: 'message', limit: 10, page: 2 });
   })
   .then(function(notifications) {
     expect(notifications).to.exist;
     expect(notifications).to.have.length(8);
   })
   .then(function() {
     return db.notifications.latest(user.id, { type: 'message', limit: 20 });
   })
   .then(function(notifications) {
     expect(notifications).to.exist;
     expect(notifications).to.have.length(18);
   })
   .catch(function(err) {
     throw err;
   });
 })
Example #2
0
 Promise.resolve(runtime.users[0]).then(function(user) {
   // this is the default paging limit
   return db.notifications.dismiss({ receiver_id: user.id, type: 'message' })
   .then(function() { return db.notifications.counts(user.id); })
   .then(function(counts) {
     expect(counts.message).to.equal(0);
     expect(counts.mention).to.equal('10+');
   })
   .then(function() { return db.notifications.counts(runtime.users[1].id); })
   .then(function(counts) {
     expect(counts.message).to.equal('10+');
   })
   .then(function() {
     return db.notifications.latest(user.id, { type: 'message' });
   })
   .then(function(notifications) {
     expect(notifications).to.have.length(0);
   })
   .then(function(notifications) {
     return db.notifications.dismiss({ receiver_id: user.id, type: 'message' })
     .catch(function(err) {
       expect(err).to.not.exist();
     });
   })
   .catch(function(err) {
     throw err;
   });
 })
Example #3
0
 Promise.resolve(runtime.users[0]).then(function(user) {
   // this is the default paging limit
   return db.notifications.latest(user.id, { type: 'mention' })
   .then(function(notifications) {
     expect(notifications).to.exist;
     expect(notifications).to.have.length(15);
   })
   .then(function() {
     // this is the first page of notifications
     return db.notifications.latest(user.id, { type: 'mention', page: 1 });
   })
   .then(function(notifications) {
     expect(notifications).to.exist;
     expect(notifications).to.have.length(15);
   })
   .then(function() {
     // this is the second page of notifications
     return db.notifications.latest(user.id, { type: 'mention', page: 2 });
   })
   .then(function(notifications) {
     expect(notifications).to.exist;
     expect(notifications).to.have.length(3);
   })
   .catch(function(err) {
     throw err;
   });
 })
Example #4
0
 Promise.map(runtime.users, function(user) {
   return db.notifications.latest(user.id, { type: 'mention' })
   .then(function(notifications) {
     expect(notifications).to.exist;
   })
   .catch(function(err) {
     throw err;
   });
 })
Example #5
0
 .then(function(user) {
   return db.notifications.counts(user.id)
   .then(function(counts) {
     expect(counts.message).to.exist;
     expect(counts.message).to.equal(3);
     expect(counts.mention).to.exist;
     expect(counts.mention).to.equal(3);
   })
   .catch(function(err) {
     throw err;
   });
 })
Example #6
0
 Promise.resolve(runtime.users[0]).then(function(user) {
   return db.notifications.counts(user.id)
   .then(function(counts) {
     expect(counts.message).to.exist;
     expect(counts.message).to.equal('10+');
     expect(counts.mention).to.exist;
     expect(counts.mention).to.equal('10+');
   })
   .catch(function(err) {
     throw err;
   });
 })
Example #7
0
 lab.test('should create a notification for a user', function(done) {
   db.notifications.create({ sender_id: runtime.users[3].id, receiver_id: runtime.users[3].id, type: 'test' })
   .then(function(notification) {
     expect(notification).to.exist;
     expect(notification.id).to.exist;
     expect(notification.created_at).to.be.a.date();
     expect(notification.viewed).to.be.false();
   })
   .then(function() {
     done();
   })
   .catch(function(err) {
     throw err;
   });
 });
Example #8
0
 Promise.resolve().then(function() {
   db.notifications.create()
   .catch(function(err) {
     expect(err).to.be.instanceof(CreationError);
   });
 })
Example #9
0
 Promise.resolve().then(function() {
   db.notifications.create({ sender_id: runtime.users[3].id, receiver_id: runtime.users[3].id })
   .catch(function(err) {
     expect(err).to.be.instanceof(CreationError);
   });
 })
Example #10
0
 .then(function(notifications) {
   return db.notifications.dismiss({ receiver_id: user.id, type: 'message' })
   .catch(function(err) {
     expect(err).to.not.exist();
   });
 })
Example #11
0
 .then(function() {
   return db.notifications.latest(user.id, { type: 'message' });
 })
Example #12
0
 .then(function() { return db.notifications.counts(runtime.users[1].id); })
Example #13
0
 .then(function() { return db.notifications.counts(user.id); })
Example #14
0
 .then(function() {
   return db.notifications.latest(user.id, { type: 'message', limit: 1, page: 19 });
 })
Example #15
0
 .then(function() {
   // this is the second page of notifications
   return db.notifications.latest(user.id, { type: 'mention', page: 2 });
 })
Example #16
0
 .then(function() {
   // this is the first page of notifications
   return db.notifications.latest(user.id, { type: 'message', page: 1 });
 })