Skip to content

Commit

Permalink
merge addTop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
O-Mutt committed Oct 1, 2021
2 parents d949679 + 198f7ac commit 0adbf1e
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hubot-plusplus-expanded",
"version": "3.3.0",
"version": "3.3.1",
"description": "A hubot script for micro praise",
"main": "index.js",
"engines": {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/services/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,19 @@ class DatabaseService {
}

async savePlusPlusLog(to, from, room, reason, incrementValue) {
const pointsAmount = parseInt(incrementValue, 10);
const fromId = from.slackId || from.name;
const scoreSearch = from.slackId ? { slackId: from.slackId } : { name: from.name };
const toId = to.slackId || to.name;
const db = await this.getDb();
await db.collection(scoresDocumentName).updateOne(scoreSearch, { $inc: { totalPointsGiven: incrementValue } });
await db.collection(scoresDocumentName).updateOne(scoreSearch, { $inc: { totalPointsGiven: pointsAmount } });
await db.collection(logDocumentName).insertOne({
from: fromId,
to: toId,
date: moment().toISOString(),
room,
reason,
scoreChange: incrementValue,
scoreChange: pointsAmount,
});
}

Expand Down
3 changes: 2 additions & 1 deletion test/mockData/mockFullUser.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@
},
"hubotDay" : "2020-07-09T16:55:04.374Z",
"accountLevel": 1,
"slackId": "matt.erickson"
"slackId": "matt.erickson",
"totalPointsGiven": 13
}
3 changes: 2 additions & 1 deletion test/mockData/mockFullUserLevel2.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@
"hubotDay" : "2020-07-09T16:55:04.374Z",
"accountLevel": 2,
"token": 200,
"slackId": "peter.parker"
"slackId": "peter.parker",
"totalPointsGiven": 13
}
3 changes: 2 additions & 1 deletion test/mockData/mockMinimalUser.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
},
"hubotDay" : "2020-07-09T16:55:04.374Z",
"accountLevel": 1,
"slackId": "matt.erickson.min"
"slackId": "matt.erickson.min",
"totalPointsGiven": -2
}
3 changes: 2 additions & 1 deletion test/mockData/mockMinimalUserLevel2.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"hubotDay" : "2020-07-09T16:55:04.374Z",
"accountLevel": 2,
"token": 8,
"slackId": "peter.parker.min"
"slackId": "peter.parker.min",
"totalPointsGiven": -2
}
7 changes: 7 additions & 0 deletions test/plusplus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ describe('PlusPlus', function () {
expect(from.token).to.equal(198);
room.user.say('peter.parker', '@hubot @peter.parker.min + 2');
await new Promise((resolve) => setTimeout(resolve, 50));
const spamCheck = await db.collection('scoreLog').findOne({ from: 'peter.parker' });
expect(Object.keys(spamCheck)).to.eql(['_id', 'from', 'to', 'date', 'room', 'reason', 'scoreChange']);
spamCheck.date = '123'; // hack to handle date;
spamCheck._id = '1';
expect(spamCheck).to.deep.include({
from: 'peter.parker', to: 'peter.parker.min', reason: null, room: room.name, scoreChange: 2, _id: '1', date: '123',
});
expect(room.messages[3][1]).to.equal("I'm sorry <@peter.parker>, I'm afraid I can't do that.");
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/scoreboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Scoreboard', function () {
room.user.say('matt.erickson', '@hubot score for @matt.erickson');
await new Promise((resolve) => setTimeout(resolve, 45));
expect(room.messages[1][1]).to.match(
/<@matt\.erickson> has 227 points\.\nAccount Level: 1\nTotal Points Given: 14\n:birthday: Hubotday is 07-09-2020\n\n:star: Here are some reasons :star:(\n.*:.*){5}/,
/<@matt\.erickson> has 227 points\.\nAccount Level: 1\nTotal Points Given: 13\n:birthday: Hubotday is 07-09-2020\n\n:star: Here are some reasons :star:(\n.*:.*){5}/,
);
});

Expand Down

0 comments on commit 0adbf1e

Please sign in to comment.