aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJames Lal <james@lightsofapollo.com>2013-05-06 21:18:31 -0700
committerJames Lal <james@lightsofapollo.com>2013-05-06 21:18:31 -0700
commit0b4733ebb28368198b747079d51033a7eeb1f276 (patch)
tree0d48aca900256baf82f0aa599d455a978780fa19 /test
parentc81e925aa6dada192db75dccd4287ab1e9e09ab2 (diff)
downloadjsCalDAV-0b4733ebb28368198b747079d51033a7eeb1f276.tar.gz
Initial error refactoring (make errors less HTTP specific)
Diffstat (limited to 'test')
-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
-rw-r--r--test/helper.js4
-rw-r--r--test/support/fake_xhr.js3
7 files changed, 84 insertions, 32 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() {
diff --git a/test/helper.js b/test/helper.js
index 5cf8d5f..92585f5 100644
--- a/test/helper.js
+++ b/test/helper.js
@@ -204,7 +204,10 @@
/* since we have global mocks easier to just include these globally */
requireRequest = function(callback) {
+ testSupport.helper('fake_xhr');
testSupport.lib('responder');
+ testSupport.lib('errors');
+ testSupport.lib('xhr');
testSupport.lib('oauth2');
testSupport.lib('http/basic_auth');
testSupport.lib('http/oauth2');
@@ -212,7 +215,6 @@
testSupport.lib('sax');
testSupport.lib('sax/base');
testSupport.lib('sax/dav_response');
- testSupport.lib('request/errors');
testSupport.lib('request/abstract');
testSupport.lib('template');
testSupport.lib('request/propfind');
diff --git a/test/support/fake_xhr.js b/test/support/fake_xhr.js
index 3f6cea0..59c6598 100644
--- a/test/support/fake_xhr.js
+++ b/test/support/fake_xhr.js
@@ -1,6 +1,4 @@
(function(module) {
- console.log('I HAZ LOADED');
-
function FakeXhr() {
this.openArgs = null;
this.sendArgs = null;
@@ -44,7 +42,6 @@
}
};
- console.log('EXPORTS ME', FakeXhr);
module.exports = FakeXhr;
}.apply(