Skip to content

Commit 19ce247

Browse files
committed
Rudimentary tests for all remaining functions
1 parent 413e3ec commit 19ce247

File tree

3 files changed

+108
-2
lines changed

3 files changed

+108
-2
lines changed

test/fixtures/fixtures.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

test/fixtures/generate_fixtures.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ var urls = [
1212
'/api/v1/search_by_date?tags=(story%2Cpoll)',
1313
'/api/v1/search?tags=story',
1414
'/api/v1/search_by_date?tags=story',
15+
'/api/v1/items/17',
16+
'/api/v1/users/pg',
17+
'/api/v1/search?tags=comment%2Cauthor_pg',
18+
'/api/v1/search_by_date?tags=comment%2Cauthor_pg',
19+
'/api/v1/search?tags=poll%2Cauthor_pg',
20+
'/api/v1/search_by_date?tags=poll%2Cauthor_pg',
21+
'/api/v1/search?tags=story%2Cauthor_pg',
22+
'/api/v1/search_by_date?tags=story%2Cauthor_pg',
23+
'/api/v1/search?query=apple&tags=comment',
24+
'/api/v1/search_by_date?query=apple&tags=comment',
25+
'/api/v1/search?query=apple&tags=poll',
26+
'/api/v1/search_by_date?query=apple&tags=poll',
27+
'/api/v1/search?query=apple&tags=story',
28+
'/api/v1/search_by_date?query=apple&tags=story',
29+
'/api/v1/search?query=apple&tags=story',
30+
'/api/v1/search_by_date?query=apple&tags=story',
31+
'/api/v1/search?tags=ask_hn&query=apple&page=2',
32+
'/api/v1/search_by_date?tags=ask_hn&query=apple&page=2',
1533
];
1634

1735
async.mapSeries(urls, function(item, next) {

test/test.js

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('hn', function(){
3232
return done("Error");
3333
}
3434
expect(data).to.have.property('hits');
35-
data.hits.map(function(comment) {
35+
data.hits.forEach(function(comment) {
3636
var intersection = tags.filter(function(n) {
3737
return comment._tags.indexOf(n) != -1;
3838
});
@@ -41,6 +41,19 @@ describe('hn', function(){
4141
done();
4242
}
4343

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+
4457
it('should get comments', function(done) {
4558
hn.getComments(crazy_curry(['comment'], done, verifyDataHasOneOfTags));
4659
});
@@ -71,4 +84,79 @@ describe('hn', function(){
7184
it('should get latest stories', function(done) {
7285
hn.getLastStories(crazy_curry(['story'], done, verifyDataHasOneOfTags));
7386
});
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+
74162
});

0 commit comments

Comments
 (0)