aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2012-06-26 12:16:49 +0200
committerJames Lal <james@lightsofapollo.com>2012-06-26 12:16:49 +0200
commit816243091b923cc64d87250f8cbd0854a1348312 (patch)
tree1b28fa3a5a357507fdf848b370230a3b5d3dad0a /test
parente961e32348203c71bfae7a9142f5d7c0b8ef4e6f (diff)
downloadjsCalDAV-816243091b923cc64d87250f8cbd0854a1348312.tar.gz
Basic propfind request
Diffstat (limited to 'test')
-rw-r--r--test/webcals/request/abstract_test.js10
-rw-r--r--test/webcals/request/propfind_test.js109
2 files changed, 114 insertions, 5 deletions
diff --git a/test/webcals/request/abstract_test.js b/test/webcals/request/abstract_test.js
index 124a135..0acb42b 100644
--- a/test/webcals/request/abstract_test.js
+++ b/test/webcals/request/abstract_test.js
@@ -31,10 +31,10 @@ suite('webcals/request/abstract.js', function() {
FakeXhr.instances.length = 0;
});
- test('#_createXhr', function() {
- var result = subject._createXhr();
- assert.instanceOf(result, Xhr);
- assert.equal(result.url, url);
+ test('.xhr', function() {
+ var xhr = subject.xhr;
+ assert.instanceOf(xhr, Xhr);
+ assert.equal(xhr.url, url);
});
test('#_createPayload', function() {
@@ -84,7 +84,7 @@ suite('webcals/request/abstract.js', function() {
});
xhr = getXhr();
- xhr.respond(xml, 200);
+ xhr.respond(xml, 207);
});
test('on response', function() {
diff --git a/test/webcals/request/propfind_test.js b/test/webcals/request/propfind_test.js
new file mode 100644
index 0000000..998fd2f
--- /dev/null
+++ b/test/webcals/request/propfind_test.js
@@ -0,0 +1,109 @@
+requireRequest();
+
+suite('webcals/request/propfind', function() {
+ var Abstract,
+ Propfind,
+ FakeXhr,
+ Xhr,
+ Template,
+ oldXhrClass,
+ SaxResponse;
+
+ var url = 'http://google.com',
+ subject;
+
+ suiteSetup(function() {
+ Abstract = Webcals.require('request/abstract');
+ Propfind = Webcals.require('request/propfind');
+ SaxResponse = Webcals.require('sax/dav_response');
+ FakeXhr = Webcals.require('support/fake_xhr');
+ Template = Webcals.require('template');
+ Xhr = Webcals.require('xhr');
+
+ oldXhrClass = Xhr.prototype.xhrClass;
+ Xhr.prototype.xhrClass = FakeXhr;
+ });
+
+ suiteTeardown(function() {
+ Xhr.prototype.xhrClass = oldXhrClass;
+ });
+
+ setup(function() {
+ subject = new Propfind(url);
+ FakeXhr.instances.length = 0;
+ });
+
+ test('initializer', function() {
+ assert.instanceOf(subject, Abstract);
+ assert.instanceOf(subject.template, Template);
+ assert.deepEqual(subject._props, []);
+ assert.equal(
+ subject.sax.handles['DAV:/response'],
+ SaxResponse
+ );
+
+ assert.equal(subject.xhr.headers['Depth'], 0);
+ assert.equal(subject.xhr.method, 'PROPFIND');
+ });
+
+ test('#prop', function() {
+ var expected = subject.template.tag('test');
+
+ subject.prop('test');
+
+ assert.deepEqual(subject._props, [expected]);
+ });
+
+ test('#_createPayload', function() {
+ subject.prop('foo');
+ subject.prop('bar');
+
+ var tags = [
+ '<N0:foo />',
+ '<N0:bar />'
+ ].join('');
+
+ var expected = [
+ subject.template.doctype,
+ '<N0:propfind xmlns:N0="DAV:">',
+ '<N0:prop>', tags, '</N0:prop>',
+ '</N0:propfind>'
+ ].join('');
+
+ var result = subject._createPayload();
+
+ console.log(result);
+
+ assert.equal(subject._createPayload(), expected);
+ });
+
+ suite('integration', function() {
+ var xml,
+ data,
+ result,
+ xhr,
+ calledWith;
+
+ defineSample('xml/propget.xml', function(data) {
+ xml = data;
+ });
+
+ setup(function(done) {
+ subject.prop('foo');
+
+ subject.send(function(err, tree) {
+ data = tree;
+ done();
+ });
+
+ xhr = FakeXhr.instances.pop();
+ xhr.respond(xml, 207);
+ });
+
+ test('simple tree', function() {
+ assert.ok(data.multistatus);
+ assert.ok(data.multistatus['/calendar/user/']);
+ });
+ });
+
+});