refactor: More precise error messages

This commit is contained in:
Ruben Verborgh
2020-09-04 23:15:35 +02:00
parent 389fb33334
commit 063437e5c1
2 changed files with 18 additions and 20 deletions

View File

@@ -12,14 +12,14 @@ describe('A SparqlPatchPermissionsExtractor', (): void => {
const operation = { method: 'PATCH', body: { algebra: factory.createDeleteInsert() }} as unknown as Operation;
await expect(extractor.canHandle(operation)).resolves.toBeUndefined();
await expect(extractor.canHandle({ ...operation, method: 'GET' }))
.rejects.toThrow(new UnsupportedHttpError('Only PATCH operations are supported.'));
.rejects.toThrow(new UnsupportedHttpError('Cannot determine permissions of GET, only PATCH.'));
await expect(extractor.canHandle({ ...operation, body: undefined }))
.rejects.toThrow(new UnsupportedHttpError('PATCH body is required to determine permissions.'));
.rejects.toThrow(new UnsupportedHttpError('Cannot determine permissions of PATCH operations without a body.'));
await expect(extractor.canHandle({ ...operation, body: {} as SparqlUpdatePatch }))
.rejects.toThrow(new UnsupportedHttpError('Only SPARQL update PATCHes are supported.'));
.rejects.toThrow(new UnsupportedHttpError('Cannot determine permissions of non-SPARQL patches.'));
await expect(extractor.canHandle({ ...operation,
body: { algebra: factory.createMove('DEFAULT', 'DEFAULT') } as unknown as SparqlUpdatePatch }))
.rejects.toThrow(new UnsupportedHttpError('Only DELETE/INSERT SPARQL update operations are supported.'));
.rejects.toThrow(new UnsupportedHttpError('Cannot determine permissions of a PATCH without DELETE/INSERT.'));
});
it('requires append for INSERT operations.', async(): Promise<void> => {