fixed missing endpoint GET /routes/:id/pois/:id and added json style fileupload

This commit is contained in:
Florian Zumpe
2026-06-17 01:39:50 +02:00
parent 5c85a0194b
commit 09ce7c0605
10 changed files with 380 additions and 50 deletions
+73 -3
View File
@@ -114,6 +114,27 @@ test('pictures and audio are managed as individual REST resources', { timeout: 3
})
}, 201);
const { body: fetchedPoi } = await requestJson(
`${baseUrl}/api/routes/${route.id}/pois/${poi.id}`
);
assert.equal(fetchedPoi.id, poi.id);
assert.equal(fetchedPoi.routeId, route.id);
assert.equal(fetchedPoi.title, 'Teststation');
const { body: updatedPoi } = await requestJson(
`${baseUrl}/api/routes/${route.id}/pois/${poi.id}`,
{
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title: 'Aktualisierte Teststation' })
}
);
assert.equal(updatedPoi.title, 'Aktualisierte Teststation');
await requestJson(`${baseUrl}/api/routes/999999/pois/${poi.id}`, {}, 404);
await requestJson(`${baseUrl}/api/routes/${route.id}/pois/999999`, {}, 404);
await requestJson(`${baseUrl}/api/pois/${poi.id}`, {}, 404);
const pictureForm = new FormData();
pictureForm.append('poiId', String(otherPoi.id));
pictureForm.append('caption', 'Erste Bildbeschreibung');
@@ -144,6 +165,40 @@ test('pictures and audio are managed as individual REST resources', { timeout: 3
assert.equal(pictureList.pictures.length, 1);
assert.equal(pictureList.pictures[0].id, picture.id);
const jsonPicturePayload = {
caption: 'Bild aus JSON',
sequence: 1,
picture: {
filename: 'bild-json.webp',
contentType: 'image/webp',
base64: Buffer.from('picture-json').toString('base64')
}
};
const { body: jsonPicture } = await requestJson(
`${baseUrl}/api/routes/${route.id}/pois/${otherPoi.id}/pictures`,
{
method: 'POST',
headers: { 'Content-Type': 'text/json' },
body: JSON.stringify(jsonPicturePayload)
},
201
);
assert.equal(jsonPicture.poiId, otherPoi.id);
assert.equal(jsonPicture.caption, 'Bild aus JSON');
const { response: jsonPictureResponse, body: jsonPictureFile } = await requestBuffer(`${baseUrl}${jsonPicture.url}`);
assert.match(jsonPictureResponse.headers.get('content-type') || '', /image\/webp/);
assert.equal(jsonPictureFile.toString(), 'picture-json');
await requestJson(
`${baseUrl}/api/routes/${route.id}/pois/${otherPoi.id}/pictures`,
{
method: 'POST',
headers: { 'Content-Type': 'text/json' },
body: '{}'
},
400
);
const { body: updatedPicture } = await requestJson(
`${baseUrl}/api/routes/${route.id}/pois/${poi.id}/pictures/${picture.id}`,
{
@@ -178,11 +233,20 @@ test('pictures and audio are managed as individual REST resources', { timeout: 3
body: duplicateAudio
}, 409);
const replacementAudio = new FormData();
replacementAudio.append('audio', new Blob(['audio-two'], { type: 'audio/ogg' }), 'ansage-neu.ogg');
const replacementAudio = {
audio: {
filename: 'ansage-neu.ogg',
contentType: 'audio/ogg',
base64: Buffer.from('audio-two').toString('base64')
}
};
const { body: replacedAudio } = await requestJson(
`${baseUrl}/api/routes/${route.id}/pois/${poi.id}/audio`,
{ method: 'PUT', body: replacementAudio }
{
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(replacementAudio)
}
);
assert.equal(replacedAudio.url, `/api/routes/${route.id}/pois/${poi.id}/audio`);
const { response: replacedAudioResponse, body: replacedAudioFile } = await requestBuffer(`${baseUrl}${replacedAudio.url}`);
@@ -214,6 +278,12 @@ test('pictures and audio are managed as individual REST resources', { timeout: 3
);
assert.equal(deletedPicture.deleted, true);
const { body: deletedJsonPicture } = await requestJson(
`${baseUrl}/api/routes/${route.id}/pois/${otherPoi.id}/pictures/${jsonPicture.id}`,
{ method: 'DELETE' }
);
assert.equal(deletedJsonPicture.deleted, true);
await requestJson(`${baseUrl}/api/routes/${route.id}/pois/${poi.id}/pictures/${picture.id}`, {}, 404);
await requestJson(`${baseUrl}/api/routes/${route.id}/pois/${poi.id}/audio`, {}, 404);
});