/stations: fix Content-Type 🐛✅
This commit is contained in:
parent
40865154fa
commit
6bca0d4f59
2 changed files with 46 additions and 1 deletions
|
@ -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 {
|
||||
|
|
|
@ -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')
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue