mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Add migration for v6 account data
This commit is contained in:
69
test/unit/init/migration/SingleContainerJsonStorage.test.ts
Normal file
69
test/unit/init/migration/SingleContainerJsonStorage.test.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { BasicRepresentation } from '../../../../src/http/representation/BasicRepresentation';
|
||||
import type { Representation } from '../../../../src/http/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../../../src/http/representation/RepresentationMetadata';
|
||||
import { SingleContainerJsonStorage } from '../../../../src/init/migration/SingleContainerJsonStorage';
|
||||
import { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { NotFoundHttpError } from '../../../../src/util/errors/NotFoundHttpError';
|
||||
import { isContainerIdentifier } from '../../../../src/util/PathUtil';
|
||||
import { LDP } from '../../../../src/util/Vocabularies';
|
||||
|
||||
describe('A SingleContainerJsonStorage', (): void => {
|
||||
const baseUrl = 'http://example.com/';
|
||||
const container = '.internal/accounts/';
|
||||
let store: jest.Mocked<ResourceStore>;
|
||||
let storage: SingleContainerJsonStorage<any>;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
store = {
|
||||
getRepresentation: jest.fn(async(id): Promise<Representation> => {
|
||||
if (isContainerIdentifier(id)) {
|
||||
const metadata = new RepresentationMetadata(id);
|
||||
metadata.add(LDP.terms.contains, 'http://example.com/.internal/accounts/foo');
|
||||
metadata.add(LDP.terms.contains, 'http://example.com/.internal/accounts/bar/');
|
||||
metadata.add(LDP.terms.contains, 'http://example.com/.internal/accounts/baz');
|
||||
metadata.add(LDP.terms.contains, 'http://example.com/.internal/accounts/unknown');
|
||||
return new BasicRepresentation('', metadata);
|
||||
}
|
||||
if (id.path.endsWith('unknown')) {
|
||||
throw new NotFoundHttpError();
|
||||
}
|
||||
return new BasicRepresentation(`{ "id": "${id.path}" }`, 'text/plain');
|
||||
}),
|
||||
} satisfies Partial<ResourceStore> as any;
|
||||
|
||||
storage = new SingleContainerJsonStorage(store, baseUrl, container);
|
||||
});
|
||||
|
||||
it('only iterates over the documents in the base container.', async(): Promise<void> => {
|
||||
const entries = [];
|
||||
for await (const entry of storage.entries()) {
|
||||
entries.push(entry);
|
||||
}
|
||||
expect(entries).toEqual([
|
||||
[ '/foo', { id: 'http://example.com/.internal/accounts/foo' }],
|
||||
[ '/baz', { id: 'http://example.com/.internal/accounts/baz' }],
|
||||
]);
|
||||
expect(store.getRepresentation).toHaveBeenCalledTimes(4);
|
||||
expect(store.getRepresentation).toHaveBeenNthCalledWith(1,
|
||||
{ path: 'http://example.com/.internal/accounts/' },
|
||||
{});
|
||||
expect(store.getRepresentation).toHaveBeenNthCalledWith(2,
|
||||
{ path: 'http://example.com/.internal/accounts/foo' },
|
||||
{ type: { 'application/json': 1 }});
|
||||
expect(store.getRepresentation).toHaveBeenNthCalledWith(3,
|
||||
{ path: 'http://example.com/.internal/accounts/baz' },
|
||||
{ type: { 'application/json': 1 }});
|
||||
expect(store.getRepresentation).toHaveBeenNthCalledWith(4,
|
||||
{ path: 'http://example.com/.internal/accounts/unknown' },
|
||||
{ type: { 'application/json': 1 }});
|
||||
});
|
||||
|
||||
it('does nothing if the container does not exist.', async(): Promise<void> => {
|
||||
store.getRepresentation.mockRejectedValueOnce(new NotFoundHttpError());
|
||||
const entries = [];
|
||||
for await (const entry of storage.entries()) {
|
||||
entries.push(entry);
|
||||
}
|
||||
expect(entries).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user