aboutsummaryrefslogtreecommitdiffstats
path: root/test/caldav/connection_test.js
blob: fb32e8ec5835a1e594bbe9da647cab4446f28e00 (plain) (blame)
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
testSupport.lib('xhr');
testSupport.lib('connection');

suite('caldav/connection', function() {

  var subject;
  var Connection;
  var XHR;
  var user = 'foo';
  var password = 'bar';
  var domain = 'http://foo.com';

  suiteSetup(function() {
    Connection = Caldav.require('connection');
    XHR = Caldav.require('xhr');
  });

  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() {

    test('credentails', function() {
      var result = subject.request({
        url: domain
      });

      assert.instanceOf(result, XHR);
      assert.equal(result.url, domain);
      assert.equal(result.password, password);
      assert.equal(result.user, user);
    });

    test('url without domain', function() {
      var request = subject.request({
        url: 'bar.json'
      });

      // we add slash
      assert.equal(request.url, domain + '/bar.json');
    });

  });

});