mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Test error classes correctly
This commit is contained in:
@@ -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> => {
|
||||
|
||||
Reference in New Issue
Block a user