-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnitpin.js
96 lines (72 loc) · 2.39 KB
/
nitpin.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
var assert = require('assert'),
Nitpin = require('../index.js'),
server,
worker;
describe('Nitpin', function() {
describe('new Nitpin()', function() {
it('should create a new Nitpin object', function() {
// Create new object with the open php.net servers
server = new Nitpin({
host: 'news.php.net',
user: null,
pass: null,
port: 119,
secure: false,
connections: 1
});
assert.strictEqual(server.constructor.name, 'Nitpin');
});
});
describe('#getSocket()', function() {
it('should return a NitpinWorker', function() {
worker = server.getSocket();
});
it('should emit a connected event', function(done) {
// It could take a while before the server connects
this.timeout(5000);
worker.after('connected', function() {
done();
});
});
it('should emit an authenticated event (even without requiring login)', function(done) {
worker.after('authenticated', function() {
done();
});
});
});
describe('#over(group, low, high, callback)', function() {
it('should get an overview of messages', function(done) {
server.over('php.doc.nl', 2, 5, function gotMessages(err, messages) {
// There should be no errors
assert.strictEqual(err, null);
// There should be 4 messages
assert.strictEqual(messages.length, 4);
// The first message should have id 2
assert.strictEqual(messages[0].id, '2');
// The last message should have id 5
assert.strictEqual(messages[3].id, '5');
done();
});
});
it('should return an error if the group does not exist', function(done) {
server.over('non.existing.group', 2, 5, function gotMessages(err, messages) {
assert.strictEqual(err.code, 411, 'Error code should be 411');
assert.strictEqual(messages, undefined, 'Messages should be undefined');
done();
});
});
});
describe('#getArticle(group, articleId, callback)', function() {
it('should return the article with headers & body', function(done) {
server.getArticle('php.doc.nl', '[email protected]', function gotArticle(err, headers, body) {
// Error should be null
assert.strictEqual(err, null);
// Headers should be set
assert.strictEqual(headers.subject, 'test');
assert.strictEqual(headers.date, 'Mon, 24 Jun 2002 14');
assert.strictEqual(body.indexOf('JDI Media Solutions') > -1, true);
done();
});
});
});
});