feat: Support Add/Remove notifications on containers

This commit is contained in:
Joachim Van Herwegen
2023-02-07 13:06:19 +01:00
parent 9e1e65cdb9
commit 134237a80f
17 changed files with 326 additions and 83 deletions

View File

@@ -1,5 +1,6 @@
import { EventEmitter } from 'events';
import type { Server } from 'http';
import { RepresentationMetadata } from '../../../src/http/representation/RepresentationMetadata';
import { UnsecureWebSocketsProtocol } from '../../../src/http/UnsecureWebSocketsProtocol';
import type { HttpRequest } from '../../../src/server/HttpRequest';
import { BaseActivityEmitter } from '../../../src/server/notifications/ActivityEmitter';
@@ -26,6 +27,7 @@ class DummySocket extends EventEmitter {
describe('An UnsecureWebSocketsProtocol', (): void => {
let server: Server;
let webSocket: DummySocket;
const metadata = new RepresentationMetadata();
const source = new BaseActivityEmitter();
let protocol: UnsecureWebSocketsProtocol;
@@ -67,7 +69,7 @@ describe('An UnsecureWebSocketsProtocol', (): void => {
describe('before subscribing to resources', (): void => {
it('does not emit pub messages.', (): void => {
source.emit('changed', { path: 'https://mypod.example/foo/bar' }, AS.terms.Update);
source.emit('changed', { path: 'https://mypod.example/foo/bar' }, AS.terms.Update, metadata);
expect(webSocket.messages).toHaveLength(0);
});
});
@@ -83,7 +85,7 @@ describe('An UnsecureWebSocketsProtocol', (): void => {
});
it('emits pub messages for that resource.', (): void => {
source.emit('changed', { path: 'https://mypod.example/foo/bar' }, AS.terms.Update);
source.emit('changed', { path: 'https://mypod.example/foo/bar' }, AS.terms.Update, metadata);
expect(webSocket.messages).toHaveLength(1);
expect(webSocket.messages.shift()).toBe('pub https://mypod.example/foo/bar');
});
@@ -100,7 +102,7 @@ describe('An UnsecureWebSocketsProtocol', (): void => {
});
it('emits pub messages for that resource.', (): void => {
source.emit('changed', { path: 'https://mypod.example/relative/foo' }, AS.terms.Update);
source.emit('changed', { path: 'https://mypod.example/relative/foo' }, AS.terms.Update, metadata);
expect(webSocket.messages).toHaveLength(1);
expect(webSocket.messages.shift()).toBe('pub https://mypod.example/relative/foo');
});