New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ACHIEVEMENT] The Gladiator - achievement for getting all the reaction to a comment #51
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
71e944e
[ACHIEVEMENT] used all reactions
dunaevsky 4f5c1c1
used all reactions - now with returning value in function
dunaevsky be50b3b
All reactions used achvmnt- not including inline comments
dunaevsky c6c1ea5
Used all reactions - add inline and PR check(still problem with PR)
dunaevsky b9e31d6
fix achievement + implement tests
dunaevsky 808304d
CR comments
dunaevsky File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
|
||
//var template = { | ||
// name: , | ||
// check: function(pullRequest, shall) { | ||
// if (...) { | ||
// | ||
// var achievement = { | ||
// / avatar : '', | ||
// name: '', | ||
// short: '', | ||
// description: '', | ||
// relatedPullRequest: pullRequest._id | ||
// }; | ||
|
||
//shall.grant(pullRequest.creator.username, achievement); | ||
// } | ||
// } | ||
//}; | ||
|
||
|
||
|
||
//module.exports = template; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
var _ = require('lodash'); | ||
// Gives achievement to comment authors who got all reactions | ||
// without reacting themselves | ||
|
||
var usedAllReactionsInComment = { | ||
name: 'Gladiator', | ||
check: function(pullRequest, shall) { | ||
var topAuthorsUsernames = getCommentAuthorsWithAllReactions(pullRequest); | ||
if (!_.isEmpty(topAuthorsUsernames)) { | ||
var achievement = { | ||
avatar: 'images/achievements/gladiator.achievement.gif', | ||
name: 'Gladiator', | ||
short: 'Are You Not Entertained?', | ||
description: [ | ||
'You got all the reactions to your comment. You make everybody feel.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you like this description? seems kind of too non-descriptive to me |
||
].join(''), | ||
relatedPullRequest: pullRequest._id | ||
}; | ||
|
||
_.forEach(topAuthorsUsernames, function(author) { | ||
shall.grant(author, achievement); | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
function getCommentAuthorsWithAllReactions(pullRequest) { | ||
var allComments = _.concat(pullRequest.comments, pullRequest.inlineComments); | ||
var authors = _.map(allComments, 'author.username'); | ||
var AllCommentsReactions = _.map(allComments, 'reactions'); | ||
|
||
// also add pull request description reactions | ||
authors.push(pullRequest.creator.username); | ||
AllCommentsReactions.push(pullRequest.reactions); | ||
|
||
getOnlyUniqueReactionsWithoutAuthors(AllCommentsReactions, authors); | ||
|
||
return onlyUsersWithAllReactions(authors, AllCommentsReactions); | ||
} | ||
|
||
function reactionsWithoutAuthor(reactions, author) { | ||
return _.map(_.reject(reactions, ['user.username', author]), 'reaction'); | ||
} | ||
|
||
function getOnlyUniqueReactionsWithoutAuthors(AllCommentsReactions, authors) { | ||
_.forEach(AllCommentsReactions, function(reactions, index) { | ||
AllCommentsReactions[index] = | ||
_.uniq(reactionsWithoutAuthor(reactions, authors[index])); | ||
|
||
}); | ||
} | ||
|
||
function onlyUsersWithAllReactions(authors, AllCommentsReactions) { | ||
var commentAuthorsWithAllReactions = []; | ||
|
||
_.forEach(authors, function(author, index) { | ||
if (AllCommentsReactions[index].length === 6) { | ||
commentAuthorsWithAllReactions.push(author); | ||
} | ||
}); | ||
|
||
return commentAuthorsWithAllReactions; | ||
} | ||
module.exports = usedAllReactionsInComment; |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
var usedAllReactionsInComment = | ||
require('../achievements/usedAllReactionsInComment.achievement'); | ||
var expect = require('chai').expect; | ||
|
||
describe('usedAllReactionsInComment achievement', function() { | ||
describe('should be granted if PR has a message with all reactions', | ||
function() { | ||
it('should work with inline comments', function() { | ||
var testShall = new Shall(); | ||
var pullRequest = new PullRequest(); | ||
|
||
pullRequest.inlineComments = [ createQualifiedComment() ]; | ||
|
||
usedAllReactionsInComment.check(pullRequest, testShall); | ||
expect(testShall.grantedToUsername).to.be.a('string'); | ||
expect(testShall.grantedToUsername).to.equal('comment_author'); | ||
expect(testShall.grantedAchievement).to.be.an('object'); | ||
}); | ||
|
||
it('should work with PR comments', function() { | ||
var testShall = new Shall(); | ||
var pullRequest = new PullRequest(); | ||
|
||
pullRequest.comments = [ createQualifiedComment() ]; | ||
|
||
usedAllReactionsInComment.check(pullRequest, testShall); | ||
expect(testShall.grantedToUsername).to.be.a('string'); | ||
expect(testShall.grantedToUsername).to.equal('comment_author'); | ||
expect(testShall.grantedAchievement).to.be.an('object'); | ||
}); | ||
|
||
it('should work with PR description', function() { | ||
var testShall = new Shall(); | ||
var pullRequest = new PullRequest(); | ||
|
||
pullRequest.reactions = createQualifiedReactions(); | ||
|
||
usedAllReactionsInComment.check(pullRequest, testShall); | ||
expect(testShall.grantedToUsername).to.be.a('string'); | ||
expect(testShall.grantedToUsername).to.equal('creator'); | ||
expect(testShall.grantedAchievement).to.be.an('object'); | ||
}); | ||
it('should work if all reactions + author reaction', function() { | ||
var testShall = new Shall(); | ||
var pullRequest = new PullRequest(); | ||
|
||
pullRequest.reactions = createQualifiedReactions(); | ||
pullRequest.reactions.push({ | ||
'reaction': '+1', | ||
'user': { | ||
'username': 'creator' | ||
} | ||
}); | ||
|
||
usedAllReactionsInComment.check(pullRequest, testShall); | ||
expect(testShall.grantedToUsername).to.be.a('string'); | ||
expect(testShall.grantedToUsername).to.equal('creator'); | ||
expect(testShall.grantedAchievement).to.be.an('object'); | ||
}); | ||
}); | ||
|
||
it('should not grant if comment with less than all reactions', function() { | ||
var testShall = new Shall(); | ||
var pullRequest = new PullRequest(); | ||
|
||
pullRequest.inlineComments = [ createQualifiedComment() ]; | ||
pullRequest.inlineComments[0].reactions.pop(); //remove 1 reaction | ||
|
||
usedAllReactionsInComment.check(pullRequest, testShall); | ||
expect(testShall.grantedToUsername).to.not.exist; | ||
expect(testShall.grantedAchievement).to.not.exist; | ||
}); | ||
|
||
it('should not grant if author reacted', function() { | ||
var testShall = new Shall(); | ||
var pullRequest = new PullRequest(); | ||
|
||
pullRequest.comments = [ createQualifiedComment() ]; | ||
pullRequest.comments[0].reactions[0].user.username = 'comment_author'; | ||
|
||
usedAllReactionsInComment.check(pullRequest, testShall); | ||
expect(testShall.grantedToUsername).to.not.exist; | ||
expect(testShall.grantedAchievement).to.not.exist; | ||
}); | ||
|
||
it('should not grant if 6 reactions with a duplicate', function() { | ||
var testShall = new Shall(); | ||
var pullRequest = new PullRequest(); | ||
|
||
pullRequest.comments = [ createQualifiedComment() ]; | ||
pullRequest.comments[0].reactions[0].reaction = '-1'; | ||
|
||
usedAllReactionsInComment.check(pullRequest, testShall); | ||
expect(testShall.grantedToUsername).to.not.exist; | ||
expect(testShall.grantedAchievement).to.not.exist; | ||
}); | ||
}); | ||
|
||
function Shall() { | ||
var self = this; | ||
|
||
self.grantedAchievement = undefined; | ||
self.grantedToUsername = undefined; | ||
|
||
self.grant = function(username, achievementObject) { | ||
self.grantedToUsername = username; | ||
self.grantedAchievement = achievementObject; | ||
}; | ||
} | ||
|
||
function createQualifiedComment() { | ||
return { | ||
'author': { | ||
'username': 'comment_author' | ||
}, | ||
'reactions': createQualifiedReactions() | ||
}; | ||
} | ||
|
||
function createQualifiedReactions() { | ||
return [ | ||
{ | ||
'reaction': '+1', | ||
'user': { | ||
'username': 'Thatkookooguy' | ||
} | ||
}, | ||
{ | ||
'reaction': '-1', | ||
'user': { | ||
'username': 'Thatkookooguy' | ||
} | ||
}, | ||
{ | ||
'reaction': 'laugh', | ||
'user': { | ||
'username': 'Thatkookooguy' | ||
} | ||
}, | ||
{ | ||
'reaction': 'hooray', | ||
'user': { | ||
'username': 'Thatkookooguy' | ||
} | ||
}, | ||
{ | ||
'reaction': 'confused', | ||
'user': { | ||
'username': 'Thatkookooguy' | ||
} | ||
}, | ||
{ | ||
'reaction': 'heart', | ||
'user': { | ||
'username': 'Thatkookooguy' | ||
} | ||
} | ||
]; | ||
} | ||
|
||
function PullRequest() { | ||
return { | ||
'id': 'test', | ||
'url': 'url', | ||
'number': 3, | ||
'creator': { | ||
'username': 'creator' | ||
} | ||
}; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E is uppercase
I think a
?!
can work here