1
1
import test from 'ava' ;
2
2
import addContributor from './add' ;
3
3
4
- function mockInfoFetcher ( username , cb ) {
5
- return cb ( null , {
4
+ function mockInfoFetcher ( username ) {
5
+ return Promise . resolve ( {
6
6
login : username ,
7
7
name : 'Some name' ,
8
8
avatar_url : 'www.avatar.url' ,
@@ -34,27 +34,27 @@ function fixtures() {
34
34
return { options} ;
35
35
}
36
36
37
- test . cb ( 'should callback with error if infoFetcher fails' , t => {
37
+ test ( 'should callback with error if infoFetcher fails' , t => {
38
38
const { options} = fixtures ( ) ;
39
39
const username = 'login3' ;
40
40
const contributions = [ 'doc' ] ;
41
- function infoFetcher ( username , cb ) {
42
- return cb ( new Error ( 'infoFetcher error' ) ) ;
41
+ function infoFetcher ( ) {
42
+ return Promise . reject ( new Error ( 'infoFetcher error' ) ) ;
43
43
}
44
44
45
- return addContributor ( options , username , contributions , infoFetcher , function ( error ) {
46
- t . is ( error . message , 'infoFetcher error' ) ;
47
- t . end ( ) ;
48
- } ) ;
45
+ return t . throws (
46
+ addContributor ( options , username , contributions , infoFetcher ) ,
47
+ 'infoFetcher error'
48
+ ) ;
49
49
} ) ;
50
50
51
- test . cb ( 'should add new contributor at the end of the list of contributors' , t => {
51
+ test ( 'should add new contributor at the end of the list of contributors' , t => {
52
52
const { options} = fixtures ( ) ;
53
53
const username = 'login3' ;
54
54
const contributions = [ 'doc' ] ;
55
55
56
- return addContributor ( options , username , contributions , mockInfoFetcher , function ( error , contributors ) {
57
- t . falsy ( error ) ;
56
+ return addContributor ( options , username , contributions , mockInfoFetcher )
57
+ . then ( contributors => {
58
58
t . is ( contributors . length , 3 ) ;
59
59
t . deepEqual ( contributors [ 2 ] , {
60
60
login : 'login3' ,
@@ -65,18 +65,17 @@ test.cb('should add new contributor at the end of the list of contributors', t =
65
65
'doc'
66
66
]
67
67
} ) ;
68
- t . end ( ) ;
69
68
} ) ;
70
69
} ) ;
71
70
72
- test . cb ( 'should add new contributor at the end of the list of contributors with a url link' , t => {
71
+ test ( 'should add new contributor at the end of the list of contributors with a url link' , t => {
73
72
const { options} = fixtures ( ) ;
74
73
const username = 'login3' ;
75
74
const contributions = [ 'doc' ] ;
76
75
options . url = 'www.foo.bar' ;
77
76
78
- return addContributor ( options , username , contributions , mockInfoFetcher , function ( error , contributors ) {
79
- t . falsy ( error ) ;
77
+ return addContributor ( options , username , contributions , mockInfoFetcher )
78
+ . then ( contributors => {
80
79
t . is ( contributors . length , 3 ) ;
81
80
t . deepEqual ( contributors [ 2 ] , {
82
81
login : 'login3' ,
@@ -87,28 +86,26 @@ test.cb('should add new contributor at the end of the list of contributors with
87
86
{ type : 'doc' , url : 'www.foo.bar' }
88
87
]
89
88
} ) ;
90
- t . end ( ) ;
91
89
} ) ;
92
90
} ) ;
93
91
94
- test . cb ( `should not update an existing contributor's contributions where nothing has changed` , t => {
92
+ test ( `should not update an existing contributor's contributions where nothing has changed` , t => {
95
93
const { options} = fixtures ( ) ;
96
94
const username = 'login2' ;
97
95
const contributions = [ 'blog' , 'code' ] ;
98
96
99
- return addContributor ( options , username , contributions , mockInfoFetcher , function ( error , contributors ) {
100
- t . falsy ( error ) ;
97
+ return addContributor ( options , username , contributions , mockInfoFetcher )
98
+ . then ( contributors => {
101
99
t . deepEqual ( contributors , options . contributors ) ;
102
- t . end ( ) ;
103
100
} ) ;
104
101
} ) ;
105
102
106
- test . cb ( `should update an existing contributor's contributions if a new type is added` , t => {
103
+ test ( `should update an existing contributor's contributions if a new type is added` , t => {
107
104
const { options} = fixtures ( ) ;
108
105
const username = 'login1' ;
109
106
const contributions = [ 'bug' ] ;
110
- return addContributor ( options , username , contributions , mockInfoFetcher , function ( error , contributors ) {
111
- t . falsy ( error ) ;
107
+ return addContributor ( options , username , contributions , mockInfoFetcher )
108
+ . then ( contributors => {
112
109
t . is ( contributors . length , 2 ) ;
113
110
t . deepEqual ( contributors [ 0 ] , {
114
111
login : 'login1' ,
@@ -120,18 +117,17 @@ test.cb(`should update an existing contributor's contributions if a new type is
120
117
'bug'
121
118
]
122
119
} ) ;
123
- t . end ( ) ;
124
120
} ) ;
125
121
} ) ;
126
122
127
- test . cb ( `should update an existing contributor's contributions if a new type is added with a link` , t => {
123
+ test ( `should update an existing contributor's contributions if a new type is added with a link` , t => {
128
124
const { options} = fixtures ( ) ;
129
125
const username = 'login1' ;
130
126
const contributions = [ 'bug' ] ;
131
127
options . url = 'www.foo.bar' ;
132
128
133
- return addContributor ( options , username , contributions , mockInfoFetcher , function ( error , contributors ) {
134
- t . falsy ( error ) ;
129
+ return addContributor ( options , username , contributions , mockInfoFetcher )
130
+ . then ( contributors => {
135
131
t . is ( contributors . length , 2 ) ;
136
132
t . deepEqual ( contributors [ 0 ] , {
137
133
login : 'login1' ,
@@ -143,6 +139,5 @@ test.cb(`should update an existing contributor's contributions if a new type is
143
139
{ type : 'bug' , url : 'www.foo.bar' }
144
140
]
145
141
} ) ;
146
- t . end ( ) ;
147
142
} ) ;
148
143
} ) ;
0 commit comments