aboutsummaryrefslogtreecommitdiffstats
path: root/test/webcals/sax/dav_response_test.js
blob: 70d1c0b01775f07ef7432e52c6bd9b7a1ddc514d (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
testSupport.lib('sax');
testSupport.lib('sax/base');
testSupport.lib('sax/dav_response');
testSupport.lib('ical');

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

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


  suiteSetup(function() {
    Parse = Webcals.require('sax');
    Base = Webcals.require('sax/base');
    Response = Webcals.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('parsing', 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: {}
        }
      },

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

    };

    test('output', function(done) {
      subject.once('complete', function(data) {
        assert.deepEqual(
          data.multistatus, expected,
          "expected \n '" + JSON.stringify(data.multistatus) +
          "'\n to equal \n '" + JSON.stringify(expected) + '\n"'
        );
        done();
      });
      subject.write(xml).close();
    });
  });

});