@@ -6,7 +6,7 @@ import { LogConfig } from '@basemaps/shared';
66import { round } from '@basemaps/test/build/rounding.js' ;
77
88import { FakeData } from '../../__tests__/config.data.js' ;
9- import { Api , mockRequest } from '../../__tests__/xyz.util.js' ;
9+ import { Api , mockRequest , mockUrlRequest } from '../../__tests__/xyz.util.js' ;
1010import { handler } from '../../index.js' ;
1111import { ConfigLoader } from '../../util/config.loader.js' ;
1212import { Etag } from '../../util/etag.js' ;
@@ -53,8 +53,8 @@ describe('/v1/tiles', () => {
5353
5454 const request = mockRequest ( '/v1/tiles/aerial/3857/0/0/0.webp' , 'get' , Api . header ) ;
5555 const res = await handler . router . handle ( request ) ;
56- console . log ( res . statusDescription ) ;
57- assert . equal ( res . status , 200 ) ;
56+
57+ assert . equal ( res . status , 200 , res . statusDescription ) ;
5858 assert . equal ( res . header ( 'content-type' ) , 'image/webp' ) ;
5959 assert . equal ( res . header ( 'eTaG' ) , 'fakeEtag' ) ;
6060 // o(res.body).equals(rasterMockBuffer.toString('base64'));
@@ -68,13 +68,13 @@ describe('/v1/tiles', () => {
6868 it ( `should 200 with empty ${ fmt } if a tile is out of bounds` , async ( t ) => {
6969 t . mock . method ( ConfigLoader , 'getDefaultConfig' , ( ) => Promise . resolve ( config ) ) ;
7070
71- const res = await handler . router . handle (
72- mockRequest ( `/v1/tiles/aerial/global-mercator/0/0/0.${ fmt } ` , 'get' , Api . header ) ,
73- ) ;
74- assert . equal ( res . status , 200 ) ;
71+ const request = mockRequest ( `/v1/tiles/aerial/global-mercator/0/0/0.${ fmt } ` , 'get' , Api . header ) ;
72+ const res = await handler . router . handle ( request ) ;
73+ assert . equal ( res . status , 200 , res . statusDescription ) ;
7574 assert . equal ( res . header ( 'content-type' ) , `image/${ fmt } ` ) ;
7675 assert . notEqual ( res . header ( 'etag' ) , undefined ) ;
7776 assert . equal ( res . header ( 'cache-control' ) , 'public, max-age=604800, stale-while-revalidate=86400' ) ;
77+ assert . deepEqual ( request . logContext [ 'pipeline' ] , 'rgba' ) ;
7878 } ) ;
7979 } ) ;
8080
@@ -114,7 +114,7 @@ describe('/v1/tiles', () => {
114114 const req = mockRequest ( '/v1/tiles/🦄 🌈/global-mercator/0/0/0.png' , 'get' , Api . header ) ;
115115 assert . equal ( req . path , '/v1/tiles/%F0%9F%A6%84%20%F0%9F%8C%88/global-mercator/0/0/0.png' ) ;
116116 const res = await handler . router . handle ( req ) ;
117- assert . equal ( res . status , 200 ) ;
117+ assert . equal ( res . status , 200 , res . statusDescription ) ;
118118 assert . equal ( res . header ( 'content-type' ) , 'image/png' ) ;
119119 assert . notEqual ( res . header ( 'etag' ) , undefined ) ;
120120 assert . equal ( res . header ( 'cache-control' ) , 'public, max-age=604800, stale-while-revalidate=86400' ) ;
@@ -129,21 +129,52 @@ describe('/v1/tiles', () => {
129129 } ) ;
130130 } ) ;
131131
132+ it ( 'should 404 if pipelines are defined but one is not requested' , async ( t ) => {
133+ t . mock . method ( ConfigLoader , 'getDefaultConfig' , ( ) => Promise . resolve ( config ) ) ;
134+
135+ const elevation = FakeData . tileSetRaster ( 'elevation' ) ;
136+
137+ elevation . outputs = [ { title : 'Terrain RGB' , name : 'terrain-rgb' , output : { lossless : true } } ] ;
138+ config . put ( elevation ) ;
139+
140+ const request = mockRequest ( '/v1/tiles/elevation/3857/11/2022/1283.webp' , 'get' , Api . header ) ;
141+
142+ const res = await handler . router . handle ( request ) ;
143+
144+ assert . equal ( res . status , 404 , res . statusDescription ) ;
145+ } ) ;
146+
132147 it ( 'should generate a terrain-rgb 11/2022/1283 in webp' , async ( t ) => {
133148 t . mock . method ( ConfigLoader , 'getDefaultConfig' , ( ) => Promise . resolve ( config ) ) ;
134149
135150 const elevation = FakeData . tileSetRaster ( 'elevation' ) ;
136151
137- elevation . outputs = [ { title : 'Terrain RGB' , name : 'terrain-rgb' , output : { type : 'webp' , lossless : true } } ] ;
152+ elevation . outputs = [ { title : 'Terrain RGB' , name : 'terrain-rgb' , output : { lossless : true } } ] ;
138153 config . put ( elevation ) ;
139154
140- const request = mockRequest ( '/v1/tiles/elevation/3857/11/2022/1283-terrain-rgb .webp' , 'get ' , Api . header ) ;
155+ const request = mockUrlRequest ( '/v1/tiles/elevation/3857/11/2022/1283.webp' , '?pipeline=terrain-rgb ' , Api . header ) ;
141156
142157 const res = await handler . router . handle ( request ) ;
143158
144- assert . equal ( res . status , 200 ) ;
159+ assert . equal ( res . status , 200 , res . statusDescription ) ;
145160 // Validate the session information has been set correctly
146161 assert . deepEqual ( request . logContext [ 'xyz' ] , { x : 2022 , y : 1283 , z : 11 } ) ;
162+ assert . deepEqual ( request . logContext [ 'pipeline' ] , 'terrain-rgb' ) ;
147163 assert . deepEqual ( round ( request . logContext [ 'location' ] ) , { lat : - 41.44272638 , lon : 175.51757812 } ) ;
148164 } ) ;
165+
166+ it ( 'should validate lossless if pipelines are defined but one is not requested' , async ( t ) => {
167+ t . mock . method ( ConfigLoader , 'getDefaultConfig' , ( ) => Promise . resolve ( config ) ) ;
168+
169+ const elevation = FakeData . tileSetRaster ( 'elevation' ) ;
170+
171+ elevation . outputs = [ { title : 'Terrain RGB' , name : 'terrain-rgb' , output : { lossless : true } } ] ;
172+ config . put ( elevation ) ;
173+
174+ // JPEG is not lossless
175+ const res = await handler . router . handle (
176+ mockUrlRequest ( '/v1/tiles/elevation/3857/11/2022/1283.jpeg' , '?pipeline=terrain-rgb' , Api . header ) ,
177+ ) ;
178+ assert . equal ( res . status , 400 , res . statusDescription ) ;
179+ } ) ;
149180} ) ;
0 commit comments