fix: Test error classes correctly

This commit is contained in:
Joachim Van Herwegen
2021-01-28 17:16:11 +01:00
parent a57105be8e
commit c29928c32c
18 changed files with 110 additions and 78 deletions

View File

@@ -1,6 +1,7 @@
import type { ResourceStore } from '../../../../src/storage/ResourceStore';
import { RegexRouterRule } from '../../../../src/storage/routing/RegexRouterRule';
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
describe('A RegexRouterRule', (): void => {
const base = 'http://test.com/';
@@ -8,14 +9,16 @@ describe('A RegexRouterRule', (): void => {
it('rejects identifiers not containing the base.', async(): Promise<void> => {
const router = new RegexRouterRule(base, {});
await expect(router.canHandle({ identifier: { path: 'http://notTest.com/apple' }}))
.rejects.toThrow(new BadRequestHttpError(`Identifiers need to start with http://test.com`));
const result = router.canHandle({ identifier: { path: 'http://notTest.com/apple' }});
await expect(result).rejects.toThrow(BadRequestHttpError);
await expect(result).rejects.toThrow('Identifiers need to start with http://test.com');
});
it('rejects identifiers not matching any regex.', async(): Promise<void> => {
const router = new RegexRouterRule(base, { pear: store });
await expect(router.canHandle({ identifier: { path: `${base}apple/` }}))
.rejects.toThrow(new BadRequestHttpError(`No stored regexes match http://test.com/apple/`));
const result = router.canHandle({ identifier: { path: `${base}apple/` }});
await expect(result).rejects.toThrow(NotImplementedHttpError);
await expect(result).rejects.toThrow('No stored regexes match http://test.com/apple/');
});
it('accepts identifiers matching any regex.', async(): Promise<void> => {