From af18fcd4f38993eca144091944b816eaf2a8f0f3 Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Sat, 20 May 2017 21:50:35 +0200 Subject: [PATCH] Updated the tests about XML responses --- test/tests/copyPhysicalFolder.js | 2 +- test/tests/proppatch.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/test/tests/copyPhysicalFolder.js b/test/tests/copyPhysicalFolder.js index 4b295632..fe6e6889 100644 --- a/test/tests/copyPhysicalFolder.js +++ b/test/tests/copyPhysicalFolder.js @@ -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); diff --git a/test/tests/proppatch.js b/test/tests/proppatch.js index 9e629d07..1e0d8f9c 100644 --- a/test/tests/proppatch.js +++ b/test/tests/proppatch.js @@ -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 + ')'); } } @@ -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)) { @@ -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; @@ -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); }); })); }));