mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Ignore unsupported notifications features in subscriptions
This commit is contained in:
parent
65860f77da
commit
67d1ff4ac0
@ -223,18 +223,21 @@ export abstract class BaseChannelType implements NotificationChannelType {
|
|||||||
|
|
||||||
// Apply the values for all present features that are enabled
|
// Apply the values for all present features that are enabled
|
||||||
for (const feature of DEFAULT_NOTIFICATION_FEATURES) {
|
for (const feature of DEFAULT_NOTIFICATION_FEATURES) {
|
||||||
const objects = data.getObjects(subject, feature, null);
|
const featNode = this.features.find((node): boolean => node.value === feature);
|
||||||
if (objects.length === 1) {
|
if (featNode) {
|
||||||
// Will always succeed since we are iterating over a list which was built using `featureDefinitions`
|
const objects = data.getObjects(subject, feature, null);
|
||||||
const { dataType, key } = featureDefinitions.find((feat): boolean => feat.predicate.value === feature)!;
|
if (objects.length === 1) {
|
||||||
let val: string | number = objects[0].value;
|
// Will always succeed since we are iterating over a list which was built using `featureDefinitions`
|
||||||
if (dataType === XSD.dateTime) {
|
const { dataType, key } = featureDefinitions.find((feat): boolean => feat.predicate.value === feature)!;
|
||||||
val = Date.parse(val);
|
let val: string | number = objects[0].value;
|
||||||
} else if (dataType === XSD.duration) {
|
if (dataType === XSD.dateTime) {
|
||||||
val = toSeconds(parse(val)) * 1000;
|
val = Date.parse(val);
|
||||||
|
} else if (dataType === XSD.duration) {
|
||||||
|
val = toSeconds(parse(val)) * 1000;
|
||||||
|
}
|
||||||
|
// Need to convince TS that we can assign `string | number` to this key
|
||||||
|
(channel as Record<typeof key, string | number>)[key] = val;
|
||||||
}
|
}
|
||||||
// Need to convince TS that we can assign `string | number` to this key
|
|
||||||
(channel as Record<typeof key, string | number>)[key] = val;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +142,26 @@ describe('A BaseChannelType', (): void => {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('removes features from the input that are not supported.', async(): Promise<void> => {
|
||||||
|
const date = '1988-03-09T14:48:00.000Z';
|
||||||
|
|
||||||
|
data.addQuad(quad(subject, NOTIFY.terms.startAt, literal(date, XSD.terms.dateTime)));
|
||||||
|
data.addQuad(quad(subject, NOTIFY.terms.endAt, literal(date, XSD.terms.dateTime)));
|
||||||
|
data.addQuad(quad(subject, NOTIFY.terms.rate, literal('PT10S', XSD.terms.duration)));
|
||||||
|
data.addQuad(quad(subject, NOTIFY.terms.accept, literal('text/turtle')));
|
||||||
|
data.addQuad(quad(subject, NOTIFY.terms.state, literal('123456')));
|
||||||
|
|
||||||
|
const featChannelType = new DummyChannelType([ 'notify:endAt', 'notify:accept', NOTIFY.state ]);
|
||||||
|
await expect(featChannelType.initChannel(data, credentials)).resolves.toEqual({
|
||||||
|
id,
|
||||||
|
type: dummyType.value,
|
||||||
|
topic: 'https://storage.example/resource',
|
||||||
|
endAt: Date.parse(date),
|
||||||
|
accept: 'text/turtle',
|
||||||
|
state: '123456',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('requires correct datatypes on the features.', async(): Promise<void> => {
|
it('requires correct datatypes on the features.', async(): Promise<void> => {
|
||||||
for (const feature of DEFAULT_NOTIFICATION_FEATURES) {
|
for (const feature of DEFAULT_NOTIFICATION_FEATURES) {
|
||||||
const badData = new Store(data.getQuads(null, null, null, null));
|
const badData = new Store(data.getQuads(null, null, null, null));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user