2016-03-01 22:30:14 +00:00
import test from 'ava' ;
import _ from 'lodash/fp' ;
import formatContributor from './formatContributor' ;
import contributors from './fixtures/contributors.json' ;
function fixtures ( ) {
const options = {
projectOwner : 'jfmengels' ,
projectName : 'all-contributors-cli' ,
2016-03-20 19:33:01 +00:00
imageSize : 150
2016-03-01 22:30:14 +00:00
} ;
return { options } ;
}
test ( 'should format a simple contributor' , t => {
2016-03-06 23:20:24 +00:00
const contributor = _ . assign ( contributors . kentcdodds , { contributions : [ 'review' ] } ) ;
2016-03-01 22:30:14 +00:00
const { options } = fixtures ( ) ;
2016-03-20 19:33:01 +00:00
const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=150)<br /><sub>Kent C. Dodds</sub>](http://kentcdodds.com)<br />👀' ;
2016-03-01 22:30:14 +00:00
t . is ( formatContributor ( options , contributor ) , expected ) ;
} ) ;
test ( 'should format contributor with complex contribution types' , t => {
const contributor = contributors . kentcdodds ;
const { options } = fixtures ( ) ;
2016-03-31 09:00:02 +00:00
const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=150)<br /><sub>Kent C. Dodds</sub>](http://kentcdodds.com)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=kentcdodds) 👀 💁' ;
2016-03-01 22:30:14 +00:00
t . is ( formatContributor ( options , contributor ) , expected ) ;
} ) ;
test ( 'should format contributor using custom template' , t => {
const contributor = contributors . kentcdodds ;
const { options } = fixtures ( ) ;
2016-03-06 23:20:24 +00:00
options . contributorTemplate = '<%= contributor.name %> is awesome!' ;
2016-03-01 22:30:14 +00:00
const expected = 'Kent C. Dodds is awesome!' ;
t . is ( formatContributor ( options , contributor ) , expected ) ;
} ) ;
test ( 'should add image size to url' , t => {
const { options } = fixtures ( ) ;
const contributor = contributors . kentcdodds ;
2016-03-06 23:20:24 +00:00
options . contributorTemplate = '<%= contributor.name %> at <%= contributor.avatar_url %>' ;
2016-03-01 22:30:14 +00:00
var contributionWithoutQuestionMarkUrl = _ . assign ( contributor , {
avatar _url : 'www.some-url-without-question-mark.com'
} ) ;
var contributionWithQuestionMarkUrl = _ . assign ( contributor , {
avatar _url : 'www.some-url-with-question-mark.com?v=3'
} ) ;
t . is ( formatContributor ( options , contributionWithoutQuestionMarkUrl ) ,
2016-03-20 19:33:01 +00:00
'Kent C. Dodds at www.some-url-without-question-mark.com?s=150'
2016-03-01 22:30:14 +00:00
) ;
t . is ( formatContributor ( options , contributionWithQuestionMarkUrl ) ,
2016-03-20 19:33:01 +00:00
'Kent C. Dodds at www.some-url-with-question-mark.com?v=3&s=150'
) ;
} ) ;
test ( 'should default image size to 100' , t => {
const { options } = fixtures ( ) ;
const contributor = contributors . kentcdodds ;
options . contributorTemplate = '<%= contributor.name %> at <%= contributor.avatar_url %>' ;
delete options . imageSize ;
t . is ( formatContributor ( options , contributor ) ,
'Kent C. Dodds at https://avatars1.githubusercontent.com/u/1500684?s=100'
2016-03-01 22:30:14 +00:00
) ;
} ) ;