mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 13:36:29 +00:00
fix: non-http prepended urls (#35)
* Add editor config * Fix non-http prepended urls * Remove editorconfig * Use startsWith and shorthand operator
This commit is contained in:
parent
1305a7cd92
commit
a879de2a7f
2 changed files with 20 additions and 1 deletions
|
@ -12,11 +12,14 @@ module.exports = function getUserInfo(username) {
|
|||
})
|
||||
.then(res => {
|
||||
var body = JSON.parse(res.body);
|
||||
var profile = body.blog || body.html_url;
|
||||
profile = profile.startsWith('http') ? profile : 'http://' + profile;
|
||||
|
||||
return {
|
||||
login: body.login,
|
||||
name: body.name || username,
|
||||
avatar_url: body.avatar_url,
|
||||
profile: body.blog || body.html_url
|
||||
profile
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -41,3 +41,19 @@ test('should fill in the name when an empty string is returned', t => {
|
|||
t.is(info.name, 'nodisplayname');
|
||||
});
|
||||
});
|
||||
|
||||
test('should append http when no absolute link is provided', t => {
|
||||
nock('https://api.github.com')
|
||||
.get('/users/nodisplayname')
|
||||
.reply(200, {
|
||||
login: 'nodisplayname',
|
||||
name: '',
|
||||
avatar_url: 'https://avatars2.githubusercontent.com/u/3869412?v=3&s=400',
|
||||
html_url: 'www.github.com/nodisplayname'
|
||||
});
|
||||
|
||||
return getUserInfo('nodisplayname')
|
||||
.then(info => {
|
||||
t.is(info.profile, 'http://www.github.com/nodisplayname');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue