mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 21:46:29 +00:00
parent
9f72f9aabc
commit
a79f9d4ea6
2 changed files with 54 additions and 2 deletions
|
@ -23,7 +23,7 @@ function updateContributor(options, contributor, contributions) {
|
||||||
|
|
||||||
function updateExistingContributor(options, username, contributions) {
|
function updateExistingContributor(options, username, contributions) {
|
||||||
return options.contributors.map(function (contributor) {
|
return options.contributors.map(function (contributor) {
|
||||||
if (username !== contributor.login) {
|
if (username.toLowerCase() !== contributor.login.toLowerCase()) {
|
||||||
return contributor;
|
return contributor;
|
||||||
}
|
}
|
||||||
return updateContributor(options, contributor, contributions);
|
return updateContributor(options, contributor, contributions);
|
||||||
|
@ -41,8 +41,14 @@ function addNewContributor(options, username, contributions, infoFetcher) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function addContributor(options, username, contributions, infoFetcher) {
|
module.exports = function addContributor(options, username, contributions, infoFetcher) {
|
||||||
if (_.find({login: username}, options.contributors)) {
|
// case insensitive find
|
||||||
|
var exists = _.find(function (contributor) {
|
||||||
|
return contributor.login.toLowerCase() === username.toLowerCase();
|
||||||
|
}, options.contributors);
|
||||||
|
|
||||||
|
if (exists) {
|
||||||
return Promise.resolve(updateExistingContributor(options, username, contributions));
|
return Promise.resolve(updateExistingContributor(options, username, contributions));
|
||||||
}
|
}
|
||||||
return addNewContributor(options, username, contributions, infoFetcher);
|
return addNewContributor(options, username, contributions, infoFetcher);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,21 @@ function fixtures() {
|
||||||
return {options};
|
return {options};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function caseFixtures() {
|
||||||
|
const options = {
|
||||||
|
contributors: [{
|
||||||
|
login: 'Login1',
|
||||||
|
name: 'Some name',
|
||||||
|
avatar_url: 'www.avatar.url',
|
||||||
|
profile: 'www.profile.url',
|
||||||
|
contributions: [
|
||||||
|
'code'
|
||||||
|
]
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
return {options};
|
||||||
|
}
|
||||||
|
|
||||||
test('should callback with error if infoFetcher fails', t => {
|
test('should callback with error if infoFetcher fails', t => {
|
||||||
const {options} = fixtures();
|
const {options} = fixtures();
|
||||||
const username = 'login3';
|
const username = 'login3';
|
||||||
|
@ -100,6 +115,17 @@ test(`should not update an existing contributor's contributions where nothing ha
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(`should not update an existing contributor's contributions where nothing has changed but the casing`, t => {
|
||||||
|
const {options} = caseFixtures();
|
||||||
|
const username = 'login1';
|
||||||
|
const contributions = ['code'];
|
||||||
|
|
||||||
|
return addContributor(options, username, contributions, mockInfoFetcher)
|
||||||
|
.then(contributors => {
|
||||||
|
t.deepEqual(contributors, options.contributors);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test(`should update an existing contributor's contributions if a new type is added`, t => {
|
test(`should update an existing contributor's contributions if a new type is added`, t => {
|
||||||
const {options} = fixtures();
|
const {options} = fixtures();
|
||||||
const username = 'login1';
|
const username = 'login1';
|
||||||
|
@ -120,6 +146,26 @@ test(`should update an existing contributor's contributions if a new type is add
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(`should update an existing contributor's contributions if a new type is added with different username case`, t => {
|
||||||
|
const {options} = caseFixtures();
|
||||||
|
const username = 'login1';
|
||||||
|
const contributions = ['bug'];
|
||||||
|
return addContributor(options, username, contributions, mockInfoFetcher)
|
||||||
|
.then(contributors => {
|
||||||
|
t.is(contributors.length, 1);
|
||||||
|
t.deepEqual(contributors[0], {
|
||||||
|
login: 'Login1',
|
||||||
|
name: 'Some name',
|
||||||
|
avatar_url: 'www.avatar.url',
|
||||||
|
profile: 'www.profile.url',
|
||||||
|
contributions: [
|
||||||
|
'code',
|
||||||
|
'bug'
|
||||||
|
]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test(`should update an existing contributor's contributions if a new type is added with a link`, t => {
|
test(`should update an existing contributor's contributions if a new type is added with a link`, t => {
|
||||||
const {options} = fixtures();
|
const {options} = fixtures();
|
||||||
const username = 'login1';
|
const username = 'login1';
|
||||||
|
|
Loading…
Reference in a new issue