Merge branch 'master' into 13990-collection-files-service-based-on-webdav
[arvados-workbench2.git] / src / services / collection-files-service / collection-manifest-mapper.test.ts
index ad8f8727eba264747c30325af94be8cd3cad17c7..698a6bb7f4ba6f55a46a8a5a5d6e986eaff92747 100644 (file)
@@ -3,36 +3,40 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { parseKeepManifestText } from "./collection-manifest-parser";
-import { mapManifestToFiles, mapManifestToDirectories } from "./collection-manifest-mapper";
+import { mapManifestToFiles, mapManifestToDirectories, mapManifestToCollectionFilesTree, mapCollectionFilesTreeToManifest } from "./collection-manifest-mapper";
 
 test('mapManifestToFiles', () => {
     const manifestText = `. 930625b054ce894ac40596c3f5a0d947+33 0:0:a 0:0:b 0:33:output.txt\n./c d41d8cd98f00b204e9800998ecf8427e+0 0:0:d`;
     const manifest = parseKeepManifestText(manifestText);
     const files = mapManifestToFiles(manifest);
     expect(files).toEqual([{
-        parentId: '',
+        path: '',
         id: '/a',
         name: 'a',
         size: 0,
-        type: 'file'
+        type: 'file',
+        url: ''
     }, {
-        parentId: '',
+        path: '',
         id: '/b',
         name: 'b',
         size: 0,
-        type: 'file'
+        type: 'file',
+        url: ''
     }, {
-        parentId: '',
+        path: '',
         id: '/output.txt',
         name: 'output.txt',
         size: 33,
-        type: 'file'
+        type: 'file',
+        url: ''
     }, {
-        parentId: '/c',
+        path: '/c',
         id: '/c/d',
         name: 'd',
         size: 0,
-        type: 'file'
+        type: 'file',
+        url: ''
     },]);
 });
 
@@ -41,19 +45,54 @@ test('mapManifestToDirectories', () => {
     const manifest = parseKeepManifestText(manifestText);
     const directories = mapManifestToDirectories(manifest);
     expect(directories).toEqual([{
-        parentId: "",
+        path: "",
         id: '/c',
         name: 'c',
-        type: 'directory'
+        type: 'directory',
+        url: ''
     }, {
-        parentId: '/c',
+        path: '/c',
         id: '/c/user',
         name: 'user',
-        type: 'directory'
+        type: 'directory',
+        url: ''
     }, {
-        parentId: '/c/user',
+        path: '/c/user',
         id: '/c/user/results',
         name: 'results',
-        type: 'directory'
+        type: 'directory',
+        url: ''
     },]);
+});
+
+test('mapCollectionFilesTreeToManifest', () => {
+    const manifestText = `. 930625b054ce894ac40596c3f5a0d947+33 0:22:test.txt\n./c/user/results 930625b054ce894ac40596c3f5a0d947+33 0:0:a 0:0:b 0:33:output.txt\n`;
+    const tree = mapManifestToCollectionFilesTree(parseKeepManifestText(manifestText));
+    const manifest = mapCollectionFilesTreeToManifest(tree);
+    expect(manifest).toEqual([{
+        name: '',
+        locators: [],
+        files: [{
+            name: 'test.txt',
+            position: '',
+            size: 22
+        },],
+    }, {
+        name: '/c/user/results',
+        locators: [],
+        files: [{
+            name: 'a',
+            position: '',
+            size: 0
+        }, {
+            name: 'b',
+            position: '',
+            size: 0
+        }, {
+            name: 'output.txt',
+            position: '',
+            size: 33
+        },],
+    },]);
+
 });
\ No newline at end of file