mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
test: Remove node-mocks-http references from integration tests
This commit is contained in:
@@ -1,15 +1,24 @@
|
||||
import type { HttpHandler, Initializer, ResourceStore } from '../../src/';
|
||||
import { describeIf, ResourceHelper } from '../util/TestHelpers';
|
||||
import { BASE, instantiateFromConfig } from './Config';
|
||||
import { promises as fs } from 'fs';
|
||||
import type { Server } from 'http';
|
||||
import { joinFilePath } from '../../src/';
|
||||
import type { Initializer, ResourceStore } from '../../src/';
|
||||
import type { HttpServerFactory } from '../../src/server/HttpServerFactory';
|
||||
import { putResource } from '../util/FetchUtil';
|
||||
import { describeIf, getPort } from '../util/Util';
|
||||
import { instantiateFromConfig } from './Config';
|
||||
|
||||
const port = getPort('SparqlStorage');
|
||||
const baseUrl = `http://localhost:${port}/`;
|
||||
|
||||
describeIf('docker', 'A server with a SPARQL endpoint as storage', (): void => {
|
||||
let handler: HttpHandler;
|
||||
let resourceHelper: ResourceHelper;
|
||||
let server: Server;
|
||||
let initializer: Initializer;
|
||||
let factory: HttpServerFactory;
|
||||
|
||||
beforeAll(async(): Promise<void> => {
|
||||
// Set up the internal store
|
||||
const variables: Record<string, any> = {
|
||||
'urn:solid-server:default:variable:baseUrl': BASE,
|
||||
'urn:solid-server:default:variable:port': port,
|
||||
'urn:solid-server:default:variable:baseUrl': baseUrl,
|
||||
'urn:solid-server:default:variable:sparqlEndpoint': 'http://localhost:4000/sparql',
|
||||
};
|
||||
const internalStore = await instantiateFromConfig(
|
||||
@@ -19,24 +28,29 @@ describeIf('docker', 'A server with a SPARQL endpoint as storage', (): void => {
|
||||
) as ResourceStore;
|
||||
variables['urn:solid-server:default:variable:store'] = internalStore;
|
||||
|
||||
// Create and initialize the HTTP handler and related components
|
||||
let initializer: Initializer;
|
||||
// Create and initialize the server
|
||||
const instances = await instantiateFromConfig(
|
||||
'urn:solid-server:test:Instances',
|
||||
'ldp-with-auth.json',
|
||||
variables,
|
||||
) as Record<string, any>;
|
||||
({ handler, initializer } = instances);
|
||||
await initializer.handleSafe();
|
||||
({ factory, initializer } = instances);
|
||||
|
||||
// Create test helpers for manipulating the components
|
||||
resourceHelper = new ResourceHelper(handler, BASE);
|
||||
await initializer.handleSafe();
|
||||
server = factory.startServer(port);
|
||||
});
|
||||
|
||||
it('can add a Turtle file to the store.', async():
|
||||
Promise<void> => {
|
||||
afterAll(async(): Promise<void> => {
|
||||
await new Promise((resolve, reject): void => {
|
||||
server.close((error): void => error ? reject(error) : resolve());
|
||||
});
|
||||
});
|
||||
|
||||
it('can add a Turtle file to the store.', async(): Promise<void> => {
|
||||
// PUT
|
||||
const response = await resourceHelper.createResource('../assets/person.ttl', 'person', 'text/turtle');
|
||||
const documentUrl = `${baseUrl}person`;
|
||||
const body = (await fs.readFile(joinFilePath(__dirname, '../assets/person.ttl'))).toString('utf-8');
|
||||
const response = await putResource(documentUrl, { contentType: 'text/turtle', body });
|
||||
expect(response).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user