refactor: Rename NotificationChannelInfo to NotificationChannel

This commit is contained in:
Joachim Van Herwegen
2023-02-07 14:35:02 +01:00
parent 61f04487a1
commit 8d31233075
41 changed files with 358 additions and 357 deletions

View File

@@ -3,7 +3,7 @@ import type { ResourceIdentifier } from '../../../../src/http/representation/Res
import { ComposedNotificationHandler } from '../../../../src/server/notifications/ComposedNotificationHandler';
import type { NotificationGenerator } from '../../../../src/server/notifications/generate/NotificationGenerator';
import type { Notification } from '../../../../src/server/notifications/Notification';
import type { NotificationChannelInfo } from '../../../../src/server/notifications/NotificationChannelStorage';
import type { NotificationChannel } from '../../../../src/server/notifications/NotificationChannel';
import type { NotificationEmitter } from '../../../../src/server/notifications/NotificationEmitter';
import type { NotificationSerializer } from '../../../../src/server/notifications/serialize/NotificationSerializer';
@@ -20,7 +20,7 @@ describe('A ComposedNotificationHandler', (): void => {
published: '123',
state: '123',
};
let info: NotificationChannelInfo;
let channel: NotificationChannel;
const representation = new BasicRepresentation();
let generator: jest.Mocked<NotificationGenerator>;
let serializer: jest.Mocked<NotificationSerializer>;
@@ -28,7 +28,7 @@ describe('A ComposedNotificationHandler', (): void => {
let handler: ComposedNotificationHandler;
beforeEach(async(): Promise<void> => {
info = {
channel = {
id: 'id',
topic: 'http://example.com/foo',
type: 'type',
@@ -53,26 +53,26 @@ describe('A ComposedNotificationHandler', (): void => {
});
it('can only handle input supported by the generator.', async(): Promise<void> => {
await expect(handler.canHandle({ info, topic })).resolves.toBeUndefined();
await expect(handler.canHandle({ channel, topic })).resolves.toBeUndefined();
generator.canHandle.mockRejectedValue(new Error('bad input'));
await expect(handler.canHandle({ info, topic })).rejects.toThrow('bad input');
await expect(handler.canHandle({ channel, topic })).rejects.toThrow('bad input');
});
it('calls the three wrapped classes in order.', async(): Promise<void> => {
await expect(handler.handle({ info, topic })).resolves.toBeUndefined();
await expect(handler.handle({ channel, topic })).resolves.toBeUndefined();
expect(generator.handle).toHaveBeenCalledTimes(1);
expect(generator.handle).toHaveBeenLastCalledWith({ info, topic });
expect(generator.handle).toHaveBeenLastCalledWith({ channel, topic });
expect(serializer.handleSafe).toHaveBeenCalledTimes(1);
expect(serializer.handleSafe).toHaveBeenLastCalledWith({ info, notification });
expect(serializer.handleSafe).toHaveBeenLastCalledWith({ channel, notification });
expect(emitter.handleSafe).toHaveBeenCalledTimes(1);
expect(emitter.handleSafe).toHaveBeenLastCalledWith({ info, representation });
expect(emitter.handleSafe).toHaveBeenLastCalledWith({ channel, representation });
});
it('does not emit the notification if its state matches the info state.', async(): Promise<void> => {
info.state = notification.state;
await expect(handler.handle({ info, topic })).resolves.toBeUndefined();
it('does not emit the notification if its state matches the channel state.', async(): Promise<void> => {
channel.state = notification.state;
await expect(handler.handle({ channel, topic })).resolves.toBeUndefined();
expect(generator.handle).toHaveBeenCalledTimes(1);
expect(generator.handle).toHaveBeenLastCalledWith({ info, topic });
expect(generator.handle).toHaveBeenLastCalledWith({ channel, topic });
expect(serializer.handleSafe).toHaveBeenCalledTimes(0);
expect(emitter.handleSafe).toHaveBeenCalledTimes(0);
});