2016-03-02 22:45:23 +00:00
|
|
|
import test from 'ava';
|
|
|
|
import addContributor from './add';
|
|
|
|
|
|
|
|
function mockInfoFetcher(username, cb) {
|
|
|
|
return cb(null, {
|
|
|
|
login: username,
|
|
|
|
name: 'Some name',
|
|
|
|
avatar_url: 'www.avatar.url',
|
2016-03-06 18:37:26 +00:00
|
|
|
profile: 'www.profile.url'
|
2016-03-02 22:45:23 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function fixtures() {
|
|
|
|
const options = {
|
|
|
|
contributors: [{
|
|
|
|
login: 'login1',
|
|
|
|
name: 'Some name',
|
|
|
|
avatar_url: 'www.avatar.url',
|
2016-03-06 18:37:26 +00:00
|
|
|
profile: 'www.profile.url',
|
2016-03-02 22:45:23 +00:00
|
|
|
contributions: [
|
|
|
|
'code'
|
|
|
|
]
|
|
|
|
}, {
|
|
|
|
login: 'login2',
|
|
|
|
name: 'Some name',
|
|
|
|
avatar_url: 'www.avatar.url',
|
2016-03-06 18:37:26 +00:00
|
|
|
profile: 'www.profile.url',
|
2016-03-02 22:45:23 +00:00
|
|
|
contributions: [
|
2016-03-06 23:20:24 +00:00
|
|
|
{type: 'blog', url: 'www.blog.url/path'},
|
2016-03-02 22:45:23 +00:00
|
|
|
'code'
|
|
|
|
]
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
return {options};
|
|
|
|
}
|
|
|
|
|
|
|
|
test.cb('should callback with error if infoFetcher fails', t => {
|
|
|
|
const {options} = fixtures();
|
|
|
|
const username = 'login3';
|
|
|
|
const contributions = ['doc'];
|
|
|
|
function infoFetcher(username, cb) {
|
|
|
|
return cb(new Error('infoFetcher error'));
|
|
|
|
}
|
|
|
|
|
2016-03-06 23:20:24 +00:00
|
|
|
return addContributor(options, username, contributions, infoFetcher, function (error) {
|
2016-03-02 22:45:23 +00:00
|
|
|
t.is(error.message, 'infoFetcher error');
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test.cb('should add new contributor at the end of the list of contributors', t => {
|
|
|
|
const {options} = fixtures();
|
|
|
|
const username = 'login3';
|
|
|
|
const contributions = 'doc';
|
|
|
|
|
2016-03-06 23:20:24 +00:00
|
|
|
return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
|
2016-03-02 22:45:23 +00:00
|
|
|
t.notOk(error);
|
|
|
|
t.is(contributors.length, 3);
|
|
|
|
t.same(contributors[2], {
|
|
|
|
login: 'login3',
|
|
|
|
name: 'Some name',
|
|
|
|
avatar_url: 'www.avatar.url',
|
2016-03-06 18:37:26 +00:00
|
|
|
profile: 'www.profile.url',
|
2016-03-02 22:45:23 +00:00
|
|
|
contributions: [
|
|
|
|
'doc'
|
|
|
|
]
|
|
|
|
});
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test.cb('should add new contributor at the end of the list of contributors with a url link', t => {
|
|
|
|
const {options} = fixtures();
|
|
|
|
const username = 'login3';
|
|
|
|
const contributions = 'doc';
|
|
|
|
options.url = 'www.foo.bar';
|
|
|
|
|
2016-03-06 23:20:24 +00:00
|
|
|
return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
|
2016-03-02 22:45:23 +00:00
|
|
|
t.notOk(error);
|
|
|
|
t.is(contributors.length, 3);
|
|
|
|
t.same(contributors[2], {
|
|
|
|
login: 'login3',
|
|
|
|
name: 'Some name',
|
|
|
|
avatar_url: 'www.avatar.url',
|
2016-03-06 18:37:26 +00:00
|
|
|
profile: 'www.profile.url',
|
2016-03-02 22:45:23 +00:00
|
|
|
contributions: [
|
2016-03-06 23:20:24 +00:00
|
|
|
{type: 'doc', url: 'www.foo.bar'}
|
2016-03-02 22:45:23 +00:00
|
|
|
]
|
|
|
|
});
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test.cb(`should not update an existing contributor's contributions where nothing has changed`, t => {
|
|
|
|
const {options} = fixtures();
|
|
|
|
const username = 'login2';
|
|
|
|
const contributions = 'blog,code';
|
|
|
|
|
2016-03-06 23:20:24 +00:00
|
|
|
return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
|
2016-03-02 22:45:23 +00:00
|
|
|
t.notOk(error);
|
|
|
|
t.same(contributors, options.contributors);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test.cb(`should update an existing contributor's contributions if a new type is added`, t => {
|
|
|
|
const {options} = fixtures();
|
|
|
|
const username = 'login1';
|
|
|
|
const contributions = 'bug';
|
|
|
|
|
2016-03-06 23:20:24 +00:00
|
|
|
return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
|
2016-03-02 22:45:23 +00:00
|
|
|
t.notOk(error);
|
|
|
|
t.is(contributors.length, 2);
|
|
|
|
t.same(contributors[0], {
|
|
|
|
login: 'login1',
|
|
|
|
name: 'Some name',
|
|
|
|
avatar_url: 'www.avatar.url',
|
2016-03-06 18:37:26 +00:00
|
|
|
profile: 'www.profile.url',
|
2016-03-02 22:45:23 +00:00
|
|
|
contributions: [
|
|
|
|
'code',
|
|
|
|
'bug'
|
|
|
|
]
|
|
|
|
});
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test.cb(`should update an existing contributor's contributions if a new type is added with a link`, t => {
|
|
|
|
const {options} = fixtures();
|
|
|
|
const username = 'login1';
|
|
|
|
const contributions = 'bug';
|
|
|
|
options.url = 'www.foo.bar';
|
|
|
|
|
2016-03-06 23:20:24 +00:00
|
|
|
return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
|
2016-03-02 22:45:23 +00:00
|
|
|
t.notOk(error);
|
|
|
|
t.is(contributors.length, 2);
|
|
|
|
t.same(contributors[0], {
|
|
|
|
login: 'login1',
|
|
|
|
name: 'Some name',
|
|
|
|
avatar_url: 'www.avatar.url',
|
2016-03-06 18:37:26 +00:00
|
|
|
profile: 'www.profile.url',
|
2016-03-02 22:45:23 +00:00
|
|
|
contributions: [
|
|
|
|
'code',
|
2016-03-06 23:20:24 +00:00
|
|
|
{type: 'bug', url: 'www.foo.bar'}
|
2016-03-02 22:45:23 +00:00
|
|
|
]
|
|
|
|
});
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|