mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-10 05:56:29 +00:00
Provide a fallback for null display names. (#21)
* Provide a fallback for null display names. * Check empty strings too.
This commit is contained in:
parent
47c69a381a
commit
c4d04d00ee
3 changed files with 50 additions and 1 deletions
|
@ -15,7 +15,7 @@ module.exports = function getUserInfo(username, cb) {
|
||||||
var body = JSON.parse(res.body);
|
var body = JSON.parse(res.body);
|
||||||
var user = {
|
var user = {
|
||||||
login: body.login,
|
login: body.login,
|
||||||
name: body.name,
|
name: body.name || username,
|
||||||
avatar_url: body.avatar_url,
|
avatar_url: body.avatar_url,
|
||||||
profile: body.blog || body.html_url
|
profile: body.blog || body.html_url
|
||||||
};
|
};
|
||||||
|
|
48
lib/contributors/github.test.js
Normal file
48
lib/contributors/github.test.js
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
import test from 'ava';
|
||||||
|
import nock from 'nock';
|
||||||
|
import getUserInfo from './github';
|
||||||
|
|
||||||
|
test.cb('should handle errors', function (t) {
|
||||||
|
nock('https://api.github.com')
|
||||||
|
.get('/users/nodisplayname')
|
||||||
|
.replyWithError(404);
|
||||||
|
|
||||||
|
getUserInfo('nodisplayname', function (err) {
|
||||||
|
t.truthy(err);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.cb('should fill in the name when null is returned', function (t) {
|
||||||
|
nock('https://api.github.com')
|
||||||
|
.get('/users/nodisplayname')
|
||||||
|
.reply(200, {
|
||||||
|
login: 'nodisplayname',
|
||||||
|
name: null,
|
||||||
|
avatar_url: 'https://avatars2.githubusercontent.com/u/3869412?v=3&s=400',
|
||||||
|
html_url: 'https://github.com/nodisplayname'
|
||||||
|
});
|
||||||
|
|
||||||
|
getUserInfo('nodisplayname', function (err, info) {
|
||||||
|
t.falsy(err);
|
||||||
|
t.is(info.name, 'nodisplayname');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.cb('should fill in the name when an empty string is returned', function (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: 'https://github.com/nodisplayname'
|
||||||
|
});
|
||||||
|
|
||||||
|
getUserInfo('nodisplayname', function (err, info) {
|
||||||
|
t.falsy(err);
|
||||||
|
t.is(info.name, 'nodisplayname');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
});
|
|
@ -31,6 +31,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ava": "^0.14.0",
|
"ava": "^0.14.0",
|
||||||
|
"nock": "^8.0.0",
|
||||||
"nyc": "^6.4.2",
|
"nyc": "^6.4.2",
|
||||||
"xo": "^0.15.0"
|
"xo": "^0.15.0"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue