aboutsummaryrefslogtreecommitdiffstats
path: root/test/caldav
diff options
context:
space:
mode:
Diffstat (limited to 'test/caldav')
-rw-r--r--test/caldav/errors_test.js27
-rw-r--r--test/caldav/http/basic_auth_test.js31
-rw-r--r--test/caldav/index_test.js1
-rw-r--r--test/caldav/request/abstract_test.js22
-rw-r--r--test/caldav/request/calendar_home_test.js28
5 files changed, 81 insertions, 28 deletions
diff --git a/test/caldav/errors_test.js b/test/caldav/errors_test.js
new file mode 100644
index 0000000..e02ea84
--- /dev/null
+++ b/test/caldav/errors_test.js
@@ -0,0 +1,27 @@
+testSupport.lib('errors');
+
+suite('errors/authentication', function() {
+ var Errors;
+
+ suiteSetup(function() {
+ Errors = Caldav.require('errors');
+ });
+
+ function verifyErrorExists(symbol) {
+ test(symbol, function() {
+ var error = new Errors[symbol]('oops');
+ assert.equal(error.message, 'oops');
+ assert.ok(error.name, 'has name');
+ assert.ok(error.stack, 'has stack');
+ });
+ }
+
+ // why grouped? gjslint hates us otherwise
+ ([
+ 'Authentication',
+ 'InvalidEntrypoint',
+ 'ServerFailure',
+ 'Unknown'
+ ]).forEach(verifyErrorExists);
+
+});
diff --git a/test/caldav/http/basic_auth_test.js b/test/caldav/http/basic_auth_test.js
index 566de08..a264d1b 100644
--- a/test/caldav/http/basic_auth_test.js
+++ b/test/caldav/http/basic_auth_test.js
@@ -39,19 +39,24 @@ suite('http/basic_auth', function() {
assert.equal(subject.url, url);
});
- test('#send', function() {
- var xhr = subject.send();
-
- assert.deepEqual(
- xhr.openArgs,
- [
- 'GET',
- url,
- subject.async,
- connection.user,
- connection.password
- ]
- );
+ suite('#send', function() {
+ test('success', function() {
+ var xhr = subject.send();
+
+ assert.deepEqual(
+ xhr.openArgs,
+ [
+ 'GET',
+ url,
+ subject.async,
+ connection.user,
+ connection.password
+ ]
+ );
+ });
+
+
+
});
});
diff --git a/test/caldav/index_test.js b/test/caldav/index_test.js
index baad822..d8f25b9 100644
--- a/test/caldav/index_test.js
+++ b/test/caldav/index_test.js
@@ -33,6 +33,7 @@ suite('caldav', function() {
assert.ok(root.Resources.Calendar, 'Calendar.Resources.Calendar');
assert.ok(root.OAuth2, 'OAuth2');
assert.ok(root.Http, 'Http');
+ assert.ok(root.Errors, 'Errors');
});
});
diff --git a/test/caldav/request/abstract_test.js b/test/caldav/request/abstract_test.js
index e2fb3d1..18d6bc3 100644
--- a/test/caldav/request/abstract_test.js
+++ b/test/caldav/request/abstract_test.js
@@ -77,22 +77,26 @@ suite('caldav/request/abstract.js', function() {
assert.deepEqual(con.password, req.password);
});
- suite('error', function() {
+ suite('errors', function() {
var calledWith;
- setup(function(done) {
+ setup(function() {
subject.send(function() {
calledWith = arguments;
- done();
});
-
- xhr = getXhr();
- xhr.respond('NOT XML <div>', 500);
});
- test('on response', function() {
- assert.equal(calledWith[0].code, 500);
- });
+ function verifyStatusFailure(status, name) {
+ test('status ' + status, function() {
+ xhr = getXhr();
+ xhr.respond('', status);
+ assert.equal(calledWith[0].name, name);
+ });
+ }
+
+ verifyStatusFailure(403, 'caldav-unknown');
+ verifyStatusFailure(401, 'caldav-authentication');
+ verifyStatusFailure(500, 'caldav-server-failure');
});
suite('success', function() {
diff --git a/test/caldav/request/calendar_home_test.js b/test/caldav/request/calendar_home_test.js
index 13483ad..6ed65fb 100644
--- a/test/caldav/request/calendar_home_test.js
+++ b/test/caldav/request/calendar_home_test.js
@@ -20,7 +20,7 @@ suite('caldav/request/propfind', function() {
Connection = Caldav.require('connection');
Home = Caldav.require('request/calendar_home');
MockRequest = Caldav.require('support/mock_request');
- Errors = Caldav.require('request/errors');
+ Errors = Caldav.require('errors');
});
suiteSetup(function() {
@@ -76,7 +76,7 @@ suite('caldav/request/propfind', function() {
response[url] = {
'current-user-principal': {
status: '200',
- value: { href:'foo.com/' }
+ value: { href: 'foo.com/' }
}
};
@@ -104,7 +104,7 @@ suite('caldav/request/propfind', function() {
assert.equal(data, 'bar.com/');
});
-
+
test('unauthenticated', function() {
var req = request('_findPrincipal');
@@ -116,12 +116,28 @@ suite('caldav/request/propfind', function() {
}
}
};
-
req.respond(null, response);
- assert.equal(true, err instanceof Errors.UnauthenticatedError);
+ assert.instanceOf(err, Errors.Authentication);
+ });
+
+ test('without href', function() {
+ var req = request('_findPrincipal');
+ response[url] = {
+ 'principal-URL': {}
+ };
+
+ req.respond(null, response);
+ assert.instanceOf(err, Errors.InvalidEntrypoint);
+ });
+
+ test('without useful response', function() {
+ var req = request('_findPrincipal');
+ response[url] = {};
+ req.respond(null, response);
+
+ assert.instanceOf(err, Errors.InvalidEntrypoint);
});
-
});
suite('#_findCalendarHome', function() {