Skip to content

Commit

Permalink
Updated the tests about XML responses
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 20, 2017
1 parent 2f02c2b commit af18fcd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/tests/copyPhysicalFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var webdav = require('../../lib/index.js'),
path = require('path'),
fs = require('fs');

module.exports = (test, options, index) => test('copy a virtual folder', isValid =>
module.exports = (test, options, index) => test('copy a physical folder', isValid =>
{
var server = new webdav.WebDAVServer();
server.start(options.port + index);
Expand Down
12 changes: 8 additions & 4 deletions test/tests/proppatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = (test, options, index) => test('PROPPATCH method', isValid =>
}
catch(e)
{
isValid(false, 'Bad response body for ' + (isJSON ? 'JSON' : 'XML') + ' reponse.');
isValid(false, 'Bad response body for ' + (isJSON ? 'JSON' : 'XML') + ' response. (' + e + ')');
}
}

Expand All @@ -66,8 +66,10 @@ module.exports = (test, options, index) => test('PROPPATCH method', isValid =>
tryCatch(() => {
const xml = isJSON ? JSON.parse(body) : xmljs.xml2js(body, { compact: true, alwaysArray: true });
const response = xml['D:multistatus'][0]['D:response'][0];
const prop = response['D:propstat'][0]['D:prop'][0];
const authorsKey = Object.keys(prop).find((k) => k.endsWith(':Authors'));

if(!(response['D:propstat'][0]['D:prop'][0]['x:Authors'].length === 1 &&
if(!(prop[authorsKey].length === 1 &&
response['D:propstat'][0]['D:status'][0]._text[0].indexOf('HTTP/1.1 20') === 0 &&
response['D:href'][0]._text[0] === url))
{
Expand All @@ -85,8 +87,9 @@ module.exports = (test, options, index) => test('PROPPATCH method', isValid =>
tryCatch(() => {
const xml = isJSON ? JSON.parse(body) : xmljs.xml2js(body, { compact: true, alwaysArray: true });
const prop = xml['D:multistatus'][0]['D:response'][0]['D:propstat'][0]['D:prop'][0];
const authorsKey = Object.keys(prop).find((k) => k.endsWith(':Authors'));

if(prop['x:Authors'].length !== 1)
if(prop[authorsKey].length !== 1)
{
isValid(false);
return;
Expand All @@ -111,8 +114,9 @@ module.exports = (test, options, index) => test('PROPPATCH method', isValid =>
tryCatch(() => {
const xml = isJSON ? JSON.parse(body) : xmljs.xml2js(body, { compact: true, alwaysArray: true });
const prop = xml['D:multistatus'][0]['D:response'][0]['D:propstat'][0]['D:prop'][0];
const authorsKey = Object.keys(prop).find((k) => k.endsWith(':Authors'));

isValid(prop['x:Authors'] === undefined);
isValid(authorsKey === undefined);
});
}));
}));
Expand Down

0 comments on commit af18fcd

Please sign in to comment.