Skip to content

Commit

Permalink
Merge aa6da46 into 28c2ed2
Browse files Browse the repository at this point in the history
  • Loading branch information
ZimGil committed Nov 12, 2018
2 parents 28c2ed2 + aa6da46 commit 072fd34
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
29 changes: 29 additions & 0 deletions achievements/imTheDevilILoveMetal.achievement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var imTheDevilILoveMetal = {
name: 'I\'m the Devil I Love Metal',
check: function(pullRequest, shall) {
if (isSequenceOfSixes(pullRequest.number)) {

var achievement = {
avatar: 'images/achievements/iAmTheDevilILikeMetal.achievement.gif',
name: 'I\'m the Devil I Love Metal',
short: 'check this riff it\'s fucking tasty',
description: [
'Your pull request number ' + pullRequest.number,
' summoned the devil himself. ',
'I hope that code you submitted was a masterpiece, ',
'or you\'re gonna gargle mayonnaise'
].join(''),
relatedPullRequest: pullRequest.id
};

shall.grant(pullRequest.creator.username, achievement);
}
}
};

function isSequenceOfSixes(number) {
const sequenceOfSixesRegExp = /^66+$/;
return sequenceOfSixesRegExp.test(number);
}

module.exports = imTheDevilILoveMetal;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions test/imTheDevilILoveMetal.specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
var imTheDevilILoveMetal = require('../achievements/imTheDevilILoveMetal.achievement');
var expect = require('chai').expect;

describe('imTheDevilILoveMetal achievement', function() {
it(
'should not grant if PR number is a sequence of numbers other than 6',
function() {
var testShall = new Shall();
var pullRequest = new PullRequest();

pullRequest.number = 333;

imTheDevilILoveMetal.check(pullRequest, testShall);
expect(testShall.grantedToUsername).to.not.exist;
expect(testShall.grantedToUsername).to.not.exist;
}
);

it(
'should be granted to PR creator if PR number is a sequence of 2 sixes',
function() {
var testShall = new Shall();
var pullRequest = new PullRequest();

pullRequest.number = 66;

imTheDevilILoveMetal.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 be granted to PR creator if PR number is a sequence of more then 2 sixes',
function() {
var testShall = new Shall();
var pullRequest = new PullRequest();

pullRequest.number = 6666;

imTheDevilILoveMetal.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 PR number is 6',
function() {
var testShall = new Shall();
var pullRequest = new PullRequest();

pullRequest.number = 6;

imTheDevilILoveMetal.check(pullRequest, testShall);
expect(testShall.grantedToUsername).to.not.exist;
expect(testShall.grantedToUsername).to.not.exist;
}
);

it(
'should not grand if PR number is not only a sequence of sixes',
function() {
var testShall = new Shall();
var pullRequest = new PullRequest();

pullRequest.number = 1666;

imTheDevilILoveMetal.check(pullRequest, testShall);
expect(testShall.grantedToUsername).to.not.exist;
expect(testShall.grantedToUsername).to.not.exist;
}
);

it(
'should not fail if PR number does not exist',
function() {
var testShall = new Shall();
var pullRequest = new PullRequest();

imTheDevilILoveMetal.check(pullRequest, testShall);
expect(testShall.grantedToUsername).to.not.exist;
expect(testShall.grantedToUsername).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 PullRequest() {
return {
'id': 'test',
'url': 'url',
'creator': {
'username': 'creator'
}
};
};

0 comments on commit 072fd34

Please sign in to comment.