Skip to content

Commit

Permalink
mocking slack requests in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Parama92 committed May 7, 2024
1 parent 412ae9a commit 4a69b93
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions packages/web-api/src/WebClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1613,42 +1613,46 @@ describe('WebClient', function () {
});

describe('has an option to suppress request error from Axios', () => {

beforeEach(function () {
this.scope = nock('https://slack.com')
.post(/api/)
.replyWithError('Request failed!!')
})

it('the \'original\' property is attached when the option, attachOriginalToWebAPIRequestError is absent', async () => {
const client = new WebClient(token, {
timeout: 10,
retryConfig: rapidRetryPolicy,
const client = new WebClient(token);

client.apiCall('conversations/list').catch((error) => {
expect(error).to.haveOwnProperty('original')
this.scope.done();
done();
});
try {
await client.conversations.list()
} catch(err) {
expect(err).to.haveOwnProperty('original')
}

});

it('the \'original\' property is attached when the option, attachOriginalToWebAPIRequestError is set to true', async () => {
const client = new WebClient(token, {
timeout: 10,
retryConfig: rapidRetryPolicy,
attachOriginalToWebAPIRequestError: true,
});
try {
await client.conversations.list()
} catch(err) {
expect(err).to.haveOwnProperty('original')
}

client.apiCall('conversations/list').catch((error) => {
expect(error).to.haveOwnProperty('original')
this.scope.done();
done();
});
});

it('the \'original\' property is not attached when the option, attachOriginalToWebAPIRequestError is set to false', async () => {
const client = new WebClient(token, {
timeout: 10,
retryConfig: rapidRetryPolicy,
attachOriginalToWebAPIRequestError: false,
});
try {
await client.conversations.list()
} catch(err) {
expect(err).not.to.haveOwnProperty('original')
}

client.apiCall('conversations/list').catch((error) => {
expect(error).not.to.haveOwnProperty('original')
this.scope.done();
done();
});
});
});

Expand Down

0 comments on commit 4a69b93

Please sign in to comment.