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:
Alex Jover 2017-02-23 20:02:55 +01:00 committed by Kent C. Dodds
parent 1305a7cd92
commit a879de2a7f
2 changed files with 20 additions and 1 deletions

View file

@ -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
};
});
};

View file

@ -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');
});
});