forked from smfreegard/Haraka
/
relay_all.js
74 lines (64 loc) · 2.21 KB
/
relay_all.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
var stub = require('../fixtures/stub'),
constants = require('../../constants'),
Connection = require('../fixtures/stub_connection'),
Plugin = require('../fixtures/stub_plugin');
// huge hack here, but plugin tests need constants
constants.import(global);
function _set_up(callback) {
this.backup = {};
// needed for tests
this.plugin = Plugin('relay_all');
this.connection = Connection.createConnection();
this.params = ['foo@bar.com'];
// stub out functions
this.connection.loginfo = stub();
// going to need these in multiple tests
this.plugin.register();
callback();
}
function _tear_down(callback) {
callback();
}
exports.relay_all = {
setUp : _set_up,
tearDown : _tear_down,
'should have register function' : function (test) {
test.expect(2);
test.isNotNull(this.plugin);
test.isFunction(this.plugin.register);
test.done();
},
'register function should call register_hook()' : function (test) {
test.expect(1);
test.ok(this.plugin.register_hook.called);
test.done();
},
'register_hook() should register for propper hook' : function (test) {
test.expect(1);
test.equals(this.plugin.register_hook.args[0], 'rcpt');
test.done();
},
'register_hook() should register available function' : function (test) {
test.expect(3);
test.equals(this.plugin.register_hook.args[1], 'confirm_all');
test.isNotNull(this.plugin.confirm_all);
test.isFunction(this.plugin.confirm_all);
test.done();
},
'confirm_all hook always returns OK' : function (test) {
var next = function (action) {
test.expect(1);
test.equals(action, constants.ok);
test.done();
};
this.plugin.confirm_all(next, this.connection, this.params);
},
'confirm_all hook always sets connection.relaying to 1' : function (test) {
var next = function (action) {
test.expect(1);
test.equals(this.connection.relaying, 1);
test.done();
}.bind(this);
this.plugin.confirm_all(next, this.connection, this.params);
}
};