-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathspecialUrlEmitter.js
More file actions
125 lines (107 loc) · 3.42 KB
/
specialUrlEmitter.js
File metadata and controls
125 lines (107 loc) · 3.42 KB
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
var rewire = require('rewire');
var sinon = require('sinon');
var assert = require('chai').assert;
var specialUrlEmitterModule = rewire('../lib/specialUrlEmitter');
describe('SpecialUrlEmitter module:', function() {
var specialUrlEmitter;
before(function() {
var pathPrefix;
var sshCredentials = function() {
};
var logFunction = function() {
};
specialUrlEmitter = specialUrlEmitterModule(
pathPrefix,
sshCredentials,
logFunction);
});
describe('emitEventUrlToClient()', function() {
it('can be called', function() {
var connection = {
on: function() {
},
connect: function() {
}
};
var ssh2 = function() {
return connection;
};
var revert = specialUrlEmitterModule.__set__("ssh2", ssh2);
specialUrlEmitter.emitEventUrlToClient("user12", "eventType");
revert();
});
it('should call emit for file', function() {
var spy = sinon.spy();
var revert = specialUrlEmitterModule
.__set__("emitUrlForUserGeneratedFileToClient", spy);
specialUrlEmitter.emitEventUrlToClient("user12", "eventType");
assert(spy.called, "emitUrlForUserGeneratedFile was never called");
revert();
});
it('can be called with vieHelp', function() {
var connection = {
on: function() {
},
connect: function() {
}
};
var ssh2 = function() {
return connection;
};
var revert = specialUrlEmitterModule.__set__("ssh2", ssh2);
var revertIsViewHelpEvent = specialUrlEmitterModule
.__set__("isViewHelpEvent", function() {
return true;
});
specialUrlEmitter.emitEventUrlToClient("user12", "eventType");
revert();
revertIsViewHelpEvent();
});
it('emits correct URL for viewHelp', function() {
var spy = sinon.spy();
var revert = specialUrlEmitterModule
.__set__("emitHelpUrlToClient", spy);
var revertIsViewHelpEvent = specialUrlEmitterModule
.__set__("isViewHelpEvent", function() {
return true;
});
specialUrlEmitter.emitEventUrlToClient("user12", "eventType");
assert(spy.called, "emitHelpUrlToClient was never called");
revert();
revertIsViewHelpEvent();
});
});
describe('isSpecial()', function() {
it('should match special data', function() {
var data = ">>SPECIAL_EVENT_START>>special<<SPECIAL_EVENT_END";
assert.equal(specialUrlEmitter.isSpecial(data), "special");
});
it('should return false', function() {
var data = ">>SPECIAL_EVENT_START>>";
assert.isFalse(specialUrlEmitter.isSpecial(data),
data + " should not be special.");
});
});
describe('isViewHelpEvent', function() {
var isViewHelpEvent;
before(function() {
isViewHelpEvent = specialUrlEmitterModule.__get__("isViewHelpEvent");
});
it('should match on file:', function() {
var data = "file:";
assert.isTrue(isViewHelpEvent(data));
});
it('should match on file:something', function() {
var data = "file:something";
assert.isTrue(isViewHelpEvent(data));
});
it('should not match', function() {
var data = "somethingfile:";
assert.isFalse(isViewHelpEvent(data));
});
it('should not on empty string', function() {
var data = "";
assert.isFalse(isViewHelpEvent(data));
});
});
});