File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const Github = require ( '../github' ) ;
2+
3+ describe ( 'Github Resource' , ( ) => {
4+ const fakeRequest = {
5+ get : jest . fn ( )
6+ } ;
7+ const githubResource = new Github ( fakeRequest ) ;
8+ afterEach ( ( ) => jest . clearAllMocks ( ) ) ;
9+
10+ it ( 'should return the followers count for a given github user' , async ( ) => {
11+ fakeRequest . get . mockResolvedValueOnce ( { data : { followers : 120 } } ) ;
12+
13+ const response = await githubResource . getFollowerCount ( 'waldemarnt' ) ;
14+ expect ( response ) . toEqual ( { followers :120 } ) ;
15+ } ) ;
16+ it ( 'should return not found when the user doenst exist' , async ( ) => {
17+ fakeRequest . get . mockRejectedValueOnce ( { response : { data : 'Not Found' , status : 404 } } ) ;
18+
19+ const response = await githubResource . getFollowerCount ( 'odkasodksaodk' ) ;
20+ expect ( response ) . toEqual ( { error : 'Not Found' } ) ;
21+ } ) ;
22+ it ( 'should return error when a general error happens' , async ( ) => {
23+ fakeRequest . get . mockRejectedValueOnce ( { response : { data : 'Error' , status : 500 } } ) ;
24+
25+ const response = await githubResource . getFollowerCount ( 'waldemarnt' ) ;
26+ expect ( response ) . toEqual ( { error : 'Error' } ) ;
27+ } ) ;
28+ } ) ;
You can’t perform that action at this time.
0 commit comments