Skip to content

Commit

Permalink
fix: use res.send instead of res.json
Browse files Browse the repository at this point in the history
  • Loading branch information
ggurkal committed Sep 17, 2021
1 parent 0b5843d commit 2c94263
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internals/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async function runMainLayer(
res.send(returnValue.contents);
}
} else {
res.json(returnValue ?? null);
res.send(returnValue ?? null);
}
}

Expand Down
44 changes: 44 additions & 0 deletions test/e2e-buffer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'reflect-metadata';
import request from 'supertest';
import { createHandler, Get, SetHeader } from '../lib';
import { setupServer } from './setupServer';

const nextJsLogo = Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAA6UlEQVQ4ja3TMUpDYRAE4K8wYCM2kljb2IidvU2apE1ErNQcQMFCjRohx/AUXkOPYERvYBUkihKLf5+8BM3LEwe2WXaGf2b35x+xiibaBdWM2Qlc4B0jvBTUCG/oZuQOhmhhYY6XVmJ2iAN4xGUZr4ErPMAn6ljBxhzEdawF5wPG2MaulMPxDHIHrzgJzjgvAHuSt1ss54iLuJECPIrejwKwGd6ecIZTDPCMrdzcrwKwhGvc4R79qRdNCGQhlsV3iAN/W2NPrPFQCq4tHUkRKtgJzn7W7ErnWeaUz6eVa2go/kwNVEtYnY0vxaFKHj8ZCrUAAAAASUVORK5CYII=',
'base64'
);

class TestHandler {
@Get()
@SetHeader('Content-Type', 'image/png')
public image() {
return nextJsLogo;
}
}

describe('E2E - Buffer', () => {
let server: ReturnType<typeof setupServer>;
beforeAll(() => {
server = setupServer(createHandler(TestHandler));
});

afterAll(() => {
if ('close' in server && typeof server.close === 'function') {
server.close();
}
});

it('Should return the image with the correct headers.', () =>
request(server)
.get('/')
.expect(200)
.then(res =>
expect(res).toMatchObject({
header: {
'content-type': 'image/png',
'content-length': nextJsLogo.length.toString()
},
body: nextJsLogo
})
));
});

0 comments on commit 2c94263

Please # to comment.