Skip to content

Commit

Permalink
test: test for slug construction
Browse files Browse the repository at this point in the history
  • Loading branch information
amfage committed Nov 18, 2024
1 parent 4f9e532 commit 13ccb14
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 100 deletions.
116 changes: 28 additions & 88 deletions src/commands/generate-path/__test__/generate.path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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 = {
Expand All @@ -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,
Expand Down Expand Up @@ -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');
});
});
65 changes: 53 additions & 12 deletions src/commands/generate-path/__test__/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']],
},
},
};
11 changes: 11 additions & 0 deletions src/utils/__test__/date.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});

0 comments on commit 13ccb14

Please sign in to comment.