mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
Complete rewrite of the account management and related systems. Makes the architecture more modular, allowing for easier extensions and configurations.
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { PasswordLoginHandler } from '../../../../../src/identity/interaction/password/PasswordLoginHandler';
|
|
import type { PasswordStore } from '../../../../../src/identity/interaction/password/util/PasswordStore';
|
|
|
|
describe('A PasswordLoginHandler', (): void => {
|
|
let json: unknown;
|
|
const accountId = 'accountId';
|
|
const email = 'alice@test.email';
|
|
const password = 'supersecret!';
|
|
let passwordStore: jest.Mocked<PasswordStore>;
|
|
let handler: PasswordLoginHandler;
|
|
|
|
beforeEach(async(): Promise<void> => {
|
|
json = { email, password };
|
|
|
|
passwordStore = {
|
|
authenticate: jest.fn().mockResolvedValue(accountId),
|
|
} as any;
|
|
|
|
handler = new PasswordLoginHandler({
|
|
passwordStore,
|
|
accountStore: {} as any,
|
|
accountRoute: {} as any,
|
|
cookieStore: {} as any,
|
|
});
|
|
});
|
|
|
|
it('requires specific input fields.', async(): Promise<void> => {
|
|
await expect(handler.getView()).resolves.toEqual({
|
|
json: {
|
|
fields: {
|
|
email: {
|
|
required: true,
|
|
type: 'string',
|
|
},
|
|
password: {
|
|
required: true,
|
|
type: 'string',
|
|
},
|
|
remember: {
|
|
required: false,
|
|
type: 'boolean',
|
|
},
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
it('logs the user in.', async(): Promise<void> => {
|
|
await expect(handler.login({ json } as any)).resolves.toEqual({ json: { accountId, remember: false }});
|
|
|
|
expect(passwordStore.authenticate).toHaveBeenCalledTimes(1);
|
|
expect(passwordStore.authenticate).toHaveBeenLastCalledWith(email, password);
|
|
});
|
|
});
|