Skip to content

Commit 697f83e

Browse files
committed
Add smaller GeoPDF test
1 parent 59b7f5c commit 697f83e

File tree

9 files changed

+119
-8
lines changed

9 files changed

+119
-8
lines changed

tasks/events/src/worker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,15 @@ export default class Worker extends EventEmitter {
271271
body: JSON.stringify({
272272
name: json.name,
273273
url: json.url,
274-
minzoom: basemap.minZoom,
275-
maxzoom: basemap.maxZoom,
276-
format: basemap.tileType,
274+
minzoom: json.minZoom,
275+
maxzoom: json.maxZoom,
276+
format: json.tileType,
277277
})
278278
});
279279

280-
if (!icon_req.ok) console.error(await icon_req.text());
280+
if (!basemap_req.ok) console.error(await basemap_req.text());
281281
} catch (err) {
282-
console.log(`Import: ${this.msg.job.id} - ${file} is not a Basemap:`, err.message);
282+
console.log(`Import: ${this.msg.job.id} - ${file} is not a Basemap:`, err instanceof Error ? err.message : String(err));
283283
}
284284
}
285285
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import test from 'tape';
2+
import path from 'node:path';
3+
import Worker from '../src/worker.js';
4+
import fs from 'node:fs';
5+
import fsp from 'node:fs/promises';
6+
import Sinon from 'sinon';
7+
import {
8+
S3Client,
9+
GetObjectCommand,
10+
PutObjectCommand,
11+
} from '@aws-sdk/client-s3';
12+
import { MockAgent, setGlobalDispatcher, getGlobalDispatcher } from 'undici';
13+
14+
for (const fixturename of await fsp.readdir(new URL('./fixtures/transform-raster/', import.meta.url))) {
15+
const { ext } = path.parse(fixturename);
16+
17+
test(`Worker Data Transform Raster: ${fixturename}`, async (t) => {
18+
let id: string;
19+
20+
const mockAgent = new MockAgent();
21+
const originalDispatcher = getGlobalDispatcher();
22+
mockAgent.disableNetConnect();
23+
setGlobalDispatcher(mockAgent);
24+
const mockPool = mockAgent.get('http://localhost:5001');
25+
26+
mockPool.intercept({
27+
path: /profile\/asset/,
28+
method: 'POST'
29+
}).reply((req) => {
30+
const body = JSON.parse(req.body) as {
31+
id: string
32+
};
33+
34+
id = body.id;
35+
36+
return {
37+
statusCode: 200,
38+
data: JSON.stringify({
39+
id: body.id
40+
})
41+
};
42+
});
43+
44+
const ExternalOperations = [
45+
(command) => {
46+
t.ok(command instanceof GetObjectCommand);
47+
t.deepEquals(command.input, {
48+
Bucket: 'test-bucket',
49+
Key: `import/ba58a298-a3fe-46b4-a29a-9dd33fbb2139${ext}`
50+
});
51+
52+
return Promise.resolve({
53+
Body: fs.createReadStream(new URL(`./fixtures/transform-raster/${fixturename}`, import.meta.url))
54+
})
55+
},
56+
(command) => {
57+
t.ok(command instanceof PutObjectCommand);
58+
59+
t.equals(command.input.Bucket, 'test-bucket')
60+
t.ok(command.input.Key.startsWith(`profile/admin@example.com/`))
61+
t.ok(command.input.Key.endsWith(ext))
62+
63+
return Promise.resolve({});
64+
},
65+
(command) => {
66+
t.ok(command instanceof PutObjectCommand);
67+
68+
t.equals(command.input.Bucket, 'test-bucket')
69+
t.equals(command.input.Key, `profile/admin@example.com/${id}.pmtiles`);
70+
71+
return Promise.resolve({});
72+
},
73+
].reverse();
74+
75+
Sinon.stub(S3Client.prototype, 'send').callsFake((command) => {
76+
return ExternalOperations.pop()(command);
77+
});
78+
79+
const worker = new Worker({
80+
api: 'http://localhost:5001',
81+
secret: 'coe-wildland-fire',
82+
bucket: 'test-bucket',
83+
job: {
84+
id: 'ba58a298-a3fe-46b4-a29a-9dd33fbb2139',
85+
created: '2025-08-25T18:08:21.563Z',
86+
updated: '2025-08-25T18:08:21.563Z',
87+
status: 'Running',
88+
error: null,
89+
result: {},
90+
name: `import${ext}`,
91+
username: 'admin@example.com',
92+
source: 'Upload',
93+
config: {},
94+
source_id: null,
95+
}
96+
});
97+
98+
worker.on('error', (err) => {
99+
t.error(err);
100+
});
101+
102+
worker.on('success', () => {
103+
Sinon.restore();
104+
setGlobalDispatcher(originalDispatcher);
105+
mockAgent.close();
106+
t.end()
107+
});
108+
109+
await worker.process()
110+
});
111+
}

tasks/events/test/worker.test.ts renamed to tasks/events/test/worker-vector.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {
1111
} from '@aws-sdk/client-s3';
1212
import { MockAgent, setGlobalDispatcher, getGlobalDispatcher } from 'undici';
1313

14-
for (const fixturename of await fsp.readdir(new URL('./fixtures/transform/', import.meta.url))) {
14+
for (const fixturename of await fsp.readdir(new URL('./fixtures/transform-vector/', import.meta.url))) {
1515
const { ext } = path.parse(fixturename);
1616

17-
test(`Worker Data Transform: ${fixturename}`, async (t) => {
17+
test(`Worker Data Transform Vector: ${fixturename}`, async (t) => {
1818
let id: string;
1919

2020
const mockAgent = new MockAgent();
@@ -50,7 +50,7 @@ for (const fixturename of await fsp.readdir(new URL('./fixtures/transform/', imp
5050
});
5151

5252
return Promise.resolve({
53-
Body: fs.createReadStream(new URL(`./fixtures/transform/${fixturename}`, import.meta.url))
53+
Body: fs.createReadStream(new URL(`./fixtures/transform-vector/${fixturename}`, import.meta.url))
5454
})
5555
},
5656
(command) => {

0 commit comments

Comments
 (0)