From 6bca0d4f59bea0d9cf4365d1d5ec19a3f5db0a52 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 22 Nov 2022 16:01:29 +0100 Subject: [PATCH] =?UTF-8?q?/stations:=20fix=20Content-Type=20=F0=9F=90=9B?= =?UTF-8?q?=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/stations.js | 7 ++++++- test/index.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/routes/stations.js b/routes/stations.js index 37df43a..5934980 100644 --- a/routes/stations.js +++ b/routes/stations.js @@ -95,10 +95,15 @@ const stationsRoute = (req, res, next) => { pAllStations .then(({stations, timeModified, asJson, asNdjson}) => { res.setHeader('Last-Modified', timeModified.toUTCString()) + res.setHeader('Content-Type', t) if (Object.keys(q).length === 0) { const data = t === JSON_MIME ? asJson.data : asNdjson.data const etag = t === JSON_MIME ? asJson.etag : asNdjson.etag - serveBuffer(req, res, data, {timeModified, etag}) + serveBuffer(req, res, data, { + timeModified, + etag, + contentType: t, + }) } else if (q.query) { complete(req, res, next, q, stations, onStation, onEnd) } else { diff --git a/test/index.js b/test/index.js index a00c7c8..718dea9 100644 --- a/test/index.js +++ b/test/index.js @@ -39,3 +39,43 @@ tape.test('/journeys?loyaltyCard works', async (t) => { } }, {}, '/journeys?from=123&to=234&loyaltyCard=bahncard-2nd-50') }) + +tape.test('/stations works', async (t) => { + { + const {headers} = await fetchWithTestApi({}, {}, '/stations', { + headers: { + 'accept': 'application/json', + }, + }) + t.equal(headers['content-type'], 'application/json') + } + + { + const {headers} = await fetchWithTestApi({}, {}, '/stations', { + headers: { + 'accept': 'application/x-ndjson', + }, + }) + t.equal(headers['content-type'], 'application/x-ndjson') + } +}) + +tape.test('/stations?query=frankf works', async (t) => { + { + const {headers} = await fetchWithTestApi({}, {}, '/stations?query=frankf', { + headers: { + 'accept': 'application/json', + }, + }) + t.equal(headers['content-type'], 'application/json') + } + + { + const {headers} = await fetchWithTestApi({}, {}, '/stations?query=frankf', { + headers: { + 'accept': 'application/x-ndjson', + }, + }) + t.equal(headers['content-type'], 'application/x-ndjson') + } +})