2016-06-28 09:29:23 +00:00
|
|
|
import test from 'ava';
|
|
|
|
import nock from 'nock';
|
|
|
|
import getUserInfo from './github';
|
|
|
|
|
2017-02-15 21:25:32 +00:00
|
|
|
test('should handle errors', t => {
|
2016-06-28 09:29:23 +00:00
|
|
|
nock('https://api.github.com')
|
|
|
|
.get('/users/nodisplayname')
|
|
|
|
.replyWithError(404);
|
|
|
|
|
2017-02-15 21:25:32 +00:00
|
|
|
return t.throws(getUserInfo('nodisplayname'));
|
2016-06-28 09:29:23 +00:00
|
|
|
});
|
|
|
|
|
2017-02-15 21:25:32 +00:00
|
|
|
test('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'
|
|
|
|
});
|
|
|
|
|
2017-02-15 21:25:32 +00:00
|
|
|
return getUserInfo('nodisplayname')
|
|
|
|
.then(info => {
|
2016-06-28 09:29:23 +00:00
|
|
|
t.is(info.name, 'nodisplayname');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-15 21:25:32 +00:00
|
|
|
test('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'
|
|
|
|
});
|
|
|
|
|
2017-02-15 21:25:32 +00:00
|
|
|
return getUserInfo('nodisplayname')
|
|
|
|
.then(info => {
|
2016-06-28 09:29:23 +00:00
|
|
|
t.is(info.name, 'nodisplayname');
|
|
|
|
});
|
|
|
|
});
|
2017-02-23 19:02:55 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|