mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Pass optional Interaction to InteractionHandlers
This commit is contained in:
@@ -1,45 +1,31 @@
|
||||
import type { Provider } from 'oidc-provider';
|
||||
import type { ProviderFactory } from '../../../../src/identity/configuration/ProviderFactory';
|
||||
import type { Interaction } from '../../../../src/identity/interaction/email-password/handler/InteractionHandler';
|
||||
import { SessionHttpHandler } from '../../../../src/identity/interaction/SessionHttpHandler';
|
||||
import type { HttpRequest } from '../../../../src/server/HttpRequest';
|
||||
import type { HttpResponse } from '../../../../src/server/HttpResponse';
|
||||
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
|
||||
|
||||
describe('A SessionHttpHandler', (): void => {
|
||||
const request: HttpRequest = {} as any;
|
||||
const response: HttpResponse = {} as any;
|
||||
const webId = 'http://test.com/id#me';
|
||||
let details: any = {};
|
||||
let provider: Provider;
|
||||
let oidcInteraction: Interaction;
|
||||
let handler: SessionHttpHandler;
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
details = { session: { accountId: webId }};
|
||||
provider = {
|
||||
interactionDetails: jest.fn().mockResolvedValue(details),
|
||||
} as any;
|
||||
oidcInteraction = { session: { accountId: webId }} as any;
|
||||
|
||||
const factory: ProviderFactory = {
|
||||
getProvider: jest.fn().mockResolvedValue(provider),
|
||||
};
|
||||
|
||||
handler = new SessionHttpHandler(factory);
|
||||
handler = new SessionHttpHandler();
|
||||
});
|
||||
|
||||
it('requires a session and accountId.', async(): Promise<void> => {
|
||||
details.session = undefined;
|
||||
await expect(handler.handle({ request, response })).rejects.toThrow(NotImplementedHttpError);
|
||||
it('requires a defined oidcInteraction with a session.', async(): Promise<void> => {
|
||||
oidcInteraction!.session = undefined;
|
||||
await expect(handler.handle({ request, oidcInteraction })).rejects.toThrow(NotImplementedHttpError);
|
||||
|
||||
details.session = { accountId: undefined };
|
||||
await expect(handler.handle({ request, response })).rejects.toThrow(NotImplementedHttpError);
|
||||
await expect(handler.handle({ request })).rejects.toThrow(NotImplementedHttpError);
|
||||
});
|
||||
|
||||
it('calls the oidc completer with the webId in the session.', async(): Promise<void> => {
|
||||
await expect(handler.handle({ request, response })).resolves.toEqual({
|
||||
it('returns an InteractionCompleteResult when done.', async(): Promise<void> => {
|
||||
await expect(handler.handle({ request, oidcInteraction })).resolves.toEqual({
|
||||
details: { webId },
|
||||
type: 'complete',
|
||||
});
|
||||
expect(provider.interactionDetails).toHaveBeenCalledTimes(1);
|
||||
expect(provider.interactionDetails).toHaveBeenLastCalledWith(request, response);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user