aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-07-07 16:33:27 -0700
committerJames Lal <james@lightsofapollo.com>2012-07-07 16:33:27 -0700
commitee8dac6ecd2927d6ea1930ae478ff65766b446d9 (patch)
treef6482199d2a3fd6d57ee60e4ca659ebe9a82da4e /test
parentccf8b1382cd6a72abc93b837e5c39272df9c2d72 (diff)
downloadjsCalDAV-ee8dac6ecd2927d6ea1930ae478ff65766b446d9.tar.gz
resources request
Diffstat (limited to 'test')
-rw-r--r--test/caldav/request/resources_test.js103
-rw-r--r--test/caldav/resource_root_test.js5
2 files changed, 103 insertions, 5 deletions
diff --git a/test/caldav/request/resources_test.js b/test/caldav/request/resources_test.js
new file mode 100644
index 0000000..c8a8675
--- /dev/null
+++ b/test/caldav/request/resources_test.js
@@ -0,0 +1,103 @@
+requireRequest();
+testSupport.lib('request/propfind');
+testSupport.lib('request/resources');
+testSupport.helper('mock_request');
+
+suite('caldav/resource_finder', function() {
+
+ var Connection;
+ var MockRequest;
+ var MockPropfind;
+ var Propfind;
+ var Finder;
+ var subject;
+ var con;
+
+ var url = 'http://google.com',
+ subject;
+
+ suiteSetup(function() {
+ Connection = Caldav.require('connection');
+ Finder = Caldav.require('request/resources');
+ Propfind = Caldav.require('request/propfind');
+ MockRequest = Caldav.require('support/mock_request');
+ });
+
+ suiteSetup(function() {
+ MockPropfind = MockRequest.create(['prop']);
+ });
+
+ setup(function() {
+ MockPropfind.reset();
+
+ con = new Connection();
+ subject = new Finder(con, {
+ url: url,
+ Propfind: MockPropfind
+ });
+
+ });
+
+ test('initializer', function() {
+ assert.equal(subject.url, url);
+ assert.equal(subject.connection, con);
+ assert.deepEqual(subject._resources, {});
+ assert.instanceOf(subject, Propfind);
+ assert.equal(subject.depth, 1);
+ });
+
+ test('#addResource', function() {
+ var fn = function() {};
+
+ subject.addResource('foo', fn);
+
+ assert.equal(subject._resources['foo'], fn);
+ });
+
+ suite('#_processResult', function() {
+
+ var Handler = function() {
+ this.args = arguments;
+ };
+
+ function status(value, status) {
+ if (typeof(status) === 'undefined') {
+ status = '200';
+ }
+
+ return { value: value, status: status };
+ }
+
+ function resource(name, type) {
+ return {
+ name: status(name),
+ resourcetype: [type]
+ };
+ }
+
+ setup(function() {
+ subject.addResource('calendar', Handler);
+ });
+
+ test('handled & unhandled resource', function() {
+ var result;
+ var input = {
+ 'a': resource('1', 'calendar'),
+ 'b': resource('2', 'other')
+ };
+
+ subject.sax.root = { multistatus: input };
+ subject._processResult(null, function(err, data) {
+ result = data;
+ });
+
+ assert.ok(result.calendar['a']);
+ assert.instanceOf(result.calendar['a'], Handler);
+ assert.equal(Object.keys(result.calendar).length, 1);
+
+ assert.equal(result.calendar['a'].args[1].name.value, '1');
+ });
+
+ });
+
+});
diff --git a/test/caldav/resource_root_test.js b/test/caldav/resource_root_test.js
deleted file mode 100644
index 4af8286..0000000
--- a/test/caldav/resource_root_test.js
+++ /dev/null
@@ -1,5 +0,0 @@
-testSupport.lib('template');
-
-suite('resource_root', function() {
-
-});