// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 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 = '/c=xxxxx-zzzzz-vvvvvvvvvvvvvvv/Wed, 24 Feb 2021 22:16:19 GMTHTTP/1.1 200 OK/c=zzzzz-xxxxx-vvvvvvvvvvvvvvv/21582976"1666cee048aa7f98182780"2Wed, 24 Feb 2021 22:16:19 GMTtext/plain; charset=utf-8HTTP/1.1 200 OK/c=zzzzz-xxxxx-vvvvvvvvvvvvvvv/table%201%202%203133352"1666cee048aa7f98208e8"table 1 2 3Wed, 24 Feb 2021 22:16:19 GMTtext/plain; charset=utf-8HTTP/1.1 200 OK'; const parser = new DOMParser(); const xmlDoc = parser.parseFromString(xmlString, "text/xml"); // when const result = extractFilesData(xmlDoc); // 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" }]); }); }); describe('getFileFullPath', () => { it('should encode weird names', async () => { // given const file = { name: '#test', path: 'http://localhost', } as CollectionFile; // when const result = getFileFullPath(file); // then expect(result).toBe('http://localhost/#test'); }); }); });