From 13ccb1448f9d5d8b53aba5478dd50df56fd3d830 Mon Sep 17 00:00:00 2001 From: Alice Fage Date: Mon, 18 Nov 2024 13:30:20 +1300 Subject: [PATCH] test: test for slug construction --- .../__test__/generate.path.test.ts | 116 +++++------------- src/commands/generate-path/__test__/sample.ts | 65 ++++++++-- src/utils/__test__/date.test.ts | 11 ++ 3 files changed, 92 insertions(+), 100 deletions(-) create mode 100644 src/utils/__test__/date.test.ts diff --git a/src/commands/generate-path/__test__/generate.path.test.ts b/src/commands/generate-path/__test__/generate.path.test.ts index 30ce2162..518992a5 100644 --- a/src/commands/generate-path/__test__/generate.path.test.ts +++ b/src/commands/generate-path/__test__/generate.path.test.ts @@ -3,32 +3,10 @@ import { describe, it } from 'node:test'; import { FakeCogTiff } from '../../tileindex-validate/__test__/tileindex.validate.data.js'; import { extractEpsg, extractGsd, generatePath, PathMetadata } from '../path.generate.js'; -import { SampleCollection } from './sample.js'; +import { SampleCollectionDem, SampleCollectionUrbanImagery } from './sample.js'; describe('GeneratePathImagery', () => { - it('Should match - geographic description', () => { - const metadata: PathMetadata = { - targetBucketName: 'nz-imagery', - geospatialCategory: 'urban-aerial-photos', - region: 'hawkes-bay', - slug: 'napier_2017-2018_0.05m', - gsd: 0.05, - epsg: 2193, - }; - assert.equal(generatePath(metadata), 's3://nz-imagery/hawkes-bay/napier_2017-2018_0.05m/rgb/2193/'); - }); - it('Should match - event', () => { - const metadata: PathMetadata = { - targetBucketName: 'nz-imagery', - geospatialCategory: 'rural-aerial-photos', - region: 'hawkes-bay', - slug: 'north-island-weather-event_2023_0.25m', - gsd: 0.25, - epsg: 2193, - }; - assert.equal(generatePath(metadata), 's3://nz-imagery/hawkes-bay/north-island-weather-event_2023_0.25m/rgb/2193/'); - }); - it('Should match - no optional metadata', () => { + it('Should match - urban aerial from slug', () => { const metadata: PathMetadata = { targetBucketName: 'nz-imagery', geospatialCategory: 'urban-aerial-photos', @@ -42,7 +20,7 @@ describe('GeneratePathImagery', () => { }); describe('GeneratePathElevation', () => { - it('Should match - dem (no optional metadata)', () => { + it('Should match - dem from slug', () => { const metadata: PathMetadata = { targetBucketName: 'nz-elevation', geospatialCategory: 'dem', @@ -53,7 +31,7 @@ describe('GeneratePathElevation', () => { }; assert.equal(generatePath(metadata), 's3://nz-elevation/auckland/auckland_2023/dem_1m/2193/'); }); - it('Should match - dsm (no optional metadata)', () => { + it('Should match - dsm from slug', () => { const metadata: PathMetadata = { targetBucketName: 'nz-elevation', geospatialCategory: 'dsm', @@ -66,23 +44,6 @@ describe('GeneratePathElevation', () => { }); }); -describe('GeneratePathSatelliteImagery', () => { - it('Should match - geographic description & event', () => { - const metadata: PathMetadata = { - targetBucketName: 'nz-imagery', - geospatialCategory: 'satellite-imagery', - region: 'new-zealand', - slug: 'north-island-cyclone-gabrielle_2023_0.5m', - gsd: 0.5, - epsg: 2193, - }; - assert.equal( - generatePath(metadata), - 's3://nz-imagery/new-zealand/north-island-cyclone-gabrielle_2023_0.5m/rgb/2193/', - ); - }); -}); - describe('GeneratePathHistoricImagery', () => { it('Should error', () => { const metadata: PathMetadata = { @@ -99,20 +60,6 @@ describe('GeneratePathHistoricImagery', () => { }); }); -describe('GeneratePathDemIgnoringDate', () => { - it('Should not include the date in the survey name', () => { - const metadata: PathMetadata = { - targetBucketName: 'nz-elevation', - geospatialCategory: 'dem', - region: 'new-zealand', - slug: 'new-zealand', - gsd: 1, - epsg: 2193, - }; - assert.equal(generatePath(metadata), 's3://nz-elevation/new-zealand/new-zealand/dem_1m/2193/'); - }); -}); - describe('epsg', () => { const TiffEPSG = new FakeCogTiff('s3://path/fake.tiff', { epsg: 2193, @@ -151,50 +98,43 @@ describe('gsd', () => { }); }); -describe('category', () => { - it('Should return category', async () => { - const collection = structuredClone(SampleCollection); +describe('slug dates', () => { + it('Should return path with slug dates', async () => { + const collection = structuredClone(SampleCollectionDem); - assert.equal(collection['linz:geospatial_category'], 'urban-aerial-photos'); - }); -}); - -describe('geographicDescription', () => { - it('Should return geographic description', async () => { - const collection = structuredClone(SampleCollection); - - assert.equal(collection['linz:geographic_description'], 'Palmerston North'); + assert.equal(collection['linz:slug'], 'southland_2020-2023'); const metadata: PathMetadata = { targetBucketName: 'bucket', - geospatialCategory: 'urban-aerial-photos', - region: 'manawatu-whanganui', - slug: 'palmerston-north_2020_0.05m', - gsd: 0.05, + geospatialCategory: 'dem', + region: 'southland', + slug: 'southland_2020-2023', + gsd: 1, epsg: 2193, }; - assert.equal(generatePath(metadata), 's3://bucket/manawatu-whanganui/palmerston-north_2020_0.05m/rgb/2193/'); + assert.equal(generatePath(metadata), 's3://bucket/southland/southland_2020-2023/dem_1m/2193/'); }); - it('Should return undefined - no geographic description metadata', async () => { - const collection = structuredClone(SampleCollection); +}); - delete collection['linz:geographic_description']; - assert.equal(collection['linz:geographic_description'], undefined); - const metadata: PathMetadata = { - targetBucketName: 'bucket', - geospatialCategory: 'urban-aerial-photos', - region: 'manawatu-whanganui', - slug: 'manawatu-whanganui_2020_0.05m', - gsd: 0.05, - epsg: 2193, - }; - assert.equal(generatePath(metadata), 's3://bucket/manawatu-whanganui/manawatu-whanganui_2020_0.05m/rgb/2193/'); +describe('category', () => { + it('Should return category', async () => { + const collection = structuredClone(SampleCollectionUrbanImagery); + + assert.equal(collection['linz:geospatial_category'], 'urban-aerial-photos'); }); }); describe('region', () => { it('Should return region', async () => { - const collection = structuredClone(SampleCollection); + const collection = structuredClone(SampleCollectionUrbanImagery); assert.equal(collection['linz:region'], 'manawatu-whanganui'); }); }); + +describe('slug', () => { + it('Should return slug', async () => { + const collection = structuredClone(SampleCollectionUrbanImagery); + + assert.equal(collection['linz:slug'], 'palmerston-north_2024_0.3m'); + }); +}); diff --git a/src/commands/generate-path/__test__/sample.ts b/src/commands/generate-path/__test__/sample.ts index aa7e2e81..acc2d4a4 100644 --- a/src/commands/generate-path/__test__/sample.ts +++ b/src/commands/generate-path/__test__/sample.ts @@ -2,48 +2,89 @@ import { StacCollection } from 'stac-ts'; import { StacCollectionLinz } from '../../common.js'; -export const SampleCollection: StacCollection & StacCollectionLinz = { +export const SampleCollectionUrbanImagery: StacCollection & StacCollectionLinz = { type: 'Collection', stac_version: '1.0.0', - id: '01HGF4RAQSM53Z26Y7C27T1GMB', - title: 'Palmerston North 0.3m Storm Satellite Imagery (2023) - Preview', - description: - 'Satellite imagery within the Manawatū-Whanganui region captured in 2023, published as a record of the Storm event.', + id: '01J0Q2CCGQKXK0TSBEJ4HRKR2X', + title: 'Palmerston North 0.1m Urban Aerial Photos (2024)', + description: 'Orthophotography within the Manawatū-Whanganui region captured in the 2024 flying season.', license: 'CC-BY-4.0', links: [ { rel: 'self', href: './collection.json', type: 'application/json' }, { rel: 'item', - href: './BA34_1000_3040.json', + href: './BM34_1000_3040.json', type: 'application/json', }, { rel: 'item', - href: './BA34_1000_3041.json', + href: './BM34_1000_3041.json', type: 'application/json', }, ], providers: [ { name: 'Aerial Surveys', roles: ['producer'] }, - { name: 'Aerial Surveys', roles: ['licensor'] }, + { name: 'Palmerston North City Council', roles: ['licensor'] }, { name: 'Toitū Te Whenua Land Information New Zealand', roles: ['host', 'processor'], }, ], - 'linz:lifecycle': 'preview', + 'linz:lifecycle': 'completed', 'linz:geospatial_category': 'urban-aerial-photos', 'linz:region': 'manawatu-whanganui', - 'linz:slug': 'palmerston-north_2023_0.3m', + 'linz:slug': 'palmerston-north_2024_0.3m', 'linz:security_classification': 'unclassified', - 'linz:event_name': 'Storm', 'linz:geographic_description': 'Palmerston North', extent: { spatial: { bbox: [[175.4961876, -36.8000575, 175.5071491, -36.7933469]], }, temporal: { - interval: [['2022-12-31T11:00:00Z', '2022-12-31T11:00:00Z']], + interval: [['2024-02-14T11:00:00Z', '2024-04-28T12:00:00Z']], + }, + }, +}; + +export const SampleCollectionDem: StacCollection & StacCollectionLinz = { + type: 'Collection', + stac_version: '1.0.0', + id: '01HQRJ3ZRPRD0NY2406V2C47MR', + title: 'Southland LiDAR 1m DEM (2020-2024)', + description: 'Digital Elevation Model within the Southland region captured in 2020-2024.', + license: 'CC-BY-4.0', + links: [ + { rel: 'self', href: './collection.json', type: 'application/json' }, + { + rel: 'item', + href: './CG10_10000_0202.json', + type: 'application/json', + }, + { + rel: 'item', + href: './CG10_10000_0203.json', + type: 'application/json', + }, + ], + providers: [ + { name: 'Aerial Surveys', roles: ['producer'] }, + { name: 'Environment Southland', roles: ['licensor'] }, + { + name: 'Toitū Te Whenua Land Information New Zealand', + roles: ['host', 'processor'], + }, + ], + 'linz:lifecycle': 'completed', + 'linz:geospatial_category': 'dem', + 'linz:region': 'southland', + 'linz:slug': 'southland_2020-2023', + 'linz:security_classification': 'unclassified', + extent: { + spatial: { + bbox: [[175.4961876, -36.8000575, 175.5071491, -36.7933469]], + }, + temporal: { + interval: [['2020-12-14T11:00:00Z', '2024-01-29T11:00:00Z']], }, }, }; diff --git a/src/utils/__test__/date.test.ts b/src/utils/__test__/date.test.ts new file mode 100644 index 00000000..7c98279d --- /dev/null +++ b/src/utils/__test__/date.test.ts @@ -0,0 +1,11 @@ +import { describe, it } from 'node:test'; + +import assert from 'assert'; + +import { getPacificAucklandYearMonthDay } from '../date.js'; + +describe('getPacificAucklandYearMonthDay', () => { + it('should format as yyyy-mm-dd', () => { + assert.equal(getPacificAucklandYearMonthDay('2012-12-31T11:00:00Z'), '2013-01-01'); + }); +});