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
|
testSupport.lib('xhr');
testSupport.lib('connection');
testSupport.lib('http/basic_auth');
testSupport.lib('http/oauth2');
suite('caldav/connection', function() {
var Connection;
var XHR;
var BasicAuth;
suiteSetup(function() {
Connection = Caldav.require('connection');
XHR = Caldav.require('xhr');
BasicAuth = Caldav.require('http/basic_auth');
});
var subject;
var user = 'foo';
var password = 'bar';
var domain = 'http://foo.com';
setup(function() {
subject = new Connection({
user: user,
password: password,
domain: domain
});
});
suite('initialization', function() {
test('assignment', function() {
assert.equal(subject.user, user);
assert.equal(subject.password, password);
assert.equal(subject.domain, domain);
});
test('when domain has trailing slash', function() {
subject = new Connection({
domain: domain + '/'
});
assert.equal(subject.domain, domain, 'should remove trailing slash');
});
});
suite('#request', function() {
function commonCases() {
test('url without domain', function() {
var request = subject.request({
url: 'bar.json'
});
// we add slash
assert.equal(request.url, domain + '/bar.json');
});
}
suite('basic auth (default)', function() {
test('credentails', function() {
var result = subject.request({
url: domain
});
assert.instanceOf(result, BasicAuth);
assert.equal(result.url, domain);
assert.equal(result.password, password);
assert.equal(result.user, user);
});
commonCases();
});
});
suite('#update', function() {
test('without .onupdate handler', function() {
subject.update({ x: true });
assert.equal(subject.x, true);
});
test('with handler', function(done) {
subject.onupdate = function() {
assert.equal(subject.oauth, 'foo');
done();
};
subject.update({ oauth: 'foo' });
});
});
});
|