mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Add support for the Notification specification
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import type { ResourceIdentifier } from '../../../../../src/http/representation/ResourceIdentifier';
|
||||
import {
|
||||
DeleteNotificationGenerator,
|
||||
} from '../../../../../src/server/notifications/generate/DeleteNotificationGenerator';
|
||||
import type { SubscriptionInfo } from '../../../../../src/server/notifications/SubscriptionStorage';
|
||||
import { AS } from '../../../../../src/util/Vocabularies';
|
||||
|
||||
describe('A DeleteNotificationGenerator', (): void => {
|
||||
const topic: ResourceIdentifier = { path: 'http://example.com/foo' };
|
||||
const info: SubscriptionInfo = {
|
||||
id: 'id',
|
||||
topic: topic.path,
|
||||
type: 'type',
|
||||
features: {},
|
||||
lastEmit: 0,
|
||||
};
|
||||
const activity = AS.terms.Delete;
|
||||
const generator = new DeleteNotificationGenerator();
|
||||
|
||||
it('can only handle input with the Delete activity.', async(): Promise<void> => {
|
||||
await expect(generator.canHandle({ topic, info })).rejects.toThrow('Only Delete activity updates are supported.');
|
||||
await expect(generator.canHandle({ topic, info, activity: AS.terms.Update }))
|
||||
.rejects.toThrow('Only Delete activity updates are supported.');
|
||||
await expect(generator.canHandle({ topic, info, activity })).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('generates a Delete notification.', async(): Promise<void> => {
|
||||
const date = '1988-03-09T14:48:00.000Z';
|
||||
const ms = Date.parse(date);
|
||||
jest.useFakeTimers();
|
||||
jest.setSystemTime(ms);
|
||||
|
||||
await expect(generator.handle({ topic, info, activity })).resolves.toEqual({
|
||||
'@context': [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://www.w3.org/ns/solid/notification/v1',
|
||||
],
|
||||
id: `urn:${ms}:http://example.com/foo`,
|
||||
type: [ 'Delete' ],
|
||||
object: {
|
||||
id: 'http://example.com/foo',
|
||||
type: [],
|
||||
},
|
||||
published: date,
|
||||
});
|
||||
|
||||
jest.useRealTimers();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user