-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
211 lines (187 loc) · 6.68 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
var giteventsTwitter = require('./index.js')(
//{
//NOTE: If you uncomment these lines and change them to valid values,
// DO NOT update this file on github. Alternatively, edit the config.js file,
// which will be automatically picked up by index.js.
// DO NOT put your config.js changes on github, either.
//twitter: {
// consumer_key: 1,
// consumer_secret: 1,
// token: 1,
// token_secret: 1
//}
//}
);
var test = require('tape');
var fakeDataTalks = {
"webhook": {
"label": "talk proposal",
"title": "Development environments using fig",
"level": "Beginner",
"language": "en",
"speaker": {
"twitter": "bcnjs",
"name": "Jorge Dias",
"portrait": ""
},
"description": "Soft Engineer for development and testing environments is going to talk about the research being done at Xing regarding the use of docker and will do a brief overview of working with fig and some custom tools to improve the workflow"
},
"event": {
"date": "2015-01-21T19:00:00.000Z",
"name": "BarcelonaJS",
"twitter": "bcnjs",
"venue": {
"name": "Mobile World Centre",
"address": "C/ Fontanella 2, 08002 Barcelona",
"private": false
},
"url": "www.meetup.com",
"talks": [
{
"title": "Serious text editing in the browser",
"level": "Advanced",
"language": "es",
"speaker": {
"twitter": "bcnjs",
"name": "Marijn Haverbeke",
"portrait": ""
},
"description": makeid() + "When an textarea do cut it anymore alternatives: full-featured text and code editors written in browser JavaScript. This talk is about CodeMirror, one such editor. It'll explore the intricacies of faking an editable control, the challenges of making it scale to hundreds of thousands of lines, and the integration of modern code editor"
},
{
"title": "Development environments using fig",
"level": "Beginner",
"language": "en",
"speaker": {
"twitter": "bcnjs",
"name": "Jorge Dias",
"portrait": ""
},
"description": makeid() + "Software Engineer turned responsible for development and testing environments is going to talk about the research being done at Xing regarding the use of docker and will do a brief overview of working with fig and some custom tools to improve the workflow."
}
]
}
};
var fakeDataJobs = {
"webhook": {
"label": "jobs",
"title": "New cool Job",
"company": "lolipop",
"description": "We're looking for Ninjas, because Ninja just sounds cool."
},
"jobs": [
{
"title": "New cool Job",
"company": makeid() + "lolipop",
"description": "We're looking for Ninjas, because Ninja just sounds cool."
},
{
"title": "New cool Job",
"company": makeid() + "lolipop",
"description": "We're looking for Ninjas, because Ninja just sounds cool."
}
]
};
// NOTE: replace our module's send function with a mock.
// It simply tests whether any data is provided.
// If so, it invokes callback with the data,
// otherwise it invokes callback with an error message.
giteventsTwitter.send = function (data, cb) {
if (data === undefined) {
console.error("send() received no tweet");
return cb("no tweet created");
}
//actual fn sends a tweet here
return cb(null, data);
};
test('post talks tweet works', function(t){
t.plan(2);
giteventsTwitter.init(fakeDataTalks, function (err, res) {
if (err) {
return console.error(err);
}
t.ok(res, 'we get a response from server');
});
});
test('post jobs tweet works', function(t){
t.plan(2);
giteventsTwitter.init(fakeDataJobs, function(err, res){
if (err) {
return console.error(err);
}
t.ok(res, 'we get a response from server for jobs');
})
});
// Creates array of sent tweets then checks array elements
// for correctness and array for length. Either tweet
// may arrive first, so this is handled. Removes 5 character
// id from tweet before checks.
test('talk tweets match expected results', function (t) {
var tempTweet = "",
tweetAsArray = [],
tweetsSent = [],
tweet1 = "New talk: www.meetup.com When an textarea do cut it anymore alternatives: full-featured text and code editors written in bro...",
tweet2 = "New talk: www.meetup.com Software Engineer turned responsible for development and testing environments is going to talk abo...";
t.plan(2);
giteventsTwitter.init(fakeDataTalks, function (err, res) {
if (err) {
return console.error(err);
}
// remove 5 char id from tweet before adding to array
tweetAsArray = res.split('');
tweetAsArray.splice(25, 5);
res = tweetAsArray.join('');
tweetsSent.push(res);
// wait for both tweets to be sent (i.e. stored in the array)
if (tweetsSent.length === 2) {
// may need to swap tweets around before check
if (tweetsSent[0] !== tweet1) {
tempTweet = tweetsSent[0];
tweetsSent[0] = tweetsSent[1];
tweetsSent[1] = tempTweet;
}
t.equal(tweetsSent[0], tweet1, 'tweet 1 matches expected result');
t.equal(tweetsSent[1], tweet2, 'tweet 2 matches expected result');
}
else if (tweetsSent.length > 2) {
t.fail('too many tweets sent');
}
});
});
// This test calls init(), providing the optional second parameter
// as "custom", which builds the tweet using a custom format.
// Otherwise, the test is the same as the 'talk tweets match expected results'
// test directly above this one.
test('custom talk tweets match expected results', function (t) {
var tweetsSent = [],
tweet1 = "LNUG talk - @bcnjs - Serious text editing in the browser",
tweet2 = "LNUG talk - @bcnjs - Development environments using fig";
t.plan(2);
giteventsTwitter.init(fakeDataTalks, "custom", function (err, res) {
if (err) {
return console.error(err);
}
tweetsSent.push(res);
// wait for both tweets to be sent (i.e. stored in the array)
if (tweetsSent.length === 2) {
// may need to swap tweets around before check
if (tweetsSent[0] !== tweet1) {
tempTweet = tweetsSent[0];
tweetsSent[0] = tweetsSent[1];
tweetsSent[1] = tempTweet;
}
t.equal(tweetsSent[0], tweet1, 'tweet 1 matches expected result');
t.equal(tweetsSent[1], tweet2, 'tweet 2 matches expected result');
}
else if (tweetsSent.length > 2) {
t.fail('too many tweets sent');
}
});
});
function makeid(){
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}