mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Support seeding pods and accounts
* feat(seeding): seed accounts and pods with seeded-pod-config.json * feat(seeding): dry up SeededPodInitializer by using RegistrationManager directly and make compatible with version/3.0.0 * feat(seeding): update seed config files to version 3.0.0 context * feat(seeding): simplify seeded-root config by importing pre-existing prefilled-root config * feat(seeding): Add seeding as a default initializer, update seeded pod copy and guide, change seeded pod config to array * feat(seeding): remove template info from seeded pod guide, use mockFs, code style nit, fix redlock test * feat(seeding): remove old config file
This commit is contained in:
@@ -62,6 +62,7 @@ describe('AppRunner', (): void => {
|
||||
'urn:solid-server:default:variable:rootFilePath': '/var/cwd/',
|
||||
'urn:solid-server:default:variable:showStackTrace': false,
|
||||
'urn:solid-server:default:variable:podConfigJson': '/var/cwd/pod-config.json',
|
||||
'urn:solid-server:default:variable:seededPodConfigJson': '/var/cwd/seeded-pod-config.json',
|
||||
};
|
||||
const createdApp = await new AppRunner().create(
|
||||
{
|
||||
@@ -99,6 +100,7 @@ describe('AppRunner', (): void => {
|
||||
'urn:solid-server:default:variable:rootFilePath': '/var/cwd/',
|
||||
'urn:solid-server:default:variable:showStackTrace': false,
|
||||
'urn:solid-server:default:variable:podConfigJson': '/var/cwd/pod-config.json',
|
||||
'urn:solid-server:default:variable:seededPodConfigJson': '/var/cwd/seeded-pod-config.json',
|
||||
};
|
||||
await new AppRunner().run(
|
||||
{
|
||||
@@ -166,6 +168,7 @@ describe('AppRunner', (): void => {
|
||||
'-s', 'http://localhost:5000/sparql',
|
||||
'-t',
|
||||
'--podConfigJson', '/different-path.json',
|
||||
'--seededPodConfigJson', '/different-path.json',
|
||||
];
|
||||
process.argv = argvParameters;
|
||||
|
||||
|
||||
47
test/unit/init/SeededPodInitializer.test.ts
Normal file
47
test/unit/init/SeededPodInitializer.test.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { promises as fsPromises } from 'fs';
|
||||
import type { RegistrationManager } from '../../../src/identity/interaction/email-password/util/RegistrationManager';
|
||||
import { SeededPodInitializer } from '../../../src/init/SeededPodInitializer';
|
||||
import { mockFs } from '../../util/Util';
|
||||
|
||||
jest.mock('fs');
|
||||
|
||||
describe('A SeededPodInitializer', (): void => {
|
||||
const dummyConfig = JSON.stringify([
|
||||
{
|
||||
podName: 'example',
|
||||
email: 'hello@example.com',
|
||||
password: 'abc123',
|
||||
},
|
||||
{
|
||||
podName: 'example2',
|
||||
email: 'hello2@example.com',
|
||||
password: '123abc',
|
||||
},
|
||||
]);
|
||||
let registrationManager: RegistrationManager;
|
||||
let configFilePath: string | null;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
configFilePath = './seeded-pod-config.json';
|
||||
registrationManager = {
|
||||
validateInput: jest.fn((input): any => input),
|
||||
register: jest.fn(),
|
||||
} as any;
|
||||
|
||||
mockFs('/');
|
||||
await fsPromises.writeFile(configFilePath, dummyConfig);
|
||||
});
|
||||
|
||||
it('does not generate any accounts or pods if no config file is specified.', async(): Promise<void> => {
|
||||
configFilePath = null;
|
||||
await new SeededPodInitializer(registrationManager, configFilePath).handle();
|
||||
expect(registrationManager.validateInput).not.toHaveBeenCalled();
|
||||
expect(registrationManager.register).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('generates an account and a pod for every entry in the seeded pod configuration.', async(): Promise<void> => {
|
||||
await new SeededPodInitializer(registrationManager, configFilePath).handle();
|
||||
expect(registrationManager.validateInput).toHaveBeenCalledTimes(2);
|
||||
expect(registrationManager.register).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
@@ -25,4 +25,9 @@ describe('An AssetPathExtractor', (): void => {
|
||||
resolver = new AssetPathExtractor('path', '/root');
|
||||
await expect(resolver.handle({ otherPath: '/var/data' })).resolves.toBe('/root');
|
||||
});
|
||||
|
||||
it('returns null if not default value or default is provided.', async(): Promise<void> => {
|
||||
resolver = new AssetPathExtractor('path');
|
||||
await expect(resolver.handle({ otherPath: '/var/data' })).resolves.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user