|
1 | 1 | import assert from 'node:assert'; |
2 | 2 | import { describe, it } from 'node:test'; |
3 | 3 |
|
| 4 | +import { SampleCollection } from '../../generate-path/__test__/sample.js'; |
4 | 5 | import { FakeCogTiff } from '../../tileindex-validate/__test__/tileindex.validate.data.js'; |
5 | | -import { extractEpsg, extractGsd, formatName, generatePath, PathMetadata } from '../path.generate.js'; |
6 | | -import { SampleCollection } from './sample.js'; |
| 6 | +import { extractEpsg, extractGsd, generatePath, PathMetadata } from '../path.generate.js'; |
7 | 7 |
|
8 | 8 | describe('GeneratePathImagery', () => { |
9 | | - it('Should match - geographic description', () => { |
| 9 | + it('Should match - urban aerial from slug', () => { |
10 | 10 | const metadata: PathMetadata = { |
11 | 11 | targetBucketName: 'nz-imagery', |
12 | | - category: 'urban-aerial-photos', |
13 | | - geographicDescription: 'Napier', |
14 | | - region: 'hawkes-bay', |
15 | | - date: '2017-2018', |
16 | | - gsd: 0.05, |
17 | | - epsg: 2193, |
18 | | - }; |
19 | | - assert.equal(generatePath(metadata), 's3://nz-imagery/hawkes-bay/napier_2017-2018_0.05m/rgb/2193/'); |
20 | | - }); |
21 | | - it('Should match - event', () => { |
22 | | - const metadata: PathMetadata = { |
23 | | - targetBucketName: 'nz-imagery', |
24 | | - category: 'rural-aerial-photos', |
25 | | - geographicDescription: 'North Island Weather Event', |
26 | | - region: 'hawkes-bay', |
27 | | - date: '2023', |
28 | | - gsd: 0.25, |
29 | | - epsg: 2193, |
30 | | - }; |
31 | | - assert.equal(generatePath(metadata), 's3://nz-imagery/hawkes-bay/north-island-weather-event_2023_0.25m/rgb/2193/'); |
32 | | - }); |
33 | | - it('Should match - no optional metadata', () => { |
34 | | - const metadata: PathMetadata = { |
35 | | - targetBucketName: 'nz-imagery', |
36 | | - category: 'urban-aerial-photos', |
37 | | - geographicDescription: undefined, |
| 12 | + geospatialCategory: 'urban-aerial-photos', |
38 | 13 | region: 'auckland', |
39 | | - date: '2023', |
| 14 | + slug: 'auckland_2023_0.3m', |
40 | 15 | gsd: 0.3, |
41 | 16 | epsg: 2193, |
42 | 17 | }; |
43 | 18 | assert.equal(generatePath(metadata), 's3://nz-imagery/auckland/auckland_2023_0.3m/rgb/2193/'); |
44 | 19 | }); |
45 | 20 | }); |
46 | 21 |
|
47 | | -describe('GeneratePathElevation', () => { |
48 | | - it('Should match - dem (no optional metadata)', () => { |
| 22 | +describe('GeneratePathGeospatialDataCategories', () => { |
| 23 | + it('Should match - dem from slug', () => { |
49 | 24 | const metadata: PathMetadata = { |
50 | 25 | targetBucketName: 'nz-elevation', |
51 | | - category: 'dem', |
52 | | - geographicDescription: undefined, |
| 26 | + geospatialCategory: 'dem', |
53 | 27 | region: 'auckland', |
54 | | - date: '2023', |
| 28 | + slug: 'auckland_2023', |
55 | 29 | gsd: 1, |
56 | 30 | epsg: 2193, |
57 | 31 | }; |
58 | 32 | assert.equal(generatePath(metadata), 's3://nz-elevation/auckland/auckland_2023/dem_1m/2193/'); |
59 | 33 | }); |
60 | | - it('Should match - dsm (no optional metadata)', () => { |
| 34 | + it('Should match - dsm from slug', () => { |
61 | 35 | const metadata: PathMetadata = { |
62 | 36 | targetBucketName: 'nz-elevation', |
63 | | - category: 'dsm', |
64 | | - geographicDescription: undefined, |
| 37 | + geospatialCategory: 'dsm', |
65 | 38 | region: 'auckland', |
66 | | - date: '2023', |
| 39 | + slug: 'auckland_2023', |
67 | 40 | gsd: 1, |
68 | 41 | epsg: 2193, |
69 | 42 | }; |
70 | 43 | assert.equal(generatePath(metadata), 's3://nz-elevation/auckland/auckland_2023/dsm_1m/2193/'); |
71 | 44 | }); |
72 | | -}); |
73 | | - |
74 | | -describe('GeneratePathSatelliteImagery', () => { |
75 | | - it('Should match - geographic description & event', () => { |
| 45 | + it('Should error - invalid geospatial category', () => { |
76 | 46 | const metadata: PathMetadata = { |
77 | 47 | targetBucketName: 'nz-imagery', |
78 | | - category: 'satellite-imagery', |
79 | | - geographicDescription: 'North Island Cyclone Gabrielle', |
80 | | - region: 'new-zealand', |
81 | | - date: '2023', |
| 48 | + geospatialCategory: 'not-a-valid-category', |
| 49 | + region: 'wellington', |
| 50 | + slug: 'napier_2017-2018_0.05m', |
82 | 51 | gsd: 0.5, |
83 | 52 | epsg: 2193, |
84 | 53 | }; |
85 | | - assert.equal( |
86 | | - generatePath(metadata), |
87 | | - 's3://nz-imagery/new-zealand/north-island-cyclone-gabrielle_2023_0.5m/rgb/2193/', |
88 | | - ); |
| 54 | + assert.throws(() => { |
| 55 | + generatePath(metadata); |
| 56 | + }, Error("Path can't be generated from collection as no matching category for not-a-valid-category.")); |
89 | 57 | }); |
90 | | -}); |
91 | | - |
92 | | -describe('GeneratePathHistoricImagery', () => { |
93 | | - it('Should error', () => { |
| 58 | + it('Should error - does not support historical aerial photos', () => { |
94 | 59 | const metadata: PathMetadata = { |
95 | 60 | targetBucketName: 'nz-imagery', |
96 | | - category: 'scanned-aerial-imagery', |
97 | | - geographicDescription: undefined, |
| 61 | + geospatialCategory: 'scanned-aerial-photos', |
98 | 62 | region: 'wellington', |
99 | | - date: '1963', |
| 63 | + slug: 'napier_2017-2018_0.05m', |
100 | 64 | gsd: 0.5, |
101 | 65 | epsg: 2193, |
102 | 66 | }; |
103 | 67 | assert.throws(() => { |
104 | 68 | generatePath(metadata); |
105 | | - }, Error); |
| 69 | + }, Error('Historic Imagery scanned-aerial-photos is out of scope for automated path generation.')); |
106 | 70 | }); |
107 | 71 | }); |
108 | 72 |
|
109 | | -describe('GeneratePathDemIgnoringDate', () => { |
110 | | - it('Should not include the date in the survey name', () => { |
| 73 | +describe('GeneratePathImagery', () => { |
| 74 | + it('Should match - urban aerial from slug', () => { |
111 | 75 | const metadata: PathMetadata = { |
112 | | - targetBucketName: 'nz-elevation', |
113 | | - category: 'dem', |
114 | | - geographicDescription: 'new-zealand', |
115 | | - region: 'new-zealand', |
116 | | - date: '', |
117 | | - gsd: 1, |
| 76 | + targetBucketName: 'nz-imagery', |
| 77 | + geospatialCategory: 'urban-aerial-photos', |
| 78 | + region: 'auckland', |
| 79 | + slug: 'auckland_2023_0.3m', |
| 80 | + gsd: 0.3, |
118 | 81 | epsg: 2193, |
119 | 82 | }; |
120 | | - assert.equal(generatePath(metadata), 's3://nz-elevation/new-zealand/new-zealand/dem_1m/2193/'); |
121 | | - }); |
122 | | -}); |
123 | | - |
124 | | -describe('formatName', () => { |
125 | | - it('Should match - region', () => { |
126 | | - assert.equal(formatName('hawkes-bay', undefined), 'hawkes-bay'); |
127 | | - }); |
128 | | - it('Should match - region & geographic description', () => { |
129 | | - assert.equal(formatName('hawkes-bay', 'Napier'), 'napier'); |
130 | | - }); |
131 | | - it('Should match - region & event', () => { |
132 | | - assert.equal(formatName('canterbury', 'Christchurch Earthquake'), 'christchurch-earthquake'); |
| 83 | + assert.equal(generatePath(metadata), 's3://nz-imagery/auckland/auckland_2023_0.3m/rgb/2193/'); |
133 | 84 | }); |
134 | 85 | }); |
135 | 86 |
|
@@ -171,52 +122,18 @@ describe('gsd', () => { |
171 | 122 | }); |
172 | 123 | }); |
173 | 124 |
|
174 | | -describe('category', () => { |
175 | | - it('Should return category', async () => { |
176 | | - const collection = structuredClone(SampleCollection); |
177 | | - |
178 | | - assert.equal(collection['linz:geospatial_category'], 'urban-aerial-photos'); |
179 | | - }); |
180 | | -}); |
181 | | - |
182 | | -describe('geographicDescription', () => { |
183 | | - it('Should return geographic description', async () => { |
184 | | - const collection = structuredClone(SampleCollection); |
185 | | - |
186 | | - assert.equal(collection['linz:geographic_description'], 'Palmerston North'); |
187 | | - const metadata: PathMetadata = { |
188 | | - targetBucketName: 'bucket', |
189 | | - category: 'urban-aerial-photos', |
190 | | - geographicDescription: collection['linz:geographic_description'], |
191 | | - region: 'manawatu-whanganui', |
192 | | - date: '2020', |
193 | | - gsd: 0.05, |
194 | | - epsg: 2193, |
195 | | - }; |
196 | | - assert.equal(generatePath(metadata), 's3://bucket/manawatu-whanganui/palmerston-north_2020_0.05m/rgb/2193/'); |
197 | | - }); |
198 | | - it('Should return undefined - no geographic description metadata', async () => { |
| 125 | +describe('metadata from collection', () => { |
| 126 | + it('Should return urban aerial photos path', async () => { |
199 | 127 | const collection = structuredClone(SampleCollection); |
200 | 128 |
|
201 | | - delete collection['linz:geographic_description']; |
202 | | - assert.equal(collection['linz:geographic_description'], undefined); |
203 | 129 | const metadata: PathMetadata = { |
204 | 130 | targetBucketName: 'bucket', |
205 | | - category: 'urban-aerial-photos', |
206 | | - geographicDescription: collection['linz:geographic_description'], |
207 | | - region: 'manawatu-whanganui', |
208 | | - date: '2020', |
209 | | - gsd: 0.05, |
| 131 | + geospatialCategory: collection['linz:geospatial_category'], |
| 132 | + region: collection['linz:region'], |
| 133 | + slug: collection['linz:slug'], |
| 134 | + gsd: 0.3, |
210 | 135 | epsg: 2193, |
211 | 136 | }; |
212 | | - assert.equal(generatePath(metadata), 's3://bucket/manawatu-whanganui/manawatu-whanganui_2020_0.05m/rgb/2193/'); |
213 | | - }); |
214 | | -}); |
215 | | - |
216 | | -describe('region', () => { |
217 | | - it('Should return region', async () => { |
218 | | - const collection = structuredClone(SampleCollection); |
219 | | - |
220 | | - assert.equal(collection['linz:region'], 'manawatu-whanganui'); |
| 137 | + assert.equal(generatePath(metadata), 's3://bucket/manawatu-whanganui/palmerston-north_2024_0.3m/rgb/2193/'); |
221 | 138 | }); |
222 | 139 | }); |
0 commit comments