Merge branch 'master'
[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     }, {
19         path: '',
20         id: '/b',
21         name: 'b',
22         size: 0,
23         type: 'file'
24     }, {
25         path: '',
26         id: '/output.txt',
27         name: 'output.txt',
28         size: 33,
29         type: 'file'
30     }, {
31         path: '/c',
32         id: '/c/d',
33         name: 'd',
34         size: 0,
35         type: 'file'
36     },]);
37 });
38
39 test('mapManifestToDirectories', () => {
40     const manifestText = `./c/user/results 930625b054ce894ac40596c3f5a0d947+33 0:0:a 0:0:b 0:33:output.txt\n`;
41     const manifest = parseKeepManifestText(manifestText);
42     const directories = mapManifestToDirectories(manifest);
43     expect(directories).toEqual([{
44         path: "",
45         id: '/c',
46         name: 'c',
47         type: 'directory'
48     }, {
49         path: '/c',
50         id: '/c/user',
51         name: 'user',
52         type: 'directory'
53     }, {
54         path: '/c/user',
55         id: '/c/user/results',
56         name: 'results',
57         type: 'directory'
58     },]);
59 });
60
61 test('mapCollectionFilesTreeToManifest', () => {
62     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`;
63     const tree = mapManifestToCollectionFilesTree(parseKeepManifestText(manifestText));
64     const manifest = mapCollectionFilesTreeToManifest(tree);
65     expect(manifest).toEqual([{
66         name: '',
67         locators: [],
68         files: [{
69             name: 'test.txt',
70             position: '',
71             size: 22
72         },],
73     }, {
74         name: '/c/user/results',
75         locators: [],
76         files: [{
77             name: 'a',
78             position: '',
79             size: 0
80         }, {
81             name: 'b',
82             position: '',
83             size: 0
84         }, {
85             name: 'output.txt',
86             position: '',
87             size: 33
88         },],
89     },]);
90
91 });