2016-06-28 09:29:23 +00:00
|
|
|
import test from 'ava';
|
|
|
|
import nock from 'nock';
|
|
|
|
import getUserInfo from './github';
|
|
|
|
|
2016-06-28 09:34:32 +00:00
|
|
|
test.cb('should handle errors', t => {
|
2016-06-28 09:29:23 +00:00
|
|
|
nock('https://api.github.com')
|
|
|
|
.get('/users/nodisplayname')
|
|
|
|
.replyWithError(404);
|
|
|
|
|
2016-06-28 09:34:32 +00:00
|
|
|
getUserInfo('nodisplayname', err => {
|
2016-06-28 09:29:23 +00:00
|
|
|
t.truthy(err);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-06-28 09:34:32 +00:00
|
|
|
test.cb('should fill in the name when null is returned', t => {
|
2016-06-28 09:29:23 +00:00
|
|
|
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'
|
|
|
|
});
|
|
|
|
|
2016-06-28 09:34:32 +00:00
|
|
|
getUserInfo('nodisplayname', (err, info) => {
|
2016-06-28 09:29:23 +00:00
|
|
|
t.falsy(err);
|
|
|
|
t.is(info.name, 'nodisplayname');
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-06-28 09:34:32 +00:00
|
|
|
test.cb('should fill in the name when an empty string is returned', t => {
|
2016-06-28 09:29:23 +00:00
|
|
|
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'
|
|
|
|
});
|
|
|
|
|
2016-06-28 09:34:32 +00:00
|
|
|
getUserInfo('nodisplayname', (err, info) => {
|
2016-06-28 09:29:23 +00:00
|
|
|
t.falsy(err);
|
|
|
|
t.is(info.name, 'nodisplayname');
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|