Skip to content

Commit

Permalink
refactor: fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Jun 22, 2023
1 parent 4140848 commit 4f5bc1f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/lambda-tiler/src/__tests__/config.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const TileSetAerial: ConfigTileSetRaster = {
description: 'aerial__description',
title: 'Aerial Imagery',
category: 'Basemap',
background: { r: 0xff, g: 0x00, b: 0xff, alpha: 0.5 },
layers: [
{
2193: 'im_01FYWKAJ86W9P7RWM1VB62KD0H',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,12 @@ o.spec('/v1/attribution', () => {

o('should 304 with etag match', async () => {
const request = mockUrlRequest(`/v1/attribution/aerial/EPSG:3857/summary.json`, 'get', {
[HttpHeader.IfNoneMatch]: 'E5HGpTqF8AiJ7VgGVKLehYnVfLN9jaVw8Sy6UafJRh2f',
[HttpHeader.IfNoneMatch]: '3un15yA8o1ZDiyYpHXwUQHYXPxd5uGtzHS3R8gug9Nn1',
});

const res = await handler.router.handle(request);

if (res.status === 200) o(res.header('etag')).equals('E5HGpTqF8AiJ7VgGVKLehYnVfLN9jaVw8Sy6UafJRh2f');
if (res.status === 200) o(res.header('etag')).equals('3un15yA8o1ZDiyYpHXwUQHYXPxd5uGtzHS3R8gug9Nn1');

console.log(res.header('etag'));
o(res.status).equals(304);
Expand Down
10 changes: 10 additions & 0 deletions packages/lambda-tiler/src/routes/__tests__/xyz.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ o.spec('/v1/tiles', () => {
o(resB.status).equals(404);
});

o('should 204 if a tile is outside of the bounds', async () => {
const fakeTileSet = FakeData.tileSetRaster('🦄 🌈');
fakeTileSet.background = undefined;
config.put(fakeTileSet);
const res = await handler.router.handle(
mockRequest('/v1/tiles/🦄 🌈/global-mercator/0/0/0.png', 'get', Api.header),
);
o(res.status).equals(204);
});

o('should support utf8 tilesets', async () => {
const fakeTileSet = FakeData.tileSetRaster('🦄 🌈');
config.put(fakeTileSet);
Expand Down
9 changes: 9 additions & 0 deletions packages/lambda-tiler/src/routes/tile.xyz.raster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ export const TileXyzRaster = {

const background = tileSet.background ?? DefaultBackground;

// If no layers are used and the tile is going to be transparent
// return 204 no content instead of a empty image
if (layers.length === 0 && background.alpha === 0) {
const response = NoContent();
response.header(HttpHeader.ETag, cacheKey);
response.header(HttpHeader.CacheControl, 'public, max-age=604800, stale-while-revalidate=86400');
return response;
}

const res = await TileComposer.compose({
layers,
format: xyz.tileType,
Expand Down

0 comments on commit 4f5bc1f

Please sign in to comment.