mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Replace dataType by binary flag
This commit is contained in:
committed by
Joachim Van Herwegen
parent
385e1a4cdf
commit
c5c5d13570
@@ -6,10 +6,10 @@ import arrayifyStream from 'arrayify-stream';
|
||||
import { DataFactory } from 'n3';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { RuntimeConfig } from '../../../src/init/RuntimeConfig';
|
||||
import { BinaryRepresentation } from '../../../src/ldp/representation/BinaryRepresentation';
|
||||
import { Representation } from '../../../src/ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata';
|
||||
import { FileResourceStore } from '../../../src/storage/FileResourceStore';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY, DATA_TYPE_QUAD } from '../../../src/util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../../src/util/ContentTypes';
|
||||
import { ConflictHttpError } from '../../../src/util/errors/ConflictHttpError';
|
||||
import { MethodNotAllowedHttpError } from '../../../src/util/errors/MethodNotAllowedHttpError';
|
||||
import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError';
|
||||
@@ -33,7 +33,7 @@ fsPromises.access = jest.fn();
|
||||
|
||||
describe('A FileResourceStore', (): void => {
|
||||
let store: FileResourceStore;
|
||||
let representation: BinaryRepresentation;
|
||||
let representation: Representation;
|
||||
let readableMock: Readable;
|
||||
let stats: Stats;
|
||||
let writeStream: WriteStream;
|
||||
@@ -56,8 +56,8 @@ describe('A FileResourceStore', (): void => {
|
||||
);
|
||||
|
||||
representation = {
|
||||
binary: true,
|
||||
data: streamifyArray([ rawData ]),
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
metadata: { raw: [], linkRel: { type: new Set() }} as RepresentationMetadata,
|
||||
};
|
||||
|
||||
@@ -116,7 +116,7 @@ describe('A FileResourceStore', (): void => {
|
||||
});
|
||||
|
||||
it('errors for wrong input data types.', async(): Promise<void> => {
|
||||
(representation as any).dataType = DATA_TYPE_QUAD;
|
||||
(representation as any).binary = false;
|
||||
await expect(store.addResource({ path: base }, representation)).rejects.toThrow(UnsupportedMediaTypeHttpError);
|
||||
await expect(store.setRepresentation({ path: `${base}foo` }, representation)).rejects
|
||||
.toThrow(UnsupportedMediaTypeHttpError);
|
||||
@@ -142,7 +142,7 @@ describe('A FileResourceStore', (): void => {
|
||||
// Read container
|
||||
const result = await store.getRepresentation(identifier);
|
||||
expect(result).toEqual({
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
metadata: {
|
||||
raw: [],
|
||||
@@ -212,7 +212,7 @@ describe('A FileResourceStore', (): void => {
|
||||
expect(fs.createWriteStream as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'file.txt'));
|
||||
const result = await store.getRepresentation({ path: `${base}file.txt` });
|
||||
expect(result).toEqual({
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
data: expect.any(Readable),
|
||||
metadata: {
|
||||
raw: [],
|
||||
@@ -365,7 +365,7 @@ describe('A FileResourceStore', (): void => {
|
||||
];
|
||||
const result = await store.getRepresentation({ path: `${base}foo/` });
|
||||
expect(result).toEqual({
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
metadata: {
|
||||
raw: [],
|
||||
@@ -492,7 +492,7 @@ describe('A FileResourceStore', (): void => {
|
||||
|
||||
const result = await store.getRepresentation({ path: `${base}.htaccess` });
|
||||
expect(result).toEqual({
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
data: expect.any(Readable),
|
||||
metadata: {
|
||||
raw: [],
|
||||
|
||||
@@ -2,25 +2,24 @@ 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 { Representation } from '../../../src/ldp/representation/Representation';
|
||||
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;
|
||||
let representation: Representation;
|
||||
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 = {
|
||||
binary: true,
|
||||
data: streamifyArray([ dataString ]),
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
metadata: {} as RepresentationMetadata,
|
||||
};
|
||||
});
|
||||
@@ -43,7 +42,7 @@ describe('A InMemoryResourceStore', (): void => {
|
||||
expect(identifier.path.startsWith(base)).toBeTruthy();
|
||||
const result = await store.getRepresentation(identifier);
|
||||
expect(result).toEqual({
|
||||
dataType: representation.dataType,
|
||||
binary: true,
|
||||
data: expect.any(Readable),
|
||||
metadata: representation.metadata,
|
||||
});
|
||||
@@ -61,7 +60,7 @@ describe('A InMemoryResourceStore', (): void => {
|
||||
await store.setRepresentation({ path: base }, representation);
|
||||
const result = await store.getRepresentation({ path: base });
|
||||
expect(result).toEqual({
|
||||
dataType: representation.dataType,
|
||||
binary: true,
|
||||
data: expect.any(Readable),
|
||||
metadata: representation.metadata,
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Representation } from '../../../../src/ldp/representation/Representatio
|
||||
import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences';
|
||||
import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import { QuadToRdfConverter } from '../../../../src/storage/conversion/QuadToRdfConverter';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../../../src/util/ContentTypes';
|
||||
|
||||
describe('A QuadToRdfConverter', (): void => {
|
||||
const converter = new QuadToRdfConverter();
|
||||
@@ -44,7 +44,7 @@ describe('A QuadToRdfConverter', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: 'text/turtle', weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toMatchObject({
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
metadata: {
|
||||
contentType: 'text/turtle',
|
||||
},
|
||||
@@ -67,7 +67,7 @@ describe('A QuadToRdfConverter', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: 'application/ld+json', weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toMatchObject({
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
metadata: {
|
||||
contentType: 'application/ld+json',
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Representation } from '../../../../src/ldp/representation/Representatio
|
||||
import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences';
|
||||
import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import { QuadToTurtleConverter } from '../../../../src/storage/conversion/QuadToTurtleConverter';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../../../src/util/ContentTypes';
|
||||
|
||||
describe('A QuadToTurtleConverter', (): void => {
|
||||
const converter = new QuadToTurtleConverter();
|
||||
@@ -29,7 +29,7 @@ describe('A QuadToTurtleConverter', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: 'text/turtle', weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toMatchObject({
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
metadata: {
|
||||
contentType: 'text/turtle',
|
||||
},
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Representation } from '../../../../src/ldp/representation/Representatio
|
||||
import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences';
|
||||
import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import { RdfToQuadConverter } from '../../../../src/storage/conversion/RdfToQuadConverter';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A RdfToQuadConverter.test.ts', (): void => {
|
||||
@@ -42,8 +42,8 @@ describe('A RdfToQuadConverter.test.ts', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toEqual({
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
metadata: {
|
||||
contentType: CONTENT_TYPE_QUADS,
|
||||
},
|
||||
@@ -63,8 +63,8 @@ describe('A RdfToQuadConverter.test.ts', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toEqual({
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
metadata: {
|
||||
contentType: CONTENT_TYPE_QUADS,
|
||||
},
|
||||
@@ -84,8 +84,8 @@ describe('A RdfToQuadConverter.test.ts', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toEqual({
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
metadata: {
|
||||
contentType: CONTENT_TYPE_QUADS,
|
||||
},
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Representation } from '../../../../src/ldp/representation/Representatio
|
||||
import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences';
|
||||
import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import { TurtleToQuadConverter } from '../../../../src/storage/conversion/TurtleToQuadConverter';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A TurtleToQuadConverter', (): void => {
|
||||
@@ -27,8 +27,8 @@ describe('A TurtleToQuadConverter', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toEqual({
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
metadata: {
|
||||
contentType: CONTENT_TYPE_QUADS,
|
||||
},
|
||||
@@ -48,8 +48,8 @@ describe('A TurtleToQuadConverter', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toEqual({
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
metadata: {
|
||||
contentType: CONTENT_TYPE_QUADS,
|
||||
},
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Lock } from '../../../../src/storage/Lock';
|
||||
import { SparqlUpdatePatchHandler } from '../../../../src/storage/patch/SparqlUpdatePatchHandler';
|
||||
import { ResourceLocker } from '../../../../src/storage/ResourceLocker';
|
||||
import { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A SparqlUpdatePatchHandler', (): void => {
|
||||
@@ -72,7 +72,7 @@ describe('A SparqlUpdatePatchHandler', (): void => {
|
||||
const setParams = (source.setRepresentation as jest.Mock).mock.calls[0];
|
||||
expect(setParams[0]).toEqual({ path: 'path' });
|
||||
expect(setParams[1]).toEqual(expect.objectContaining({
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
binary: false,
|
||||
metadata: { raw: [], profiles: [], contentType: CONTENT_TYPE_QUADS },
|
||||
}));
|
||||
await expect(arrayifyStream(setParams[1].data)).resolves.toBeRdfIsomorphic(quads);
|
||||
|
||||
Reference in New Issue
Block a user