mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Update notification object to match the updated examples
This commit is contained in:
parent
caee563dd6
commit
7c343a5fcc
@ -3,7 +3,7 @@ export const CONTEXT_NOTIFICATION = 'https://www.w3.org/ns/solid/notification/v1
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The minimally expected fields for a Notification
|
* The minimally expected fields for a Notification
|
||||||
* as defined in https://solidproject.org/TR/notifications-protocol#notification-data-model.
|
* as defined in https://solidproject.org/TR/2022/notifications-protocol-20221231#data-model.
|
||||||
*/
|
*/
|
||||||
export interface Notification {
|
export interface Notification {
|
||||||
'@context': [
|
'@context': [
|
||||||
@ -12,11 +12,9 @@ export interface Notification {
|
|||||||
...string[],
|
...string[],
|
||||||
];
|
];
|
||||||
id: string;
|
id: string;
|
||||||
type: string[];
|
type: string;
|
||||||
object: {
|
object: string;
|
||||||
id: string;
|
|
||||||
type: string[];
|
|
||||||
};
|
|
||||||
state?: string;
|
state?: string;
|
||||||
|
target?: string | string[];
|
||||||
published: string;
|
published: string;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { getETag } from '../../../storage/Conditions';
|
import { getETag } from '../../../storage/Conditions';
|
||||||
import type { ResourceStore } from '../../../storage/ResourceStore';
|
import type { ResourceStore } from '../../../storage/ResourceStore';
|
||||||
import { NotImplementedHttpError } from '../../../util/errors/NotImplementedHttpError';
|
import { NotImplementedHttpError } from '../../../util/errors/NotImplementedHttpError';
|
||||||
import { AS, RDF } from '../../../util/Vocabularies';
|
import { AS } from '../../../util/Vocabularies';
|
||||||
import type { Notification } from '../Notification';
|
import type { Notification } from '../Notification';
|
||||||
import { CONTEXT_ACTIVITYSTREAMS, CONTEXT_NOTIFICATION } from '../Notification';
|
import { CONTEXT_ACTIVITYSTREAMS, CONTEXT_NOTIFICATION } from '../Notification';
|
||||||
import type { NotificationHandlerInput } from '../NotificationHandler';
|
import type { NotificationHandlerInput } from '../NotificationHandler';
|
||||||
@ -37,11 +37,8 @@ export class ActivityNotificationGenerator extends NotificationGenerator {
|
|||||||
CONTEXT_NOTIFICATION,
|
CONTEXT_NOTIFICATION,
|
||||||
],
|
],
|
||||||
id: `urn:${Date.now()}:${topic.path}`,
|
id: `urn:${Date.now()}:${topic.path}`,
|
||||||
type: [ activity!.value.slice(AS.namespace.length) ],
|
type: activity!.value.slice(AS.namespace.length),
|
||||||
object: {
|
object: topic.path,
|
||||||
id: topic.path,
|
|
||||||
type: representation.metadata.getAll(RDF.terms.type).map((term): string => term.value),
|
|
||||||
},
|
|
||||||
state,
|
state,
|
||||||
published: new Date().toISOString(),
|
published: new Date().toISOString(),
|
||||||
};
|
};
|
||||||
|
@ -24,11 +24,8 @@ export class DeleteNotificationGenerator extends NotificationGenerator {
|
|||||||
CONTEXT_NOTIFICATION,
|
CONTEXT_NOTIFICATION,
|
||||||
],
|
],
|
||||||
id: `urn:${Date.now()}:${topic.path}`,
|
id: `urn:${Date.now()}:${topic.path}`,
|
||||||
type: [ 'Delete' ],
|
type: 'Delete',
|
||||||
object: {
|
object: topic.path,
|
||||||
id: topic.path,
|
|
||||||
type: [],
|
|
||||||
},
|
|
||||||
published: new Date().toISOString(),
|
published: new Date().toISOString(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ describe.each(stores)('A server supporting WebSocketSubscription2021 using %s',
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('removes expired subscriptions.', async(): Promise<void> => {
|
it('removes expired subscriptions.', async(): Promise<void> => {
|
||||||
const { source } = await subscribe(notificationType, webId, subscriptionUrl, topic, { expiration: 1 }) as any;
|
const { source } = await subscribe(notificationType, webId, subscriptionUrl, topic, { endAt: 1 }) as any;
|
||||||
|
|
||||||
const socket = new WebSocket(source);
|
const socket = new WebSocket(source);
|
||||||
const messagePromise = new Promise<Buffer>((resolve): any => socket.on('message', resolve));
|
const messagePromise = new Promise<Buffer>((resolve): any => socket.on('message', resolve));
|
||||||
|
@ -15,11 +15,8 @@ describe('A ComposedNotificationHandler', (): void => {
|
|||||||
'https://www.w3.org/ns/solid/notification/v1',
|
'https://www.w3.org/ns/solid/notification/v1',
|
||||||
],
|
],
|
||||||
id: `urn:123:http://example.com/foo`,
|
id: `urn:123:http://example.com/foo`,
|
||||||
type: [ 'Update' ],
|
type: 'Update',
|
||||||
object: {
|
object: 'http://example.com/foo',
|
||||||
id: 'http://example.com/foo',
|
|
||||||
type: [],
|
|
||||||
},
|
|
||||||
published: '123',
|
published: '123',
|
||||||
state: '123',
|
state: '123',
|
||||||
};
|
};
|
||||||
|
@ -35,11 +35,8 @@ describe('A WebHookEmitter', (): void => {
|
|||||||
'https://www.w3.org/ns/solid/notification/v1',
|
'https://www.w3.org/ns/solid/notification/v1',
|
||||||
],
|
],
|
||||||
id: `urn:123:http://example.com/foo`,
|
id: `urn:123:http://example.com/foo`,
|
||||||
type: [ 'Update' ],
|
type: 'Update',
|
||||||
object: {
|
object: 'http://example.com/foo',
|
||||||
id: 'http://example.com/foo',
|
|
||||||
type: [],
|
|
||||||
},
|
|
||||||
published: '123',
|
published: '123',
|
||||||
};
|
};
|
||||||
let representation: Representation;
|
let representation: Representation;
|
||||||
|
@ -51,13 +51,8 @@ describe('An ActivityNotificationGenerator', (): void => {
|
|||||||
'https://www.w3.org/ns/solid/notification/v1',
|
'https://www.w3.org/ns/solid/notification/v1',
|
||||||
],
|
],
|
||||||
id: `urn:${ms}:http://example.com/foo`,
|
id: `urn:${ms}:http://example.com/foo`,
|
||||||
type: [ 'Update' ],
|
type: 'Update',
|
||||||
object: {
|
object: 'http://example.com/foo',
|
||||||
id: 'http://example.com/foo',
|
|
||||||
type: [
|
|
||||||
LDP.Resource,
|
|
||||||
],
|
|
||||||
},
|
|
||||||
state: expect.stringMatching(/"\d+"/u),
|
state: expect.stringMatching(/"\d+"/u),
|
||||||
published: date,
|
published: date,
|
||||||
});
|
});
|
||||||
|
@ -36,11 +36,8 @@ describe('A DeleteNotificationGenerator', (): void => {
|
|||||||
'https://www.w3.org/ns/solid/notification/v1',
|
'https://www.w3.org/ns/solid/notification/v1',
|
||||||
],
|
],
|
||||||
id: `urn:${ms}:http://example.com/foo`,
|
id: `urn:${ms}:http://example.com/foo`,
|
||||||
type: [ 'Delete' ],
|
type: 'Delete',
|
||||||
object: {
|
object: 'http://example.com/foo',
|
||||||
id: 'http://example.com/foo',
|
|
||||||
type: [],
|
|
||||||
},
|
|
||||||
published: date,
|
published: date,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -23,11 +23,8 @@ describe('A StateNotificationGenerator', (): void => {
|
|||||||
'https://www.w3.org/ns/solid/notification/v1',
|
'https://www.w3.org/ns/solid/notification/v1',
|
||||||
],
|
],
|
||||||
id: `urn:123:http://example.com/foo`,
|
id: `urn:123:http://example.com/foo`,
|
||||||
type: [ 'Update' ],
|
type: 'Update',
|
||||||
object: {
|
object: 'http://example.com/foo',
|
||||||
id: 'http://example.com/foo',
|
|
||||||
type: [],
|
|
||||||
},
|
|
||||||
published: '123',
|
published: '123',
|
||||||
};
|
};
|
||||||
let source: jest.Mocked<NotificationGenerator>;
|
let source: jest.Mocked<NotificationGenerator>;
|
||||||
|
@ -16,11 +16,8 @@ describe('A ConvertingNotificationSerializer', (): void => {
|
|||||||
'https://www.w3.org/ns/solid/notification/v1',
|
'https://www.w3.org/ns/solid/notification/v1',
|
||||||
],
|
],
|
||||||
id: `urn:123:http://example.com/foo`,
|
id: `urn:123:http://example.com/foo`,
|
||||||
type: [ 'Update' ],
|
type: 'Update',
|
||||||
object: {
|
object: 'http://example.com/foo',
|
||||||
id: 'http://example.com/foo',
|
|
||||||
type: [],
|
|
||||||
},
|
|
||||||
published: '123',
|
published: '123',
|
||||||
};
|
};
|
||||||
let representation: Representation;
|
let representation: Representation;
|
||||||
|
@ -19,11 +19,8 @@ describe('A JsonLdNotificationSerializer', (): void => {
|
|||||||
'https://www.w3.org/ns/solid/notification/v1',
|
'https://www.w3.org/ns/solid/notification/v1',
|
||||||
],
|
],
|
||||||
id: `urn:123:http://example.com/foo`,
|
id: `urn:123:http://example.com/foo`,
|
||||||
type: [ 'Update' ],
|
type: 'Update',
|
||||||
object: {
|
object: 'http://example.com/foo',
|
||||||
id: 'http://example.com/foo',
|
|
||||||
type: [],
|
|
||||||
},
|
|
||||||
published: '123',
|
published: '123',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,16 +42,12 @@ export function expectNotification(notification: unknown, topic: string, type: '
|
|||||||
'https://www.w3.org/ns/solid/notification/v1',
|
'https://www.w3.org/ns/solid/notification/v1',
|
||||||
],
|
],
|
||||||
id: expect.stringContaining(topic),
|
id: expect.stringContaining(topic),
|
||||||
type: [ type ],
|
type,
|
||||||
object: {
|
object: topic,
|
||||||
id: topic,
|
|
||||||
type: [],
|
|
||||||
},
|
|
||||||
published: expect.anything(),
|
published: expect.anything(),
|
||||||
};
|
};
|
||||||
if (type !== 'Delete') {
|
if (type !== 'Delete') {
|
||||||
expected.state = expect.anything();
|
expected.state = expect.anything();
|
||||||
expected.object.type.push('http://www.w3.org/ns/ldp#Resource');
|
|
||||||
}
|
}
|
||||||
expect(notification).toEqual(expected);
|
expect(notification).toEqual(expected);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user