16472: Adds parameter to commonService.get to avoid showing errors.
[arvados-workbench2.git] / src / services / collection-files-service / collection-manifest-mapper.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { parseKeepManifestText } from "./collection-manifest-parser";
6 import { mapManifestToFiles, mapManifestToDirectories, mapManifestToCollectionFilesTree, mapCollectionFilesTreeToManifest } from "./collection-manifest-mapper";
7
8 test('mapManifestToFiles', () => {
9     const manifestText = `. 930625b054ce894ac40596c3f5a0d947+33 0:0:a 0:0:b 0:33:output.txt\n./c d41d8cd98f00b204e9800998ecf8427e+0 0:0:d`;
10     const manifest = parseKeepManifestText(manifestText);
11     const files = mapManifestToFiles(manifest);
12     expect(files).toEqual([{
13         path: '',
14         id: '/a',
15         name: 'a',
16         size: 0,
17         type: 'file',
18         url: ''
19     }, {
20         path: '',
21         id: '/b',
22         name: 'b',
23         size: 0,
24         type: 'file',
25         url: ''
26     }, {
27         path: '',
28         id: '/output.txt',
29         name: 'output.txt',
30         size: 33,
31         type: 'file',
32         url: ''
33     }, {
34         path: '/c',
35         id: '/c/d',
36         name: 'd',
37         size: 0,
38         type: 'file',
39         url: ''
40     },]);
41 });
42
43 test('mapManifestToDirectories', () => {
44     const manifestText = `./c/user/results 930625b054ce894ac40596c3f5a0d947+33 0:0:a 0:0:b 0:33:output.txt\n`;
45     const manifest = parseKeepManifestText(manifestText);
46     const directories = mapManifestToDirectories(manifest);
47     expect(directories).toEqual([{
48         path: "",
49         id: '/c',
50         name: 'c',
51         type: 'directory',
52         url: ''
53     }, {
54         path: '/c',
55         id: '/c/user',
56         name: 'user',
57         type: 'directory',
58         url: ''
59     }, {
60         path: '/c/user',
61         id: '/c/user/results',
62         name: 'results',
63         type: 'directory',
64         url: ''
65     },]);
66 });
67
68 test('mapCollectionFilesTreeToManifest', () => {
69     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`;
70     const tree = mapManifestToCollectionFilesTree(parseKeepManifestText(manifestText));
71     const manifest = mapCollectionFilesTreeToManifest(tree);
72     expect(manifest).toEqual([{
73         name: '',
74         locators: [],
75         files: [{
76             name: 'test.txt',
77             position: '',
78             size: 22
79         },],
80     }, {
81         name: '/c/user/results',
82         locators: [],
83         files: [{
84             name: 'a',
85             position: '',
86             size: 0
87         }, {
88             name: 'b',
89             position: '',
90             size: 0
91         }, {
92             name: 'output.txt',
93             position: '',
94             size: 33
95         },],
96     },]);
97
98 });