mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
test: Move diamond identifier test to ldp handler tests
This commit is contained in:
parent
b762125ee5
commit
d3c8069aa3
@ -1,63 +0,0 @@
|
||||
import 'jest-rdf';
|
||||
import type { Server } from 'http';
|
||||
import { join } from 'path';
|
||||
import arrayifyStream from 'arrayify-stream';
|
||||
import fetch from 'cross-fetch';
|
||||
import { DataFactory, StreamParser } from 'n3';
|
||||
import type { Quad } from 'n3';
|
||||
import type { HttpServerFactory } from '../../src/server/HttpServerFactory';
|
||||
import { instantiateFromConfig } from './Config';
|
||||
const { literal, namedNode, quad } = DataFactory;
|
||||
|
||||
const port = 6003;
|
||||
const baseUrl = `http://localhost:${port}/`;
|
||||
|
||||
describe('A server', (): void => {
|
||||
let server: Server;
|
||||
|
||||
beforeAll(async(): Promise<void> => {
|
||||
const factory = await instantiateFromConfig(
|
||||
'urn:solid-server:default:ServerFactory', 'server-without-auth.json', {
|
||||
'urn:solid-server:default:variable:port': port,
|
||||
'urn:solid-server:default:variable:baseUrl': baseUrl,
|
||||
'urn:solid-server:default:variable:podTemplateFolder': join(__dirname, '../assets/templates'),
|
||||
},
|
||||
) as HttpServerFactory;
|
||||
server = factory.startServer(port);
|
||||
});
|
||||
|
||||
afterAll(async(): Promise<void> => {
|
||||
await new Promise((resolve, reject): void => {
|
||||
server.close((error): void => error ? reject(error) : resolve());
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a container.', async(): Promise<void> => {
|
||||
const slug = 'my-container';
|
||||
let response = await fetch(baseUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'text/turtle',
|
||||
link: '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"',
|
||||
slug,
|
||||
},
|
||||
body: '<> <http://www.w3.org/2000/01/rdf-schema#label> "My Container" .',
|
||||
});
|
||||
expect(response.status).toBe(201);
|
||||
expect(response.headers.get('location')).toBe(`${baseUrl}${slug}/`);
|
||||
|
||||
response = await fetch(`${baseUrl}${slug}/`, {
|
||||
headers: {
|
||||
accept: 'text/turtle',
|
||||
},
|
||||
});
|
||||
expect(response.status).toBe(200);
|
||||
|
||||
const quads: Quad[] = await arrayifyStream((response.body as any).pipe(new StreamParser({ baseIRI: baseUrl })));
|
||||
expect(quads.some((entry): boolean => entry.equals(quad(
|
||||
namedNode(`${baseUrl}${slug}/`),
|
||||
namedNode('http://www.w3.org/2000/01/rdf-schema#label'),
|
||||
literal('My Container'),
|
||||
)))).toBeTruthy();
|
||||
});
|
||||
});
|
@ -1,7 +1,11 @@
|
||||
import { DataFactory, Parser } from 'n3';
|
||||
import type { MockResponse } from 'node-mocks-http';
|
||||
import { ensureTrailingSlash } from '../../src/';
|
||||
import type { HttpHandler, Initializer, ResourceStore } from '../../src/';
|
||||
import { LDP } from '../../src/util/Vocabularies';
|
||||
import { ResourceHelper } from '../util/TestHelpers';
|
||||
import { BASE, getTestFolder, createFolder, removeFolder, instantiateFromConfig } from './Config';
|
||||
const { literal, namedNode, quad } = DataFactory;
|
||||
|
||||
const rootFilePath = getTestFolder('full-config-no-auth');
|
||||
const stores: [string, any][] = [
|
||||
@ -229,4 +233,34 @@ describe.each(stores)('An LDP handler without auth using %s', (name, { storeUrn,
|
||||
await resourceHelper.deleteResource(fileId);
|
||||
await resourceHelper.shouldNotExist(fileId);
|
||||
});
|
||||
|
||||
it('can create a container with a diamond identifier in the data.', async(): Promise<void> => {
|
||||
const slug = 'my-container';
|
||||
|
||||
let response: MockResponse<any> = await resourceHelper.performRequestWithBody(
|
||||
new URL(ensureTrailingSlash(BASE)),
|
||||
'POST',
|
||||
{
|
||||
'content-type': 'text/turtle',
|
||||
'transfer-encoding': 'chunked',
|
||||
link: '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"',
|
||||
slug,
|
||||
},
|
||||
Buffer.from('<> <http://www.w3.org/2000/01/rdf-schema#label> "My Container" .', 'utf-8'),
|
||||
);
|
||||
|
||||
expect(response.statusCode).toBe(201);
|
||||
expect(response._getHeaders().location).toBe(`${BASE}/${slug}/`);
|
||||
|
||||
response = await resourceHelper.performRequest(new URL(`${BASE}/${slug}/`), 'GET', { accept: 'text/turtle' });
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const parser = new Parser();
|
||||
const quads = parser.parse(response._getData());
|
||||
expect(quads.some((entry): boolean => entry.equals(quad(
|
||||
namedNode(`${BASE}/${slug}/`),
|
||||
namedNode('http://www.w3.org/2000/01/rdf-schema#label'),
|
||||
literal('My Container'),
|
||||
)))).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user