// 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 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"] ]; testCases.forEach(([inputURL, inputDisplayName, expectedURL, expectedName]) => { // given const collUUID = 'xxxxx-zzzzz-vvvvvvvvvvvvvvv'; const xmlData = ` /c=xxxxx-zzzzz-vvvvvvvvvvvvvvv/ Fri, 26 Mar 2021 14:44:08 GMT HTTP/1.1 200 OK /c=${collUUID}/${inputURL} application/pdf ${inputDisplayName} 3 Fri, 26 Mar 2021 14:44:08 GMT "166feb9c9110c008325a59" HTTP/1.1 200 OK `; const parser = new DOMParser(); const xmlDoc = parser.parseFromString(xmlData, "text/xml"); // when const result = extractFilesData(xmlDoc); // then expect(result).toEqual([{ id: `${collUUID}/${expectedName}`, name: expectedName, path: "", size: 3, type: "file", url: `/c=${collUUID}/${expectedURL}` }]); }); }); }); 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'); }); }); });