aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-06-18 20:51:13 -0700
committerJames Lal <james@lightsofapollo.com>2012-06-18 20:51:13 -0700
commita6c747412c0960331e4055eee97d8328ff88d584 (patch)
treec4a82365e592a2d1cfa46cd0f5f595dde6626ff8 /test
downloadjsCalDAV-a6c747412c0960331e4055eee97d8328ff88d584.tar.gz
Initial hack
Diffstat (limited to 'test')
-rw-r--r--test/caldav/ics_test.js15
-rw-r--r--test/caldav/sax/propstat_test.js27
-rw-r--r--test/caldav/sax_test.js93
-rw-r--r--test/helper.js16
4 files changed, 151 insertions, 0 deletions
diff --git a/test/caldav/ics_test.js b/test/caldav/ics_test.js
new file mode 100644
index 0000000..3f821b4
--- /dev/null
+++ b/test/caldav/ics_test.js
@@ -0,0 +1,15 @@
+var fs = require('fs'),
+ ics = requireLib('ics'),
+ data = fs.readFileSync(__dirname + '/../../data/test.data', 'utf8');
+
+suite('caldav/ics', function() {
+
+ test('intiailizer', function() {
+ ics(data, function(data) {
+ console.log(data.vevent[0]);
+ }, function() {
+ console.log('y');
+ })
+ });
+
+});
diff --git a/test/caldav/sax/propstat_test.js b/test/caldav/sax/propstat_test.js
new file mode 100644
index 0000000..74360a7
--- /dev/null
+++ b/test/caldav/sax/propstat_test.js
@@ -0,0 +1,27 @@
+suite('caldav/sax/propstat', function() {
+ var stat = requireLib('sax/propstat'),
+ sax = requireLib('sax'),
+ subject;
+
+ var expected = {
+ status: 200,
+ 'principal-URL': '/calendar/dav/calmozilla1@gmail.com/user/',
+ 'resource-type': [
+ 'principal',
+ 'collection'
+ ]
+ };
+
+ test('propstat success', function(done) {
+ var parser = sax();
+
+ console.log(parser.on);
+ stat(parser, function(err, result) {
+ console.log(result);
+ done();
+ });
+
+ parser.write(loadSample('xml/propstat-success.xml')).close();
+ });
+
+});
diff --git a/test/caldav/sax_test.js b/test/caldav/sax_test.js
new file mode 100644
index 0000000..83d69c1
--- /dev/null
+++ b/test/caldav/sax_test.js
@@ -0,0 +1,93 @@
+var xml = requireLib('sax');
+
+suite('sax test', function() {
+
+ var data,
+ subject;
+
+ test('existance', function() {
+ var parser = new xml();
+
+ var StatusHandler = {
+ tag: 'DAV:/status',
+
+ onopentag: function(data) {
+ },
+
+ ontext: function(data) {
+ this.current.status = data.match(/([0-9]{3,3})/)[1];
+ },
+
+ onclosetag: function(data) {
+ this.restoreParser();
+ }
+ };
+
+ var ResourceTypeHandler = {
+ tag: 'DAV:/resourcetype',
+
+ onopentag: function(data) {
+ this.tagStack.push(data.tagSpec);
+
+ if (data.local === 'resourcetype') {
+ this.current.resourceTypes = [];
+ } else {
+ this.current.resourceTypes.push(data.local);
+ }
+ },
+
+ onclosetag: function(data) {
+ this.checkStackForHandler(true);
+ this.tagStack.pop();
+ }
+ };
+
+ var TextOnlyHandler = {
+ tag: 'DAV:/href',
+
+ onopentag: function(data) {
+ },
+
+ ontext: function(data) {
+ this.current.href = data;
+ },
+
+ onclosetag: function(data) {
+ this.restoreParser();
+ }
+ };
+
+ var ResponseHandler = {
+ tag: 'DAV:/response',
+ handles: {
+ 'DAV:/status': StatusHandler,
+ 'DAV:/resourcetype': ResourceTypeHandler,
+ 'DAV:/href': TextOnlyHandler,
+ 'DAV:/getetag': TextOnlyHandler
+ },
+
+ onclosetag: function(data) {
+ this.checkStackForHandler(true);
+ this.onclosetag(data);
+ },
+
+ oncomplete: function() {
+ this.emit('response', this.current, this);
+ }
+
+ };
+
+ parser.addHandler(ResponseHandler);
+
+ parser.on('response', function(data, context) {
+ console.log(JSON.stringify(data), '\n\n');
+ });
+
+ parser.once('complete', function(data, parser) {
+ console.log(JSON.stringify(data));
+ });
+
+ parser.write(data).close();
+ });
+
+});
diff --git a/test/helper.js b/test/helper.js
new file mode 100644
index 0000000..9f40311
--- /dev/null
+++ b/test/helper.js
@@ -0,0 +1,16 @@
+var chai = require('chai'),
+ fs = require('fs');
+
+chai.Assertion.includeStack = true;
+assert = chai.assert;
+
+loadSample = function(file, cb) {
+ var root = __dirname + '/../samples/';
+ fs.readFile(root + file, 'utf8', function(err, contents) {
+ cb(err, contents);
+ });
+};
+
+requireLib = function(lib) {
+ return require(__dirname + '/../lib/caldav/' + lib);
+};