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
|
requireRequest();
testSupport.lib('request/propfind');
testSupport.lib('request/resources');
testSupport.helper('mock_request');
suite('caldav/resource_finder', function() {
var Connection;
var MockRequest;
var MockPropfind;
var Propfind;
var Finder;
var subject;
var con;
var url = 'http://google.com',
subject;
suiteSetup(function() {
Connection = Caldav.require('connection');
Finder = Caldav.require('request/resources');
Propfind = Caldav.require('request/propfind');
MockRequest = Caldav.require('support/mock_request');
});
suiteSetup(function() {
MockPropfind = MockRequest.create(['prop']);
});
setup(function() {
MockPropfind.reset();
con = new Connection();
subject = new Finder(con, {
url: url,
Propfind: MockPropfind
});
});
test('initializer', function() {
assert.equal(subject.url, url);
assert.equal(subject.connection, con);
assert.deepEqual(subject._resources, {});
assert.instanceOf(subject, Propfind);
assert.equal(subject.depth, 1);
});
test('#addResource', function() {
var fn = function() {};
subject.addResource('foo', fn);
assert.equal(subject._resources['foo'], fn);
});
suite('#_processResult', function() {
var Handler = function() {
this.args = arguments;
};
function status(value, status) {
if (typeof(status) === 'undefined') {
status = '200';
}
return { value: value, status: status };
}
function resource(name, type) {
return {
name: status(name),
resourcetype: status([type])
};
}
setup(function() {
subject.addResource('calendar', Handler);
});
test('handled & unhandled resource', function() {
var result;
var input = {
'a': resource('1', 'calendar'),
'b': resource('2', 'other')
};
subject.sax.root = { multistatus: input };
subject._processResult(null, function(err, data) {
result = data;
});
assert.ok(result.calendar['a']);
var cal = result.calendar['a'];
assert.instanceOf(cal, Handler);
assert.equal(Object.keys(result.calendar).length, 1);
assert.equal(cal.args[1].name.value, '1');
assert.equal(cal.url, 'a');
});
});
});
|