forked from slackapi/bolt-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.spec.ts
38 lines (34 loc) · 1.23 KB
/
errors.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { assert } from 'chai';
import {
asCodedError,
ErrorCode,
CodedError,
AppInitializationError,
AuthorizationError,
ContextMissingPropertyError,
ReceiverAuthenticityError,
ReceiverMultipleAckError,
UnknownError,
} from './errors';
describe('Errors', () => {
it('has errors matching codes', () => {
const errorMap = {
[ErrorCode.AppInitializationError]: new AppInitializationError(),
[ErrorCode.AuthorizationError]: new AuthorizationError('auth failed', new Error('auth failed')),
[ErrorCode.ContextMissingPropertyError]: new ContextMissingPropertyError('foo', "can't find foo"),
[ErrorCode.ReceiverAuthenticityError]: new ReceiverAuthenticityError(),
[ErrorCode.ReceiverMultipleAckError]: new ReceiverMultipleAckError(),
[ErrorCode.UnknownError]: new UnknownError(new Error('It errored')),
};
Object.entries(errorMap).forEach(([code, error]) => {
assert.equal((error as CodedError).code, code);
});
});
it('wraps non-coded errors', () => {
assert.instanceOf(asCodedError(new Error('AHH!')), UnknownError);
});
it('passes coded errors through', () => {
const error = new AppInitializationError();
assert.equal(asCodedError(error), error);
});
});