Skip to content

Commit

Permalink
feat(seeding): remove template info from seeded pod guide, use mockFs…
Browse files Browse the repository at this point in the history
…, code style nit, fix redlock test
  • Loading branch information
adlerfaulkner committed Mar 9, 2022
1 parent 3a8f0c1 commit feea553
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
5 changes: 0 additions & 5 deletions guides/seeding-pods.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,3 @@ To use a pre-existing wedId:
createWebId: false,
webId: "https://pod.inrupt.com/example/profile/card#me"
```

To use a specific pod template:
```json
template: "./templates/custom_pod_template"
```
53 changes: 27 additions & 26 deletions src/init/SeededPodInitializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,33 @@ export class SeededPodInitializer extends Initializer {
}

public async handle(): Promise<void> {
if (this.configFilePath) {
const configText = await fsPromises.readFile(this.configFilePath, 'utf8');
const configuration: NodeJS.Dict<unknown>[] = JSON.parse(configText);

let count = 0;
for await (const input of configuration) {
const config = {
confirmPassword: input.password,
createPod: true,
createWebId: true,
register: true,
...input,
};

this.logger.info(`Initializing pod ${input.podName}`);

// Validate the input JSON
const validated = this.registrationManager.validateInput(config, true);
this.logger.debug(`Validated input: ${JSON.stringify(validated)}`);

// Register and/or create a pod as requested. Potentially does nothing if all booleans are false.
await this.registrationManager.register(validated, true);
this.logger.info(`Initialized seeded pod and account for "${input.podName}".`);
count += 1;
}
this.logger.info(`Initialized ${count} seeded pods.`);
if (!this.configFilePath) {
return;
}
const configText = await fsPromises.readFile(this.configFilePath, 'utf8');
const configuration: NodeJS.Dict<unknown>[] = JSON.parse(configText);

let count = 0;
for await (const input of configuration) {
const config = {
confirmPassword: input.password,
createPod: true,
createWebId: true,
register: true,
...input,
};

this.logger.info(`Initializing pod ${input.podName}`);

// Validate the input JSON
const validated = this.registrationManager.validateInput(config, true);
this.logger.debug(`Validated input: ${JSON.stringify(validated)}`);

// Register and/or create a pod as requested. Potentially does nothing if all booleans are false.
await this.registrationManager.register(validated, true);
this.logger.info(`Initialized seeded pod and account for "${input.podName}".`);
count += 1;
}
this.logger.info(`Initialized ${count} seeded pods.`);
}
}
3 changes: 3 additions & 0 deletions test/integration/config/run-with-redlock.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"files-scs:config/http/middleware/no-websockets.json",
"files-scs:config/http/server-factory/no-websockets.json",
"files-scs:config/http/static/default.json",
"files-scs:config/identity/handler/account-store/default.json",
"files-scs:config/identity/ownership/unsafe-no-check.json",
"files-scs:config/identity/pod/static.json",
"files-scs:config/ldp/authentication/debug-auth-header.json",
"files-scs:config/ldp/authorization/allow-all.json",
"files-scs:config/ldp/handler/default.json",
Expand Down
7 changes: 4 additions & 3 deletions test/unit/init/SeededPodInitializer.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from 'fs';
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');
const mockFs = fs as jest.Mocked<typeof fs>;

describe('A SeededPodInitializer', (): void => {
const dummyConfig = JSON.stringify([
Expand All @@ -28,7 +28,8 @@ describe('A SeededPodInitializer', (): void => {
register: jest.fn(),
} as any;

(mockFs.promises as unknown) = { readFile: jest.fn().mockResolvedValue(dummyConfig) };
mockFs('/');
await fsPromises.writeFile(configFilePath, dummyConfig);
});

it('does not generate any accounts or pods if no config file is specified.', async(): Promise<void> => {
Expand Down

0 comments on commit feea553

Please sign in to comment.