requireRequest();
testSupport.lib('request/propfind');
testSupport.lib('request/calendar_query');
suite('caldav/request/calendar_query', function() {
var Propfind,
FakeXhr,
CalendarData,
CalendarQuery,
CalendarFilter,
Xhr,
Template,
oldXhrClass,
SaxResponse;
var url = 'http://google.com',
subject;
suiteSetup(function() {
Propfind = Caldav.require('request/propfind');
CalendarData = Caldav.require('templates/calendar_data');
CalendarFilter = Caldav.require('templates/calendar_filter');
CalendarQuery = Caldav.require('request/calendar_query');
SaxResponse = Caldav.require('sax/dav_response');
FakeXhr = Caldav.require('support/fake_xhr');
Template = Caldav.require('template');
Xhr = Caldav.require('xhr');
oldXhrClass = Xhr.prototype.xhrClass;
Xhr.prototype.xhrClass = FakeXhr;
});
suiteTeardown(function() {
Xhr.prototype.xhrClass = oldXhrClass;
});
setup(function() {
subject = new CalendarQuery(url);
FakeXhr.instances.length = 0;
});
test('initializer', function() {
assert.instanceOf(subject, Propfind);
assert.deepEqual(subject._props, []);
assert.equal(subject.xhr.headers['Depth'], 1);
assert.equal(subject.xhr.method, 'REPORT');
assert.instanceOf(subject.fields, CalendarData);
assert.instanceOf(subject.filters, CalendarFilter);
});
test('#_createPayload', function() {
subject.prop('getetag');
subject.fields.select('VEVENT', ['NAME']);
subject.filters.add('VEVENT', true);
var props = [
'',
'',
'',
'',
'',
'',
'',
''
].join('');
var filter = [
'',
'',
''
].join('');
var expected = [
subject.template.doctype,
'',
'', props, '',
'', filter, '',
''
].join('');
assert.equal(subject._createPayload(), expected);
});
suite('integration', function() {
return;
var xml,
data,
result,
xhr,
calledWith;
testSupport.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['/calendar/user/']);
});
});
});