Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('sets a terse 500 for an error in production', () => {
const ctx = selectStatus(true)({ content: { }, error }, { logger });
assertEquals(ctx.response.status, 500);
assertEquals(ctx.response.body, '');
});
it('sets a verbose 500 for an error in dev', () => {
const ctx = selectStatus(false)({ content: { }, error }, { logger });
assertEquals(ctx.response.status, 500);
assertEquals(ctx.response.body, `<code>500</code>${error}`);
assertEquals(ctx.response.headers['Content-Type'], 'application/xml');
});
it('sets a verbose 500 for an error in dev', () => {
const ctx = selectStatus(false)({ content: { }, error }, { logger });
assertEquals(ctx.response.status, 500);
assertEquals(ctx.response.body, `<code>500</code>${error}`);
assertEquals(ctx.response.headers['Content-Type'], 'application/xml');
});
it('sets a verbose 500 for an error in production if x-debug header is present', () => {
const request = {
headers: {
'x-debug': 'true',
},
};
const ctx = selectStatus(true)({ content: { }, error }, { logger, request });
assertEquals(ctx.response.status, 500);
assertEquals(ctx.response.body, `<code>500</code>${error}`);
assertEquals(ctx.response.headers['Content-Type'], 'application/xml');
});
it('sets a 200 if all good', () => {
const ctx = selectStatus(false)({
content: {
xml: {
root: {},
},
},
},
{ logger });
assertEquals(ctx.response.status, 200);
});
});
it('Ignores non-HTML', () => {
const dat = {
response: {
body: '{}',
headers: {
'Content-Type': 'application/json',
},
},
};
const dat2 = deepclone(dat);
rewrite(dat);
assertEquals(dat, dat2);
});
it('keeps an existing status', () => {
const ctx = selectStatus(false)({
response: {
status: 201,
},
}, { logger });
assertEquals(ctx.response.status, 201);
});