|
1 | 1 | import test from 'ava'; |
2 | 2 | import m from '.'; |
3 | 3 |
|
4 | | -test('empty test', t => { |
5 | | - t.is(m.thrown(), false); |
| 4 | +test('should throw InternalServer error with an invalid type', t => { |
| 5 | + const out = m.throw('a', 'An error message', 'errorno'); |
| 6 | + t.is(out.body.code, 'InternalServer'); |
| 7 | + t.is(out.message, 'An error message'); |
| 8 | + t.is(out.body.errno, 'errorno'); |
| 9 | + t.is(out.context.debug[0], 'Invalid error type provided:InternalServerError'); |
| 10 | +}); |
| 11 | + |
| 12 | +test('should throw the correct error with a valid type', t => { |
| 13 | + const pres = m.throw('LockedError', 'Requested resource is locked', '42'); |
| 14 | + t.is(pres.body.code, 'Locked'); |
| 15 | + t.is(pres.message, 'Requested resource is locked'); |
| 16 | + t.is(pres.body.errno, '42'); |
| 17 | + t.is(pres.context.debug.length, 0); |
| 18 | +}); |
| 19 | + |
| 20 | +test('should contain debug information', t => { |
| 21 | + const pres = m.throw('LockedError', 'Requested resource is locked', '42', 'debugField1', 33); |
| 22 | + t.is(pres.body.code, 'Locked'); |
| 23 | + t.is(pres.message, 'Requested resource is locked'); |
| 24 | + t.is(pres.body.errno, '42'); |
| 25 | + t.is(pres.context.debug[0], 'debugField1'); |
| 26 | + t.is(pres.context.debug[1], 33); |
| 27 | + t.is(pres.context.debug.length, 2); |
| 28 | +}); |
| 29 | + |
| 30 | +test('should return false, if error does not exist', t => { |
| 31 | + const out = m.throw('InexistentError', 'This error does not exist', 130); |
| 32 | + t.is(m.thrown(out, 'InexistentError'), false); |
| 33 | +}); |
| 34 | + |
| 35 | +test('should return true, if the error exists', t => { |
| 36 | + const out = m.throw('WrongAcceptError', 'I cannot accept this', 118); |
| 37 | + t.is(m.thrown(out, 'WrongAcceptError'), true); |
6 | 38 | }); |
0 commit comments