Skip to content

Commit

Permalink
fix(tests): Modernize unit tests of Notifications (#366)
Browse files Browse the repository at this point in the history
Replaces PR #326. Closes #212.

## Changes

- all notif tests are now pure Mocha tests. => no more wrappers
- all async functions now return Promises => no more callbacks
- each test cleans up the db before running => no more repeated "clean-up" tests
  • Loading branch information
adrienjoly committed Sep 6, 2020
1 parent e6ab012 commit 2233e2d
Show file tree
Hide file tree
Showing 2 changed files with 230 additions and 358 deletions.
14 changes: 9 additions & 5 deletions app/models/notif.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ exports.clearUserNotifsForPost = function (uId, pId) {
);
};

exports.clearUserNotifs = function (uId) {
exports.clearUserNotifs = function (uId, cb) {
if (!uId) return;
db['notif'].find({ uId: uId }, { uId: 1 }, { limit: 1000 }, function (
err,
Expand All @@ -215,9 +215,12 @@ exports.clearUserNotifs = function (uId) {
db['notif'].update(
{ uId: uId },
{ $pull: { uId: uId } },
{ multi: true, w: 0 }
{ multi: true, w: 0 },
() => {
invalidateUserNotifsCache(uId);
cb && cb();
}
);
invalidateUserNotifsCache(uId);
}
);
}
Expand Down Expand Up @@ -292,7 +295,7 @@ exports.html = function (uId, html, href, img) {

// specific notification methods

exports.love = function (loverUid, post) {
exports.love = function (loverUid, post, callback) {
var user = mongodb.usernames['' + loverUid];
var author = mongodb.usernames['' + post.uId];
if (!user || !author) return;
Expand All @@ -309,7 +312,8 @@ exports.love = function (loverUid, post) {
$push: { lov: loverUid },
$inc: { n: 1 },
},
{ upsert: true, w: 0 }
{ upsert: true, w: 0 },
callback
);
invalidateUserNotifsCache(post.uId); // author will be invalidated later by clearUserNotifsForPost()
notifEmails.sendLike(user, post, author);
Expand Down
Loading

0 comments on commit 2233e2d

Please sign in to comment.