-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtwitter-spec.js
117 lines (90 loc) · 2.73 KB
/
twitter-spec.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
113
114
115
116
117
var rewire = require('rewire'),
assert = require('assert'),
twitter = rewire('./twitter.js'),
mocks = require('./twitter-spec-mock-data.js');
describe('twitter module', function(){
describe('simplify function', function(){
var simplify;
before(function() {
simplify = twitter.__get__('simplify');
});
it('should be defined', function(){
assert.ok(simplify);
});
describe('simplify a tweet', function(){
var tweet, mock;
before(function() {
mock = mocks[0];
tweet = simplify(mock);
});
it('should have 4 properties', function() {
assert.equal( Object.keys(tweet).length, 4 );
});
it('should have date property', function() {
assert.ok(tweet.date);
});
it('should have id property', function() {
assert.ok(tweet.id);
});
it('should have user property', function() {
assert.ok(tweet.user);
});
it('should have id property within user', function() {
assert.ok(tweet.user.id);
});
it('should have tweet property', function() {
assert.ok(tweet.tweet);
});
describe('format dates as `MMMM Do YYYY, h:mm:ss a`', function() {
var revert;
describe('English format', function() {
before(function() {
revert = twitter.__set__('process.env.MomentLang', 'en');
tweet = simplify(mock);
});
it('should be `March 6th 2015, 2:29:13 am`', function() {
assert.equal(tweet.date, 'March 6th 2015, 2:29:13 am');
});
after(function(){
revert();
});
});
describe('Brazilian format', function() {
before(function() {
revert = twitter.__set__('process.env.MomentLang', 'pt-br');
tweet = simplify(mock);
});
it('should be `Março 6º 2015, 2:29:13 am`', function() {
assert.equal(tweet.date, 'Março 6º 2015, 2:29:13 am');
});
after(function(){
revert();
});
});
});
});
});
describe('retrieve timeline feed', function() {
var revert;
before(function() {
revert = twitter.__set__("T.get", function( api, query, callback ) {
callback( null, mocks);
});
});
describe('igorribeirolima timeline', function() {
var tweets;
before(function(done){
twitter('igorribeirolima', function(err, data) {
tweets = data;
done();
});
});
it('should have 19 tweets', function() {
assert.equal(tweets.length, 19);
});
});
after(function() {
revert();
});
});
});