Skip to content

Commit

Permalink
test: Remove root folder creation from integration tests
Browse files Browse the repository at this point in the history
This should be handled by the initializer
  • Loading branch information
joachimvh committed Feb 11, 2021
1 parent bb65630 commit 49a04c4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
5 changes: 0 additions & 5 deletions test/integration/Config.ts
@@ -1,4 +1,3 @@
import { mkdirSync } from 'fs';
import type { IModuleState } from 'componentsjs';
import { ComponentsManager } from 'componentsjs';
import * as rimraf from 'rimraf';
Expand Down Expand Up @@ -27,10 +26,6 @@ export function getTestFolder(name: string): string {
return joinFilePath(__dirname, '../tmp', name);
}

export function createFolder(folder: string): void {
mkdirSync(folder, { recursive: true });
}

export function removeFolder(folder: string): void {
rimraf.sync(folder, { glob: false });
}
10 changes: 4 additions & 6 deletions test/integration/LdpHandlerWithAuth.test.ts
Expand Up @@ -2,30 +2,26 @@ import { createReadStream } from 'fs';
import type { HttpHandler, Initializer, ResourceStore } from '../../src/';
import { LDP, BasicRepresentation, joinFilePath } from '../../src/';
import { AclHelper, ResourceHelper } from '../util/TestHelpers';
import { BASE, getTestFolder, createFolder, removeFolder, instantiateFromConfig } from './Config';
import { BASE, getTestFolder, removeFolder, instantiateFromConfig } from './Config';

const rootFilePath = getTestFolder('full-config-acl');
const stores: [string, any][] = [
[ 'in-memory storage', {
storeUrn: 'urn:solid-server:default:MemoryResourceStore',
setup: jest.fn(),
teardown: jest.fn(),
}],
[ 'on-disk storage', {
storeUrn: 'urn:solid-server:default:FileResourceStore',
setup: (): void => createFolder(rootFilePath),
teardown: (): void => removeFolder(rootFilePath),
}],
];

describe.each(stores)('An LDP handler with auth using %s', (name, { storeUrn, setup, teardown }): void => {
describe.each(stores)('An LDP handler with auth using %s', (name, { storeUrn, teardown }): void => {
let handler: HttpHandler;
let aclHelper: AclHelper;
let resourceHelper: ResourceHelper;

beforeAll(async(): Promise<void> => {
// Set up the internal store
await setup();
const variables: Record<string, any> = {
'urn:solid-server:default:variable:baseUrl': BASE,
'urn:solid-server:default:variable:rootFilePath': rootFilePath,
Expand All @@ -46,6 +42,8 @@ describe.each(stores)('An LDP handler with auth using %s', (name, { storeUrn, se
variables,
) as Record<string, any>;
({ handler, store, initializer } = instances);

// Set up the internal store
await initializer.handleSafe();

// Create test helpers for manipulating the components
Expand Down
29 changes: 18 additions & 11 deletions test/integration/LdpHandlerWithoutAuth.test.ts
@@ -1,33 +1,29 @@
import { DataFactory, Parser } from 'n3';
import type { MockResponse } from 'node-mocks-http';
import { ensureTrailingSlash } from '../../src/';
import { ensureTrailingSlash, PIM, RDF } 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';
import { BASE, getTestFolder, removeFolder, instantiateFromConfig } from './Config';
const { literal, namedNode, quad } = DataFactory;

const rootFilePath = getTestFolder('full-config-no-auth');
const stores: [string, any][] = [
[ 'in-memory storage', {
storeUrn: 'urn:solid-server:default:MemoryResourceStore',
setup: jest.fn(),
teardown: jest.fn(),
}],
[ 'on-disk storage', {
storeUrn: 'urn:solid-server:default:FileResourceStore',
setup: (): void => createFolder(rootFilePath),
teardown: (): void => removeFolder(rootFilePath),
}],
];

describe.each(stores)('An LDP handler without auth using %s', (name, { storeUrn, setup, teardown }): void => {
describe.each(stores)('An LDP handler without auth using %s', (name, { storeUrn, teardown }): void => {
let handler: HttpHandler;
let resourceHelper: ResourceHelper;

beforeAll(async(): Promise<void> => {
// Set up the internal store
await setup();
const variables: Record<string, any> = {
'urn:solid-server:default:variable:baseUrl': BASE,
'urn:solid-server:default:variable:rootFilePath': rootFilePath,
Expand All @@ -47,6 +43,8 @@ describe.each(stores)('An LDP handler without auth using %s', (name, { storeUrn,
variables,
) as Record<string, any>;
({ handler, initializer } = instances);

// Set up the internal store
await initializer.handleSafe();

// Create test helpers for manipulating the components
Expand All @@ -63,10 +61,15 @@ describe.each(stores)('An LDP handler without auth using %s', (name, { storeUrn,
expect(response.statusCode).toBe(200);
expect(response.getHeaders()).toHaveProperty('content-type', 'text/turtle');

const data = response._getData().toString();
expect(data).toContain(`<> a ldp:Container`);
const parser = new Parser({ baseIRI: `${BASE}/` });
const quads = parser.parse(response._getData().toString());
expect(quads.some((entry): boolean => entry.equals(
quad(namedNode(`${BASE}/`), RDF.terms.type, LDP.terms.Container),
))).toBeTruthy();
expect(response.getHeaders().link).toContain(`<${LDP.Container}>; rel="type"`);
expect(response.getHeaders().link).toContain(`<${BASE}/.acl>; rel="acl"`);
// This is only here because we're accessing the root container
expect(response.getHeaders().link).toContain(`<${PIM.Storage}>; rel="type"`);
});

it('can read a folder listing with a query string.', async():
Expand All @@ -75,10 +78,14 @@ describe.each(stores)('An LDP handler without auth using %s', (name, { storeUrn,
expect(response.statusCode).toBe(200);
expect(response.getHeaders()).toHaveProperty('content-type', 'text/turtle');

const data = response._getData().toString();
expect(data).toContain(`<> a ldp:Container`);
const parser = new Parser({ baseIRI: `${BASE}/` });
const quads = parser.parse(response._getData().toString());
expect(quads.some((entry): boolean => entry.equals(
quad(namedNode(`${BASE}/`), RDF.terms.type, LDP.terms.Container),
))).toBeTruthy();
expect(response.getHeaders().link).toContain(`<${LDP.Container}>; rel="type"`);
expect(response.getHeaders().link).toContain(`<${BASE}/.acl>; rel="acl"`);
expect(response.getHeaders().link).toContain(`<${PIM.Storage}>; rel="type"`);
});

it('can add a file to the store, read it and delete it.', async():
Expand Down

0 comments on commit 49a04c4

Please sign in to comment.