mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Fix test issues
The root container wasn't being created for file based tests. Containers should be POSTed as RDF bodies. Containment triples of child containers had no trailing slash.
This commit is contained in:
parent
e85ca622da
commit
22962192ff
@ -6,7 +6,12 @@ import { APPLICATION_OCTET_STREAM, TEXT_TURTLE } from '../util/ContentTypes';
|
||||
import { ConflictHttpError } from '../util/errors/ConflictHttpError';
|
||||
import { NotFoundHttpError } from '../util/errors/NotFoundHttpError';
|
||||
import { UnsupportedHttpError } from '../util/errors/UnsupportedHttpError';
|
||||
import { decodeUriPathComponents, encodeUriPathComponents, trimTrailingSlashes } from '../util/Util';
|
||||
import {
|
||||
decodeUriPathComponents,
|
||||
encodeUriPathComponents,
|
||||
ensureTrailingSlash,
|
||||
trimTrailingSlashes,
|
||||
} from '../util/Util';
|
||||
import type { FileIdentifierMapper, ResourceLink } from './FileIdentifierMapper';
|
||||
|
||||
const { join: joinPath, normalize: normalizePath } = posix;
|
||||
@ -137,7 +142,7 @@ export class ExtensionBasedMapper implements FileIdentifierMapper {
|
||||
let relative = filePath.slice(this.rootFilepath.length);
|
||||
if (isContainer) {
|
||||
return {
|
||||
identifier: { path: this.baseRequestURI + encodeUriPathComponents(relative) },
|
||||
identifier: { path: ensureTrailingSlash(this.baseRequestURI + encodeUriPathComponents(relative)) },
|
||||
filePath,
|
||||
};
|
||||
}
|
||||
@ -150,7 +155,7 @@ export class ExtensionBasedMapper implements FileIdentifierMapper {
|
||||
}
|
||||
|
||||
return {
|
||||
identifier: { path: this.baseRequestURI + encodeUriPathComponents(relative) },
|
||||
identifier: { path: trimTrailingSlashes(this.baseRequestURI + encodeUriPathComponents(relative)) },
|
||||
filePath,
|
||||
contentType,
|
||||
};
|
||||
|
@ -195,7 +195,7 @@ export class FileResourceStore implements ResourceStore {
|
||||
const files = await fsPromises.readdir(path);
|
||||
const match = files.find((file): any => !file.startsWith('.metadata'));
|
||||
if (typeof match === 'string') {
|
||||
throw new ConflictHttpError('Container is not empty.');
|
||||
throw new ConflictHttpError('Can only delete empty containers.');
|
||||
}
|
||||
|
||||
// Only delete the metadata file as auxiliary resource because this is the only file created by this store.
|
||||
|
@ -17,6 +17,7 @@ describe('A server using a AuthenticatedFileResourceStore', (): void => {
|
||||
|
||||
beforeAll(async(): Promise<void> => {
|
||||
rootFilePath = getRootFilePath('AuthenticatedFileResourceStore');
|
||||
mkdirSync(rootFilePath, { recursive: true });
|
||||
config = new AuthenticatedFileResourceStoreConfig(BASE, rootFilePath);
|
||||
handler = config.getHttpHandler();
|
||||
({ store } = config);
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { mkdirSync } from 'fs';
|
||||
import * as rimraf from 'rimraf';
|
||||
import type { HttpHandler } from '../../src/server/HttpHandler';
|
||||
import { FileResourceStoreConfig } from '../configs/FileResourceStoreConfig';
|
||||
@ -13,6 +14,7 @@ describe('A server using a FileResourceStore', (): void => {
|
||||
|
||||
beforeAll(async(): Promise<void> => {
|
||||
rootFilePath = getRootFilePath('FileResourceStore');
|
||||
mkdirSync(rootFilePath, { recursive: true });
|
||||
config = new FileResourceStoreConfig(BASE, rootFilePath);
|
||||
handler = config.getHttpHandler();
|
||||
fileHelper = new FileTestHelper(handler, new URL(BASE));
|
||||
@ -109,7 +111,7 @@ describe('A server using a FileResourceStore', (): void => {
|
||||
// Try DELETE folder
|
||||
response = await fileHelper.simpleCall(new URL(folderId), 'DELETE', {});
|
||||
expect(response.statusCode).toBe(409);
|
||||
expect(response._getData()).toContain('ConflictHttpError: Container is not empty.');
|
||||
expect(response._getData()).toContain('ConflictHttpError: Can only delete empty containers.');
|
||||
|
||||
// DELETE
|
||||
await fileHelper.deleteFile('http://test.com/testfolder1/testfile0.txt');
|
||||
@ -130,7 +132,7 @@ describe('A server using a FileResourceStore', (): void => {
|
||||
// Try DELETE folder
|
||||
response = await fileHelper.simpleCall(new URL(folderId), 'DELETE', {});
|
||||
expect(response.statusCode).toBe(409);
|
||||
expect(response._getData()).toContain('ConflictHttpError: Container is not empty.');
|
||||
expect(response._getData()).toContain('ConflictHttpError: Can only delete empty containers.');
|
||||
|
||||
// DELETE
|
||||
await fileHelper.deleteFolder(subFolderId);
|
||||
@ -145,7 +147,7 @@ describe('A server using a FileResourceStore', (): void => {
|
||||
const folderId = response._getHeaders().location;
|
||||
|
||||
// Create subfolder
|
||||
response = await fileHelper.createFolder('testfolder3/subfolder0');
|
||||
response = await fileHelper.createFolder('testfolder3/subfolder0/');
|
||||
const subFolderId = response._getHeaders().location;
|
||||
|
||||
// Create file
|
||||
@ -155,7 +157,7 @@ describe('A server using a FileResourceStore', (): void => {
|
||||
response = await fileHelper.getFolder(folderId);
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response._getHeaders().location).toBe(folderId);
|
||||
expect(response._getBuffer().toString()).toContain('<http://www.w3.org/ns/ldp#contains> <http://test.com/testfolder3/subfolder0> .');
|
||||
expect(response._getBuffer().toString()).toContain('<http://www.w3.org/ns/ldp#contains> <http://test.com/testfolder3/subfolder0/> .');
|
||||
expect(response._getBuffer().toString()).toContain('<http://www.w3.org/ns/ldp#contains> <http://test.com/testfolder3/testfile0.txt> .');
|
||||
|
||||
// DELETE
|
||||
|
@ -173,7 +173,7 @@ export class FileTestHelper {
|
||||
{
|
||||
slug,
|
||||
link: '<http://www.w3.org/ns/ldp#Container>; rel="type"',
|
||||
'content-type': 'text/plain',
|
||||
'content-type': 'text/turtle',
|
||||
'transfer-encoding': 'chunked',
|
||||
},
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user