|
1 | 1 | import { describe, it } from 'vitest'; |
2 | 2 | import { expect } from 'chai'; |
3 | | -import { DataSource, serializeDataSource } from '@/src/io/import/dataSource'; |
| 3 | +import { |
| 4 | + getDataSourceName, |
| 5 | + isRemoteDataSource, |
| 6 | +} from '@/src/io/import/dataSource'; |
| 7 | +import { Chunk } from '@/src/core/streaming/chunk'; |
4 | 8 |
|
5 | | -describe('serializeDataSource', () => { |
6 | | - it('should remove FileSources', () => { |
7 | | - const input: DataSource = { |
8 | | - fileSrc: { |
9 | | - file: new File([], '1.dcm'), |
10 | | - fileType: 'application/dicom', |
11 | | - }, |
12 | | - }; |
13 | | - const output = serializeDataSource(input); |
| 9 | +describe('isRemoteDatasource', () => { |
| 10 | + it('should work', () => { |
| 11 | + expect(isRemoteDataSource(undefined)).to.be.false; |
14 | 12 |
|
15 | | - expect(output).to.deep.equal({}); |
16 | | - }); |
| 13 | + expect( |
| 14 | + isRemoteDataSource({ |
| 15 | + type: 'file', |
| 16 | + file: new File([], 'name'), |
| 17 | + fileType: 'type', |
| 18 | + }) |
| 19 | + ).to.be.false; |
17 | 20 |
|
18 | | - it('should preserve archive status', () => { |
19 | | - const input: DataSource = { |
20 | | - fileSrc: { |
21 | | - file: new File([], '1.dcm'), |
22 | | - fileType: 'application/dicom', |
23 | | - }, |
24 | | - archiveSrc: { |
25 | | - path: 'a/b/c', |
26 | | - }, |
27 | | - parent: { |
28 | | - fileSrc: { |
29 | | - file: new File([], 'archive.zip'), |
30 | | - fileType: 'application/zip', |
| 21 | + expect( |
| 22 | + isRemoteDataSource({ |
| 23 | + type: 'file', |
| 24 | + file: new File([], 'name'), |
| 25 | + fileType: 'type', |
| 26 | + parent: { |
| 27 | + type: 'uri', |
| 28 | + uri: 'http://', |
| 29 | + name: 'name', |
31 | 30 | }, |
32 | | - }, |
33 | | - }; |
34 | | - const output = serializeDataSource(input); |
35 | | - |
36 | | - expect(output).to.deep.equal({ |
37 | | - archiveSrc: { |
38 | | - path: 'a/b/c', |
39 | | - }, |
40 | | - parent: {}, |
41 | | - }); |
| 31 | + }) |
| 32 | + ).to.be.true; |
42 | 33 | }); |
| 34 | +}); |
43 | 35 |
|
44 | | - it('should preserve UriSource', () => { |
45 | | - const input: DataSource = { |
46 | | - uriSrc: { |
47 | | - uri: 'https://example.com/image.jpg', |
48 | | - name: 'image.jpg', |
49 | | - }, |
50 | | - parent: { |
51 | | - uriSrc: { |
52 | | - uri: 's3://example/bucket', |
53 | | - name: '', |
54 | | - }, |
55 | | - }, |
56 | | - }; |
57 | | - const output = serializeDataSource(input); |
| 36 | +describe('getDataSourceName', () => { |
| 37 | + it('should work', () => { |
| 38 | + expect( |
| 39 | + getDataSourceName({ |
| 40 | + type: 'file', |
| 41 | + file: new File([], 'name'), |
| 42 | + fileType: 'ft', |
| 43 | + }) |
| 44 | + ).to.equal('name'); |
58 | 45 |
|
59 | | - expect(output).to.deep.equal(input); |
60 | | - }); |
| 46 | + expect( |
| 47 | + getDataSourceName({ |
| 48 | + type: 'uri', |
| 49 | + uri: 'http://', |
| 50 | + name: 'name', |
| 51 | + }) |
| 52 | + ).to.equal('name'); |
61 | 53 |
|
62 | | - it('should serialize remote archive members', () => { |
63 | | - const input: DataSource = { |
64 | | - fileSrc: { |
65 | | - file: new File([], '1.dcm'), |
66 | | - fileType: 'application/dicom', |
67 | | - }, |
68 | | - archiveSrc: { |
69 | | - path: 'a/b/c', |
70 | | - }, |
71 | | - parent: { |
72 | | - fileSrc: { |
73 | | - file: new File([], 'archive.zip'), |
74 | | - fileType: 'application/zip', |
75 | | - }, |
76 | | - parent: { |
77 | | - uriSrc: { |
78 | | - uri: 'https://example.com/archive.zip', |
79 | | - name: 'archive.zip', |
| 54 | + expect( |
| 55 | + getDataSourceName({ |
| 56 | + type: 'collection', |
| 57 | + sources: [ |
| 58 | + { |
| 59 | + type: 'file', |
| 60 | + file: new File([], 'name'), |
| 61 | + fileType: 'ft', |
80 | 62 | }, |
81 | | - }, |
82 | | - }, |
83 | | - }; |
84 | | - const output = serializeDataSource(input); |
| 63 | + ], |
| 64 | + }) |
| 65 | + ).to.equal('name'); |
85 | 66 |
|
86 | | - expect(output).to.deep.equal({ |
87 | | - archiveSrc: { |
88 | | - path: 'a/b/c', |
89 | | - }, |
90 | | - parent: { |
91 | | - // empty parent b/c archive FileSource cannot be serialized |
| 67 | + expect( |
| 68 | + getDataSourceName({ |
| 69 | + type: 'chunk', |
| 70 | + chunk: {} as Chunk, |
| 71 | + mime: 'mime', |
| 72 | + }) |
| 73 | + ).to.equal(null); |
| 74 | + |
| 75 | + expect( |
| 76 | + getDataSourceName({ |
| 77 | + type: 'chunk', |
| 78 | + chunk: {} as Chunk, |
| 79 | + mime: 'mime', |
92 | 80 | parent: { |
93 | | - uriSrc: { |
94 | | - uri: 'https://example.com/archive.zip', |
95 | | - name: 'archive.zip', |
96 | | - }, |
| 81 | + type: 'file', |
| 82 | + file: new File([], 'name'), |
| 83 | + fileType: 'ft', |
97 | 84 | }, |
98 | | - }, |
99 | | - }); |
| 85 | + }) |
| 86 | + ).to.equal('name'); |
100 | 87 | }); |
101 | 88 | }); |
0 commit comments