@@ -7,7 +7,6 @@ var fixtures = JSON.parse(fs.readFileSync(__dirname + "/fixtures/fixtures.json")
77
88var api = nock ( 'https://hn.algolia.com' ) . persist ( ) ;
99fixtures . forEach ( function ( f ) {
10- console . log ( f . url ) ;
1110 api . get ( f . url ) . reply ( 200 , f . reply ) ;
1211} ) ;
1312
@@ -33,7 +32,7 @@ describe('hn', function(){
3332 return done ( "Error" ) ;
3433 }
3534 expect ( data ) . to . have . property ( 'hits' ) ;
36- data . hits . map ( function ( comment ) {
35+ data . hits . forEach ( function ( comment ) {
3736 var intersection = tags . filter ( function ( n ) {
3837 return comment . _tags . indexOf ( n ) != - 1 ;
3938 } ) ;
@@ -42,6 +41,19 @@ describe('hn', function(){
4241 done ( ) ;
4342 }
4443
44+ function verifyDataHasAllOfTags ( err , data , tags , done ) {
45+ if ( err ) {
46+ return done ( "Error" ) ;
47+ }
48+ expect ( data ) . to . have . property ( 'hits' ) ;
49+ data . hits . forEach ( function ( item ) {
50+ tags . forEach ( function ( tag ) {
51+ expect ( item . _tags ) . to . contain ( tag ) ;
52+ } ) ;
53+ } ) ;
54+ done ( ) ;
55+ }
56+
4557 it ( 'should get comments' , function ( done ) {
4658 hn . getComments ( crazy_curry ( [ 'comment' ] , done , verifyDataHasOneOfTags ) ) ;
4759 } ) ;
@@ -72,4 +84,79 @@ describe('hn', function(){
7284 it ( 'should get latest stories' , function ( done ) {
7385 hn . getLastStories ( crazy_curry ( [ 'story' ] , done , verifyDataHasOneOfTags ) ) ;
7486 } ) ;
87+
88+ it ( 'should get item' , function ( done ) {
89+ hn . getItem ( 17 , function ( err , res ) {
90+ if ( err ) return done ( err ) ;
91+ expect ( res . id ) . to . equal ( 17 ) ;
92+ expect ( res . type ) . to . equal ( 'comment' ) ;
93+ done ( ) ;
94+ } ) ;
95+ } ) ;
96+
97+ it ( 'should get user' , function ( done ) {
98+ hn . getUser ( 'pg' , function ( err , res ) {
99+ if ( err ) return done ( err ) ;
100+ expect ( res . username ) . to . equal ( 'pg' ) ;
101+ done ( ) ;
102+ } ) ;
103+ } ) ;
104+
105+ it ( 'should get user comments' , function ( done ) {
106+ hn . getUserComments ( 'pg' , crazy_curry ( [ 'comment' , 'author_pg' ] , done , verifyDataHasAllOfTags ) ) ;
107+ } ) ;
108+ it ( 'should get last user comments' , function ( done ) {
109+ hn . getLastUserComments ( 'pg' , crazy_curry ( [ 'comment' , 'author_pg' ] , done , verifyDataHasAllOfTags ) ) ;
110+ } ) ;
111+
112+ it ( 'should get user polls' , function ( done ) {
113+ hn . getUserPolls ( 'pg' , crazy_curry ( [ 'poll' , 'author_pg' ] , done , verifyDataHasAllOfTags ) ) ;
114+ } ) ;
115+ it ( 'should get last user polls' , function ( done ) {
116+ hn . getLastUserPolls ( 'pg' , crazy_curry ( [ 'poll' , 'author_pg' ] , done , verifyDataHasAllOfTags ) ) ;
117+ } ) ;
118+
119+ it ( 'should get user stories' , function ( done ) {
120+ hn . getUserStories ( 'pg' , crazy_curry ( [ 'story' , 'author_pg' ] , done , verifyDataHasAllOfTags ) ) ;
121+ } ) ;
122+ it ( 'should get last user stories' , function ( done ) {
123+ hn . getLastUserStories ( 'pg' , crazy_curry ( [ 'story' , 'author_pg' ] , done , verifyDataHasAllOfTags ) ) ;
124+ } ) ;
125+
126+ it ( 'should search comments' , function ( done ) {
127+ hn . searchComments ( 'apple' , crazy_curry ( [ 'comment' ] , done , verifyDataHasAllOfTags ) ) ;
128+ } ) ;
129+ it ( 'should search last comments' , function ( done ) {
130+ hn . searchLastComments ( 'apple' , crazy_curry ( [ 'comment' ] , done , verifyDataHasAllOfTags ) ) ;
131+ } ) ;
132+
133+ it ( 'should search polls' , function ( done ) {
134+ hn . searchPolls ( 'apple' , crazy_curry ( [ 'poll' ] , done , verifyDataHasAllOfTags ) ) ;
135+ } ) ;
136+ it ( 'should search last polls' , function ( done ) {
137+ hn . searchLastPolls ( 'apple' , crazy_curry ( [ 'poll' ] , done , verifyDataHasAllOfTags ) ) ;
138+ } ) ;
139+
140+
141+ it ( 'should search posts' , function ( done ) {
142+ hn . searchPosts ( 'apple' , crazy_curry ( [ 'story' ] , done , verifyDataHasAllOfTags ) ) ;
143+ } ) ;
144+ it ( 'should search last posts' , function ( done ) {
145+ hn . searchLastPosts ( 'apple' , crazy_curry ( [ 'story' ] , done , verifyDataHasAllOfTags ) ) ;
146+ } ) ;
147+
148+ it ( 'should search posts' , function ( done ) {
149+ hn . searchStories ( 'apple' , crazy_curry ( [ 'story' ] , done , verifyDataHasAllOfTags ) ) ;
150+ } ) ;
151+ it ( 'should search last posts' , function ( done ) {
152+ hn . searchLastStories ( 'apple' , crazy_curry ( [ 'story' ] , done , verifyDataHasAllOfTags ) ) ;
153+ } ) ;
154+
155+ it ( 'should search' , function ( done ) {
156+ hn . search ( { tags : 'ask_hn' , query : 'apple' , page : 2 } , crazy_curry ( [ 'ask_hn' ] , done , verifyDataHasAllOfTags ) ) ;
157+ } ) ;
158+ it ( 'should search last' , function ( done ) {
159+ hn . searchLast ( { tags : 'ask_hn' , query : 'apple' , page : 2 } , crazy_curry ( [ 'ask_hn' ] , done , verifyDataHasAllOfTags ) ) ;
160+ } ) ;
161+
75162} ) ;
0 commit comments