//
// SPDX-License-Identifier: AGPL-3.0
-import { CollectionFile } from '~/models/collection-file';
+import { CollectionFile } from 'models/collection-file';
import { getFileFullPath, extractFilesData } from './collection-service-files-response';
describe('collection-service-files-response', () => {
describe('extractFilesData', () => {
- it('should extract', () => {
- // given
- const xmlString = '<D:multistatus xmlns:D="DAV:"><D:response><D:href>/c=xxxxx-zzzzz-vvvvvvvvvvvvvvv/</D:href><D:propstat><D:prop><D:resourcetype><D:collection xmlns:D="DAV:"/></D:resourcetype><D:getlastmodified>Wed, 24 Feb 2021 22:16:19 GMT</D:getlastmodified><D:supportedlock><D:lockentry xmlns:D="DAV:"><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock><D:displayname></D:displayname></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response><D:response><D:href>/c=zzzzz-xxxxx-vvvvvvvvvvvvvvv/2</D:href><D:propstat><D:prop><D:getcontentlength>1582976</D:getcontentlength><D:getetag>"1666cee048aa7f98182780"</D:getetag><D:resourcetype></D:resourcetype><D:displayname>2</D:displayname><D:getlastmodified>Wed, 24 Feb 2021 22:16:19 GMT</D:getlastmodified><D:getcontenttype>text/plain; charset=utf-8</D:getcontenttype><D:supportedlock><D:lockentry xmlns:D="DAV:"><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response><D:response><D:href>/c=zzzzz-xxxxx-vvvvvvvvvvvvvvv/table%201%202%203</D:href><D:propstat><D:prop><D:resourcetype></D:resourcetype><D:getcontentlength>133352</D:getcontentlength><D:getetag>"1666cee048aa7f98208e8"</D:getetag><D:displayname>table 1 2 3</D:displayname><D:getlastmodified>Wed, 24 Feb 2021 22:16:19 GMT</D:getlastmodified><D:getcontenttype>text/plain; charset=utf-8</D:getcontenttype><D:supportedlock><D:lockentry xmlns:D="DAV:"><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response></D:multistatus>';
- const parser = new DOMParser();
- const xmlDoc = parser.parseFromString(xmlString, "text/xml");
+ it('should correctly decode URLs & file names', () => {
+ const testCases = [
+ // input URL, input display name, expected URL, expected name
+ ['table%201%202%203', 'table 1 2 3', 'table%201%202%203', 'table 1 2 3'],
+ ['table%25&%3F%2A2', 'table%&?*2', 'table%25&%3F%2A2', 'table%&?*2'],
+ ["G%C3%BCnter%27s%20file.pdf", "Günter's file.pdf", "G%C3%BCnter%27s%20file.pdf", "Günter's file.pdf"],
+ ['G%25C3%25BCnter%27s%2520file.pdf', 'G%C3%BCnter's%20file.pdf', "G%25C3%25BCnter%27s%2520file.pdf", "G%C3%BCnter's%20file.pdf"]
+ ];
- // when
- const result = extractFilesData(xmlDoc);
+ testCases.forEach(([inputURL, inputDisplayName, expectedURL, expectedName]) => {
+ // given
+ const collUUID = 'xxxxx-zzzzz-vvvvvvvvvvvvvvv';
+ const xmlData = `
+ <?xml version="1.0" encoding="UTF-8"?>
+ <D:multistatus xmlns:D="DAV:">
+ <D:response>
+ <D:href>/c=xxxxx-zzzzz-vvvvvvvvvvvvvvv/</D:href>
+ <D:propstat>
+ <D:prop>
+ <D:resourcetype>
+ <D:collection xmlns:D="DAV:"/>
+ </D:resourcetype>
+ <D:supportedlock>
+ <D:lockentry xmlns:D="DAV:">
+ <D:lockscope>
+ <D:exclusive/>
+ </D:lockscope>
+ <D:locktype>
+ <D:write/>
+ </D:locktype>
+ </D:lockentry>
+ </D:supportedlock>
+ <D:displayname></D:displayname>
+ <D:getlastmodified>Fri, 26 Mar 2021 14:44:08 GMT</D:getlastmodified>
+ </D:prop>
+ <D:status>HTTP/1.1 200 OK</D:status>
+ </D:propstat>
+ </D:response>
+ <D:response>
+ <D:href>/c=${collUUID}/${inputURL}</D:href>
+ <D:propstat>
+ <D:prop>
+ <D:resourcetype></D:resourcetype>
+ <D:getcontenttype>application/pdf</D:getcontenttype>
+ <D:supportedlock>
+ <D:lockentry xmlns:D="DAV:">
+ <D:lockscope>
+ <D:exclusive/>
+ </D:lockscope>
+ <D:locktype>
+ <D:write/>
+ </D:locktype>
+ </D:lockentry>
+ </D:supportedlock>
+ <D:displayname>${inputDisplayName}</D:displayname>
+ <D:getcontentlength>3</D:getcontentlength>
+ <D:getlastmodified>Fri, 26 Mar 2021 14:44:08 GMT</D:getlastmodified>
+ <D:getetag>"166feb9c9110c008325a59"</D:getetag>
+ </D:prop>
+ <D:status>HTTP/1.1 200 OK</D:status>
+ </D:propstat>
+ </D:response>
+ </D:multistatus>
+ `;
+ const parser = new DOMParser();
+ const xmlDoc = parser.parseFromString(xmlData, "text/xml");
- // then
- expect(result).toEqual([{ id: "zzzzz-xxxxx-vvvvvvvvvvvvvvv/2", name: "2", path: "", size: 1582976, type: "file", url: "/c=zzzzz-xxxxx-vvvvvvvvvvvvvvv/2" }, { id: "zzzzz-xxxxx-vvvvvvvvvvvvvvv/table 1 2 3", name: "table 1 2 3", path: "", size: 133352, type: "file", url: "/c=zzzzz-xxxxx-vvvvvvvvvvvvvvv/table 1 2 3" }]);
+ // when
+ const result = extractFilesData(xmlDoc);
+
+ // then
+ expect(result).toEqual([{ id: `${collUUID}/${expectedName}`, name: expectedName, path: "", size: 3, type: "file", url: `/c=${collUUID}/${expectedURL}` }]);
+ });
});
});