Skip to content

Commit

Permalink
Add tests for DELETE with payload (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
geek authored Mar 8, 2023
1 parent 45addad commit 87a5fa2
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ describe('request()', () => {
expect(body.toString()).to.equal(internals.payload);
});

it('requests a DELETE resource with payload', async (flags) => {

const handler = (req, res) => {

expect(req.headers['content-length']).to.equal('16390');
res.writeHead(200, { 'Content-Type': 'text/plain' });
req.pipe(res);
};

const server = await internals.server(handler);
flags.onCleanup = () => server.close();
const res = await Wreck.request('delete', `http://localhost:${server.address().port}`, { payload: internals.payload });
const body = await Wreck.read(res);
expect(body.toString()).to.equal(internals.payload);
});

it('requests a POST resource', async (flags) => {

const handler = (req, res) => {
Expand Down Expand Up @@ -1680,28 +1696,44 @@ describe('Shortcut', () => {
it('patch request', async (flags) => {

const server = await internals.server('ok');
flags.onCleanup = () => server.close();
const { res, payload } = await Wreck.patch(`http://localhost:${server.address().port}`, { payload: '123' });
expect(res.statusCode).to.equal(200);
expect(payload.toString()).to.equal('ok');
flags.onCleanup = () => server.close();
});

it('put request', async (flags) => {

const server = await internals.server('ok');
flags.onCleanup = () => server.close();
const { res, payload } = await Wreck.put(`http://localhost:${server.address().port}`);
expect(res.statusCode).to.equal(200);
expect(payload.toString()).to.equal('ok');
flags.onCleanup = () => server.close();
});

it('delete request', async (flags) => {

const server = await internals.server('ok');
flags.onCleanup = () => server.close();
const { res, payload } = await Wreck.delete(`http://localhost:${server.address().port}`);
expect(res.statusCode).to.equal(200);
expect(payload.toString()).to.equal('ok');
});

it('delete request with payload', async (flags) => {

const handler = (req, res) => {

expect(req.headers['content-length']).to.equal('16390');
res.writeHead(200, { 'Content-Type': 'text/plain' });
req.pipe(res);
};

const server = await internals.server(handler);
flags.onCleanup = () => server.close();
const { res, payload } = await Wreck.delete('http://localhost:' + server.address().port, { payload: internals.payload });
expect(res.statusCode).to.equal(200);
expect(payload.toString()).to.equal(internals.payload);
});

it('errors on bad request', async (flags) => {
Expand Down

0 comments on commit 87a5fa2

Please sign in to comment.