Skip to content

Commit

Permalink
Merge pull request #719 from aoberoi/fix-incoming-webhook-agent-test
Browse files Browse the repository at this point in the history
Fix incoming webhook agent test
  • Loading branch information
aoberoi committed Mar 7, 2019
2 parents af5842e + 1813a8f commit e62f4e5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
61 changes: 36 additions & 25 deletions src/IncomingWebhook.spec.js
Expand Up @@ -108,16 +108,24 @@ describe('IncomingWebhook', function () {
});

describe('has an option to set a custom HTTP agent', function () {
it('should send a request using the custom agent', function (done) {
const agent = new Agent({keepAlive: true});
it('should send a request using the custom agent', function () {
const agent = new Agent({ keepAlive: true });
const spy = sinon.spy(agent, 'addRequest');
const webhook = new IncomingWebhook(url, {agent});
webhook.send('Hello', () => {
// assert(spy.called);
agent.addRequest.restore();
agent.destroy();
done();
});
const webhook = new IncomingWebhook(url, { agent });

return webhook.send('Hello')
.catch(() => {
assert(spy.called);
})
.then(() => {
agent.addRequest.restore();
agent.destroy();
})
.catch((error) => {
agent.addRequest.restore();
agent.destroy();
throw error;
});
});

it('should use the right custom agent when providing agents for many schemes', function () {
Expand All @@ -129,24 +137,27 @@ describe('IncomingWebhook', function () {
http: badAgent,
} });

webhook.send('Hello')
.catch(() => {
assert(spy.called);
}).then( () => {
agent.addRequest.restore();
agent.destroy();
}).catch((error) => {
agent.addRequest.restore();
agent.destroy();
throw error;
});
return webhook.send('Hello')
.catch(() => {
assert(spy.called);
}).then( () => {
agent.addRequest.restore();
agent.destroy();
}).catch((error) => {
agent.addRequest.restore();
agent.destroy();
throw error;
});
});

it('should use accept a boolean (false) agent', function (done) {
const webhook = new IncomingWebhook(url, {agent: false});
webhook.send('Hello', () => {
done();
});
it('should use accept a boolean (false) agent', function () {
const webhook = new IncomingWebhook(url, { agent: false });
const result = webhook.send('Hello');
return result.catch((error) => { });
});
});

afterEach(function () {
nock.cleanAll();
});
});
2 changes: 2 additions & 0 deletions src/IncomingWebhook.ts
Expand Up @@ -38,6 +38,8 @@ export class IncomingWebhook {
proxy: false,
});

delete this.defaults.agent;

}

/**
Expand Down

0 comments on commit e62f4e5

Please sign in to comment.