import { AccountInitializer } from '../../../src/identity/AccountInitializer'; import type { AccountStore } from '../../../src/identity/interaction/account/util/AccountStore'; import type { PasswordStore } from '../../../src/identity/interaction/password/util/PasswordStore'; import type { PodCreator } from '../../../src/identity/interaction/pod/util/PodCreator'; describe('An AccountInitializer', (): void => { const email = 'email@example.com'; const password = 'password!'; let accountStore: jest.Mocked; let passwordStore: jest.Mocked; let podCreator: jest.Mocked; let initializer: AccountInitializer; beforeEach(async(): Promise => { accountStore = { create: jest.fn().mockResolvedValue('account-id'), } satisfies Partial as any; passwordStore = { create: jest.fn().mockResolvedValue('password-id'), confirmVerification: jest.fn(), } satisfies Partial as any; podCreator = { handleSafe: jest.fn(), } satisfies Partial as any; initializer = new AccountInitializer({ accountStore, passwordStore, podCreator, email, password, }); }); it('creates the account/login/pod.', async(): Promise => { await expect(initializer.handle()).resolves.toBeUndefined(); expect(accountStore.create).toHaveBeenCalledTimes(1); expect(passwordStore.create).toHaveBeenCalledTimes(1); expect(passwordStore.create).toHaveBeenLastCalledWith(email, 'account-id', password); expect(passwordStore.confirmVerification).toHaveBeenCalledTimes(1); expect(podCreator.handleSafe).toHaveBeenCalledTimes(1); expect(podCreator.handleSafe).toHaveBeenLastCalledWith({ accountId: 'account-id' }); }); it('can create a pod with a name.', async(): Promise => { initializer = new AccountInitializer({ accountStore, passwordStore, podCreator, email, password, name: 'name', }); await expect(initializer.handle()).resolves.toBeUndefined(); expect(accountStore.create).toHaveBeenCalledTimes(1); expect(passwordStore.create).toHaveBeenCalledTimes(1); expect(passwordStore.create).toHaveBeenLastCalledWith(email, 'account-id', password); expect(passwordStore.confirmVerification).toHaveBeenCalledTimes(1); expect(podCreator.handleSafe).toHaveBeenCalledTimes(1); expect(podCreator.handleSafe).toHaveBeenLastCalledWith({ accountId: 'account-id', name: 'name' }); }); });