aboutsummaryrefslogtreecommitdiffstats
path: root/test/caldav/sax/dav_response_test.js
blob: cb3d2b799b44af4b58c8d45396b13ca074a2af0d (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
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
126
127
128
129
130
131
testSupport.lib('responder');
testSupport.lib('sax');
testSupport.lib('sax/base');
testSupport.lib('ical');
testSupport.lib('sax/dav_response');
require('/lib/ical.js');

suite('caldav/sax/dav_response', function() {

  var data,
      subject,
      parser,
      Parse,
      Response,
      Base,
      handler;


  suiteSetup(function() {
    Parse = Caldav.require('sax');
    Base = Caldav.require('sax/base');
    Response = Caldav.require('sax/dav_response');
  });

  setup(function() {
    //we omit the option to pass base parser
    //because we are the base parser
    subject = new Parse();
    subject.registerHandler('DAV:/response', Response);
  });

  suite('calendar-query', function() {
    var xml;

    testSupport.defineSample('xml/calendar_query_single.xml', function(data) {
      xml = data;
    });

    test('result', function(done) {
      subject.once('complete', function(data) {
        var response = data.multistatus;
        var event = response['event.ics'];
        assert.ok(event);

        assert.ok(event['calendar-data'].value.name, 'name');
        assert.ok(event['calendar-data'].value.value, 'value');
        done();
      });

      subject.write(xml).close();
    });
  });

  suite('propget', function() {
    var xml;

    testSupport.defineSample('xml/propget.xml', function(data) {
      xml = data;
    });

    expected = {
      '/calendar/user/': {

        'principal-URL': {
          status: '200',
          value: '/calendar/pinc/'
        },

        resourcetype: {
          status: '200',
          value: [
            'principal',
            'collection'
          ]
        },

        'current-user-principal': {
          status: '404',
          value: null
        }
      },

      '/calendar/other': {
        missing: {
          status: '200',
          value: {}
        }
      }

    };

    test('output', function(done) {
      var response = [];

      subject.on('DAV:/response', function(url, data) {
        response.push([url, data]);
      });


      subject.once('complete', function(data) {
        assert.deepEqual(
          data.multistatus, expected,
          "expected \n '" + JSON.stringify(data.multistatus) +
          "'\n to equal \n '" + JSON.stringify(expected) + '\n"'
        );

        assert.deepEqual(
          [
            '/calendar/user/',
            expected['/calendar/user/']
          ],
          response[0],
          '/calendar/user/ response'
        );

        assert.deepEqual(
          [
            '/calendar/other',
            expected['/calendar/other']
          ],
          response[1],
          '/calendar/other/ response'
        );

        done();
      });
      subject.write(xml).close();
    });
  });

});