aboutsummaryrefslogtreecommitdiffstats
path: root/test/caldav/request/calendar_home_test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/caldav/request/calendar_home_test.js')
-rw-r--r--test/caldav/request/calendar_home_test.js143
1 files changed, 122 insertions, 21 deletions
diff --git a/test/caldav/request/calendar_home_test.js b/test/caldav/request/calendar_home_test.js
index 6df65df..b48c3b2 100644
--- a/test/caldav/request/calendar_home_test.js
+++ b/test/caldav/request/calendar_home_test.js
@@ -40,33 +40,134 @@ suite('caldav/request/propfind', function() {
assert.equal(subject.connection, con);
});
- test('_findPrincipal', function() {
- var err, data, response = {};
+ suite('requests', function() {
+ var err, data, response;
+
+ function request(method) {
+ subject[method](url, function() {
+ err = arguments[0];
+ data = arguments[1];
+ });
+
+ return MockPropfind.instances[MockPropfind.instances.length - 1];
+ }
+
+ setup(function() {
+ err = null;
+ data = null;
+ response = {};
+ });
+
+ suite('#_findPrincipal', function() {
+
+ test('with current-user-principal', function() {
+ var req = request('_findPrincipal');
+
+ assert.equal(req.options.url, url);
+
+ assert.deepEqual(req.propCalls, [
+ ['current-user-principal'],
+ ['principal-URL']
+ ]);
+
+
+ response[url] = {
+ 'current-user-principal': {
+ status: '200',
+ value: 'foo.com/'
+ }
+ };
+
+ // respond to request
+ req.respond(null, response);
- subject._findPrincipal(url, function() {
- err = arguments[0];
- data = arguments[1];
+ assert.equal(data, 'foo.com/');
+ });
+
+ test('with principal-URL', function() {
+ var req = request('_findPrincipal');
+
+ response[url] = {
+ 'current-user-principal': {
+ status: '404',
+ value: {}
+ },
+ 'principal-URL': {
+ status: '200',
+ value: 'bar.com/'
+ }
+ };
+
+ req.respond(null, response);
+
+ assert.equal(data, 'bar.com/');
+ });
});
- var req = MockPropfind.instances[0];
- assert.equal(req.options.url, url);
- assert.deepEqual(req.propCalls, [
- ['current-user-principal'],
- ['principal-URL']
- ]);
-
- response[url] = {
- 'current-user-principal': {
- status: '200',
- value: 'foo.com/'
+ suite('#_findCalendarHome', function() {
+ test('success', function() {
+ var req = request('_findCalendarHome');
+
+ assert.equal(req.options.url, url);
+ assert.deepEqual(req.propCalls, [
+ [['caldav', 'calendar-home-set']]
+ ]);
+
+ response[url] = {
+ 'calendar-home-set': {
+ status: '200',
+ value: 'bar.com/'
+ }
+ };
+
+ req.respond(null, response);
+
+ assert.deepEqual(data, {
+ url: 'bar.com/'
+ });
+ });
+ });
+
+
+ suite('#send', function() {
+
+ function mockCallback(obj, method) {
+ var calledWith = {};
+ var calls = 0;
+
+ obj[method] = function() {
+ if (calls.length > 1) {
+ throw new Error(method + ' called more then once');
+ }
+
+ calledWith.args = arguments;
+ };
+
+ return calledWith;
}
- };
- // respond to request
- req.respond(null, response);
+ test('success', function() {
+ var expected = { url: 'foo.com' };
+ var principal = mockCallback(subject, '_findPrincipal');
+ var home = mockCallback(subject, '_findCalendarHome');
+
+ subject.send(function() {
+ err = arguments[0];
+ data = arguments[1];
+ });
+
+ assert.equal(principal.args[0], subject.url);
+ principal.args[1](null, 'baz.com');
+
+ assert.equal(home.args[0], 'baz.com');
+ home.args[1](null, expected);
+
+ assert.deepEqual(data, {
+ url: 'foo.com'
+ });
+ });
+ });
- assert.equal(data, 'foo.com/');
});
});
-