fix: Make Patch more consistent with other Representations

This commit is contained in:
Joachim Van Herwegen
2020-08-04 10:05:48 +02:00
parent 14db5fed91
commit d6a35f9954
6 changed files with 24 additions and 18 deletions

View File

@@ -120,8 +120,8 @@ describe('An AuthenticatedLdpHandler', (): void => {
describe('with simple PATCH handlers', (): void => {
const bodyParser: BodyParser = new CompositeAsyncHandler<HttpRequest, Representation | undefined>([
new SimpleBodyParser(),
new SimpleSparqlUpdateBodyParser(),
new SimpleBodyParser(),
]);
const requestParser = new SimpleRequestParser({
targetExtractor: new SimpleTargetExtractor(),

View File

@@ -1,4 +1,6 @@
import { Algebra } from 'sparqlalgebrajs';
import arrayifyStream from 'arrayify-stream';
import { DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes';
import { HttpRequest } from '../../../../src/server/HttpRequest';
import { SimpleSparqlUpdateBodyParser } from '../../../../src/ldp/http/SimpleSparqlUpdateBodyParser';
import streamifyArray from 'streamify-array';
@@ -32,13 +34,16 @@ describe('A SimpleSparqlUpdateBodyParser', (): void => {
namedNode('http://test.com/p'),
namedNode('http://test.com/o'),
) ]);
expect(result.dataType).toBe('sparql-algebra');
expect(result.raw).toBe('DELETE DATA { <http://test.com/s> <http://test.com/p> <http://test.com/o>}');
expect(result.dataType).toBe(DATA_TYPE_BINARY);
expect(result.metadata).toEqual({
raw: [],
profiles: [],
contentType: 'application/sparql-update',
});
expect((): any => result.data).toThrow('Body already parsed');
// Workaround for Node 10 not exposing objectMode
expect((await arrayifyStream(result.data)).join('')).toEqual(
'DELETE DATA { <http://test.com/s> <http://test.com/p> <http://test.com/o>}',
);
});
});

View File

@@ -80,9 +80,9 @@ describe('A SimpleSparqlUpdatePatchHandler', (): void => {
it('only accepts SPARQL updates.', async(): Promise<void> => {
const input = { identifier: { path: 'path' },
patch: { dataType: 'sparql-algebra', algebra: {}} as SparqlUpdatePatch };
patch: { algebra: {}} as SparqlUpdatePatch };
await expect(handler.canHandle(input)).resolves.toBeUndefined();
input.patch.dataType = 'notAlgebra';
delete input.patch.algebra;
await expect(handler.canHandle(input)).rejects.toThrow(UnsupportedHttpError);
});