ad75f572aa6d44836acc47a69cf4b5161062824f
[arvados-workbench2.git] / src / services / collection-service / collection-service-files-response.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { CollectionFile } from '~/models/collection-file';
6 import { getFileFullPath, extractFilesData } from './collection-service-files-response';
7
8 describe('collection-service-files-response', () => {
9
10     describe('extractFilesData', () => {
11         it('should extract', () => {
12             // given
13             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>';
14             const parser = new DOMParser();
15             const xmlDoc = parser.parseFromString(xmlString, "text/xml");
16
17             // when
18             const result = extractFilesData(xmlDoc);
19
20             // then
21             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" }]);
22         });
23     });
24
25     describe('getFileFullPath', () => {
26         it('should encode weird names', async () => {
27             // given
28             const file = {
29                 name: '#test',
30                 path: 'http://localhost',
31             } as CollectionFile;
32
33             // when
34             const result = getFileFullPath(file);
35
36             // then
37             expect(result).toBe('http://localhost/#test');
38         });
39
40     });
41 });