-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
112 lines (92 loc) · 2.78 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// var server = require ('./server'); //server.js
var api = require ('./api');
var http = require("http");
var url = require("url");
var fs = require("fs");
var api = require("./api");
var ecstatic = require("ecstatic")({ root: __dirname + '/public'});
var Twitter = require('twitter');
var home = fs.readFileSync("./home.html").toString();
var test = require('tape');
// MOCK response object
var mockresponse = {};
// res.writeHead(
mockresponse.writeHead = function(status, headers) {
mockresponse = mockresponse;
mockresponse.headers = headers;
mockresponse.status = status;
return mockresponse;
}
// res.end(
mockresponse.end = function(str) {
mockresponse = mockresponse;
mockresponse.body = str;
return mockresponse;
}
//** Tests **//
test('api.js - status code is 200', function(t){
var pathname= "/";
api.getTweets(mockresponse, pathname, function (response){
t.equal(response.status, 200, 'reponse code is 200');
t.end();
});
});
test('invoking getTweets WITHOUT callback still works', function(t){
var pathname= "/";
api.getTweets(mockresponse, pathname);
t.equal(mockresponse.status, 200, 'response code is 200');
t.end();
});
test('tweets contains the string valentines', function(t){
var pathname= "#valentines";
// console.log(">> TEST ",pathname)
api.getTweets(mockresponse, pathname, function (response){
var tweets = JSON.parse(response.body);
// console.log("Length: ", tweets.statuses.length);
for (var i = 0; i < 1; i++) {
// console.log(tweets.statuses[i].text);
var text = tweets.statuses[i].text.toLowerCase()
t.true(text.indexOf('valentines') > -1, "Tweet contains word valentines");
};
t.end();
});
});
test('tweets contains the string bmx', function(t){
var pathname= "/#bmx";
api.getTweets(mockresponse, pathname, function (response){
var tweets = JSON.parse(response.body);
// console.log("Length: ", tweets.statuses.length);
for (var i = 0; i < 1; i++) {
var text = tweets.statuses[i].text.toLowerCase()
// console.log(text);
t.true(text.indexOf('bmx') > -1, "Tweet contains word bmx");
};
t.end();
});
});
// test('Instagram fetches image urls', function(t){
// var pathname = "/dogs";
// api.getInsta(mockresponse, pathname, function(response){
// var instas = JSON.parse(response.body);
// for (var i=0; i<1; i++){
// var urls = instas.link[i];
// console.log(">>>>URLS is" + urls);
// t.true(urls.length > 0, "url is more than 1 char");
// };
// t.end();
// });
// })
// var m = api.getTweets(response, "/get");
// m();
// var n = response.statusCode;
// t.equal(n, 200);
// });
// test('tweets arr', function(t){
// t.plan(1);
// var n = tweetsArray;
// t.equal(n, []);
// });
// console.log('asdf');
// api.getTweets()
// server.start();
// console.log(response.statusCode);