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; }); })
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; }); })
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; }); })
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; }); })
.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; }); })
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; }); })
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; }); });
Promise.resolve().then(function() { db.notifications.create() .catch(function(err) { expect(err).to.be.instanceof(CreationError); }); })
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); }); })
.then(function(notifications) { return db.notifications.dismiss({ receiver_id: user.id, type: 'message' }) .catch(function(err) { expect(err).to.not.exist(); }); })
.then(function() { return db.notifications.latest(user.id, { type: 'message' }); })
.then(function() { return db.notifications.counts(runtime.users[1].id); })
.then(function() { return db.notifications.counts(user.id); })
.then(function() { return db.notifications.latest(user.id, { type: 'message', limit: 1, page: 19 }); })
.then(function() { // this is the second page of notifications return db.notifications.latest(user.id, { type: 'mention', page: 2 }); })
.then(function() { // this is the first page of notifications return db.notifications.latest(user.id, { type: 'message', page: 1 }); })