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

@@ -1,20 +1,20 @@
import { BaseStateHandler } from '../../../../src/server/notifications/BaseStateHandler';
import type { NotificationChannel } from '../../../../src/server/notifications/NotificationChannel';
import type {
NotificationChannelInfo,
NotificationChannelStorage,
} from '../../../../src/server/notifications/NotificationChannelStorage';
import type { NotificationHandler } from '../../../../src/server/notifications/NotificationHandler';
describe('A BaseStateHandler', (): void => {
let info: NotificationChannelInfo;
let channel: NotificationChannel;
let notificationHandler: jest.Mocked<NotificationHandler>;
let storage: jest.Mocked<NotificationChannelStorage>;
let handler: BaseStateHandler;
beforeEach(async(): Promise<void> => {
info = {
channel = {
id: 'id',
topic: 'http://example.com/foo',
topic: 'http://exa mple.com/foo',
type: 'type',
features: {},
lastEmit: 0,
@@ -33,21 +33,21 @@ describe('A BaseStateHandler', (): void => {
});
it('calls the handler if there is a trigger.', async(): Promise<void> => {
await expect(handler.handleSafe({ info })).resolves.toBeUndefined();
await expect(handler.handleSafe({ channel })).resolves.toBeUndefined();
expect(notificationHandler.handleSafe).toHaveBeenCalledTimes(1);
// Note that jest stores a reference to the input object so we can't see that the state value was still there
expect(notificationHandler.handleSafe).toHaveBeenLastCalledWith({ topic: { path: info.topic }, info });
expect(info.state).toBeUndefined();
expect(notificationHandler.handleSafe).toHaveBeenLastCalledWith({ topic: { path: channel.topic }, channel });
expect(channel.state).toBeUndefined();
expect(storage.update).toHaveBeenCalledTimes(1);
expect(storage.update).toHaveBeenLastCalledWith(info);
expect(storage.update).toHaveBeenLastCalledWith(channel);
});
it('does not delete the state parameter if something goes wrong.', async(): Promise<void> => {
notificationHandler.handleSafe.mockRejectedValue(new Error('bad input'));
await expect(handler.handleSafe({ info })).resolves.toBeUndefined();
await expect(handler.handleSafe({ channel })).resolves.toBeUndefined();
expect(notificationHandler.handleSafe).toHaveBeenCalledTimes(1);
expect(notificationHandler.handleSafe).toHaveBeenLastCalledWith({ topic: { path: info.topic }, info });
expect(info.state).toBe('123');
expect(notificationHandler.handleSafe).toHaveBeenLastCalledWith({ topic: { path: channel.topic }, channel });
expect(channel.state).toBe('123');
expect(storage.update).toHaveBeenCalledTimes(0);
});
});