CommunitySolidServer/test/unit/server/notifications/generate/DeleteNotificationGenerator.test.ts
2022-11-09 09:10:00 +01:00

50 lines
1.8 KiB
TypeScript

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();
});
});