refactor: Rename subscription to notification channel

This commit is contained in:
Joachim Van Herwegen
2023-01-24 14:42:24 +01:00
parent 7c343a5fcc
commit 61f04487a1
51 changed files with 462 additions and 449 deletions

View File

@@ -2,8 +2,8 @@ import { AccessMode } from '../../../../../src/authorization/permissions/Permiss
import {
AbsolutePathInteractionRoute,
} from '../../../../../src/identity/interaction/routing/AbsolutePathInteractionRoute';
import type { Subscription } from '../../../../../src/server/notifications/Subscription';
import type { SubscriptionStorage } from '../../../../../src/server/notifications/SubscriptionStorage';
import type { NotificationChannel } from '../../../../../src/server/notifications/NotificationChannel';
import type { NotificationChannelStorage } from '../../../../../src/server/notifications/NotificationChannelStorage';
import {
WebSocketSubscription2021,
} from '../../../../../src/server/notifications/WebSocketSubscription2021/WebSocketSubscription2021';
@@ -11,13 +11,13 @@ import { IdentifierSetMultiMap } from '../../../../../src/util/map/IdentifierMap
import { readJsonStream } from '../../../../../src/util/StreamUtil';
describe('A WebSocketSubscription2021', (): void => {
let subscription: Subscription;
let storage: jest.Mocked<SubscriptionStorage>;
let channel: NotificationChannel;
let storage: jest.Mocked<NotificationChannelStorage>;
const route = new AbsolutePathInteractionRoute('http://example.com/foo');
let subscriptionType: WebSocketSubscription2021;
let channelType: WebSocketSubscription2021;
beforeEach(async(): Promise<void> => {
subscription = {
channel = {
'@context': [ 'https://www.w3.org/ns/solid/notification/v1' ],
type: 'WebSocketSubscription2021',
topic: 'https://storage.example/resource',
@@ -39,27 +39,27 @@ describe('A WebSocketSubscription2021', (): void => {
add: jest.fn(),
} as any;
subscriptionType = new WebSocketSubscription2021(storage, route);
channelType = new WebSocketSubscription2021(storage, route);
});
it('has the correct type.', async(): Promise<void> => {
expect(subscriptionType.type).toBe('WebSocketSubscription2021');
expect(channelType.type).toBe('WebSocketSubscription2021');
});
it('correctly parses subscriptions.', async(): Promise<void> => {
await expect(subscriptionType.schema.isValid(subscription)).resolves.toBe(true);
it('correctly parses notification channel bodies.', async(): Promise<void> => {
await expect(channelType.schema.isValid(channel)).resolves.toBe(true);
subscription.type = 'something else';
await expect(subscriptionType.schema.isValid(subscription)).resolves.toBe(false);
channel.type = 'something else';
await expect(channelType.schema.isValid(channel)).resolves.toBe(false);
});
it('requires Read permissions on the topic.', async(): Promise<void> => {
await expect(subscriptionType.extractModes(subscription)).resolves
.toEqual(new IdentifierSetMultiMap([[{ path: subscription.topic }, AccessMode.read ]]));
await expect(channelType.extractModes(channel)).resolves
.toEqual(new IdentifierSetMultiMap([[{ path: channel.topic }, AccessMode.read ]]));
});
it('stores the info and returns a valid response when subscribing.', async(): Promise<void> => {
const { response } = await subscriptionType.subscribe(subscription);
const { response } = await channelType.subscribe(channel);
expect(response.metadata.contentType).toBe('application/ld+json');
await expect(readJsonStream(response.data)).resolves.toEqual({
'@context': [ 'https://www.w3.org/ns/solid/notification/v1' ],