mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { writeJson } from 'fs-extra';
|
|
import type { RegistrationManager } from '../../../src/identity/interaction/email-password/util/RegistrationManager';
|
|
import { SeededPodInitializer } from '../../../src/init/SeededPodInitializer';
|
|
import { mockFileSystem } from '../../util/Util';
|
|
|
|
jest.mock('fs');
|
|
jest.mock('fs-extra');
|
|
|
|
describe('A SeededPodInitializer', (): void => {
|
|
const dummyConfig = [
|
|
{
|
|
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;
|
|
|
|
mockFileSystem('/');
|
|
await writeJson(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);
|
|
});
|
|
});
|