mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00

* refactor: move toCachedNamedNode (private) * chore: only NamedNodes predicates in removes * feat: enforce NamedNode predicates in most cases * feat: getAll only accepts NamedNodes * feat: toCachedNamedNode only accepts string arg * tests: use NamedNodes for getAll calls * test: remove unnecessary string check for coverage * tests: fix NamedNodes in new tests after rebase * feat: metadatawriters store NamedNodes * refactor: toCachedNamedNode as utility function * fix: double write of linkRelMap * test: use the CONTENT_TYPE constant
50 lines
2.6 KiB
TypeScript
50 lines
2.6 KiB
TypeScript
import { PostOperationHandler } from '../../../../src/http/ldp/PostOperationHandler';
|
|
import type { Operation } from '../../../../src/http/Operation';
|
|
import { BasicRepresentation } from '../../../../src/http/representation/BasicRepresentation';
|
|
import type { Representation } from '../../../../src/http/representation/Representation';
|
|
import { RepresentationMetadata } from '../../../../src/http/representation/RepresentationMetadata';
|
|
import type { ResourceIdentifier } from '../../../../src/http/representation/ResourceIdentifier';
|
|
import { BasicConditions } from '../../../../src/storage/BasicConditions';
|
|
import type { ResourceStore } from '../../../../src/storage/ResourceStore';
|
|
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
|
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
|
|
import { SOLID_HTTP } from '../../../../src/util/Vocabularies';
|
|
|
|
describe('A PostOperationHandler', (): void => {
|
|
let operation: Operation;
|
|
let body: Representation;
|
|
const conditions = new BasicConditions({});
|
|
let store: ResourceStore;
|
|
let handler: PostOperationHandler;
|
|
|
|
beforeEach(async(): Promise<void> => {
|
|
body = new BasicRepresentation('', 'text/turtle');
|
|
operation = { method: 'POST', target: { path: 'http://test.com/foo' }, body, conditions, preferences: {}};
|
|
store = {
|
|
addResource: jest.fn(async(): Promise<ResourceIdentifier> => ({ path: 'newPath' } as ResourceIdentifier)),
|
|
} as unknown as ResourceStore;
|
|
handler = new PostOperationHandler(store);
|
|
});
|
|
|
|
it('only supports POST operations.', async(): Promise<void> => {
|
|
await expect(handler.canHandle({ operation })).resolves.toBeUndefined();
|
|
operation.method = 'GET';
|
|
await expect(handler.canHandle({ operation })).rejects.toThrow(NotImplementedHttpError);
|
|
});
|
|
|
|
it('errors if there is no content-type.', async(): Promise<void> => {
|
|
operation.body.metadata.contentType = undefined;
|
|
await expect(handler.handle({ operation })).rejects.toThrow(BadRequestHttpError);
|
|
});
|
|
|
|
it('adds the given representation to the store and returns the correct response.', async(): Promise<void> => {
|
|
const result = await handler.handle({ operation });
|
|
expect(result.statusCode).toBe(201);
|
|
expect(result.metadata).toBeInstanceOf(RepresentationMetadata);
|
|
expect(result.metadata?.get(SOLID_HTTP.terms.location)?.value).toBe('newPath');
|
|
expect(result.data).toBeUndefined();
|
|
expect(store.addResource).toHaveBeenCalledTimes(1);
|
|
expect(store.addResource).toHaveBeenLastCalledWith(operation.target, body, conditions);
|
|
});
|
|
});
|