mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Remove overused "Simple" prefix
This commit is contained in:
75
test/unit/storage/InMemoryResourceStore.test.ts
Normal file
75
test/unit/storage/InMemoryResourceStore.test.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { Readable } from 'stream';
|
||||
import arrayifyStream from 'arrayify-stream';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { RuntimeConfig } from '../../../src/init/RuntimeConfig';
|
||||
import { BinaryRepresentation } from '../../../src/ldp/representation/BinaryRepresentation';
|
||||
import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata';
|
||||
import { InMemoryResourceStore } from '../../../src/storage/InMemoryResourceStore';
|
||||
import { DATA_TYPE_BINARY } from '../../../src/util/ContentTypes';
|
||||
import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError';
|
||||
|
||||
const base = 'http://test.com/';
|
||||
|
||||
describe('A InMemoryResourceStore', (): void => {
|
||||
let store: InMemoryResourceStore;
|
||||
let representation: BinaryRepresentation;
|
||||
const dataString = '<http://test.com/s> <http://test.com/p> <http://test.com/o>.';
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
store = new InMemoryResourceStore(new RuntimeConfig({ base }));
|
||||
|
||||
representation = {
|
||||
data: streamifyArray([ dataString ]),
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
metadata: {} as RepresentationMetadata,
|
||||
};
|
||||
});
|
||||
|
||||
it('errors if a resource was not found.', async(): Promise<void> => {
|
||||
await expect(store.getRepresentation({ path: `${base}wrong` })).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(store.addResource({ path: 'http://wrong.com/wrong' }, representation))
|
||||
.rejects.toThrow(NotFoundHttpError);
|
||||
await expect(store.deleteResource({ path: 'wrong' })).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(store.setRepresentation({ path: 'http://wrong.com/' }, representation))
|
||||
.rejects.toThrow(NotFoundHttpError);
|
||||
});
|
||||
|
||||
it('errors when modifying resources.', async(): Promise<void> => {
|
||||
await expect(store.modifyResource()).rejects.toThrow(Error);
|
||||
});
|
||||
|
||||
it('can write and read data.', async(): Promise<void> => {
|
||||
const identifier = await store.addResource({ path: base }, representation);
|
||||
expect(identifier.path.startsWith(base)).toBeTruthy();
|
||||
const result = await store.getRepresentation(identifier);
|
||||
expect(result).toEqual({
|
||||
dataType: representation.dataType,
|
||||
data: expect.any(Readable),
|
||||
metadata: representation.metadata,
|
||||
});
|
||||
await expect(arrayifyStream(result.data)).resolves.toEqual([ dataString ]);
|
||||
});
|
||||
|
||||
it('can add resources to previously added resources.', async(): Promise<void> => {
|
||||
const identifier = await store.addResource({ path: base }, representation);
|
||||
representation.data = streamifyArray([ ]);
|
||||
const childIdentifier = await store.addResource(identifier, representation);
|
||||
expect(childIdentifier.path).toContain(identifier.path);
|
||||
});
|
||||
|
||||
it('can set data.', async(): Promise<void> => {
|
||||
await store.setRepresentation({ path: base }, representation);
|
||||
const result = await store.getRepresentation({ path: base });
|
||||
expect(result).toEqual({
|
||||
dataType: representation.dataType,
|
||||
data: expect.any(Readable),
|
||||
metadata: representation.metadata,
|
||||
});
|
||||
await expect(arrayifyStream(result.data)).resolves.toEqual([ dataString ]);
|
||||
});
|
||||
|
||||
it('can delete data.', async(): Promise<void> => {
|
||||
await store.deleteResource({ path: base });
|
||||
await expect(store.getRepresentation({ path: base })).rejects.toThrow(NotFoundHttpError);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user