feat: Use ETagHandler for ETag generation and comparison

This commit is contained in:
Joachim Van Herwegen
2023-07-27 09:38:46 +02:00
parent 5ec6eddbfa
commit afcbfdaacf
31 changed files with 367 additions and 234 deletions

View File

@@ -6,6 +6,7 @@ import type { Notification } from '../../../../src/server/notifications/Notifica
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';
import type { ETagHandler } from '../../../../src/storage/conditions/ETagHandler';
describe('A ComposedNotificationHandler', (): void => {
const topic: ResourceIdentifier = { path: 'http://example.com/foo' };
@@ -25,6 +26,7 @@ describe('A ComposedNotificationHandler', (): void => {
let generator: jest.Mocked<NotificationGenerator>;
let serializer: jest.Mocked<NotificationSerializer>;
let emitter: jest.Mocked<NotificationEmitter>;
let eTagHandler: jest.Mocked<ETagHandler>;
let handler: ComposedNotificationHandler;
beforeEach(async(): Promise<void> => {
@@ -47,7 +49,13 @@ describe('A ComposedNotificationHandler', (): void => {
handleSafe: jest.fn(),
} as any;
handler = new ComposedNotificationHandler({ generator, serializer, emitter });
eTagHandler = {
getETag: jest.fn(),
matchesETag: jest.fn(),
sameResourceState: jest.fn().mockReturnValue(false),
};
handler = new ComposedNotificationHandler({ generator, serializer, emitter, eTagHandler });
});
it('can only handle input supported by the generator.', async(): Promise<void> => {
@@ -68,6 +76,7 @@ describe('A ComposedNotificationHandler', (): void => {
it('does not emit the notification if it has the same resource state as the channel.', async(): Promise<void> => {
channel.state = '"123456-application/ld+json"';
eTagHandler.sameResourceState.mockReturnValue(true);
await expect(handler.handle({ channel, topic })).resolves.toBeUndefined();
expect(generator.handle).toHaveBeenCalledTimes(1);
expect(generator.handle).toHaveBeenLastCalledWith({ channel, topic });