feat: Ignore unsupported notifications features in subscriptions

This commit is contained in:
Joachim Van Herwegen 2023-02-03 13:48:46 +01:00
parent 65860f77da
commit 67d1ff4ac0
2 changed files with 34 additions and 11 deletions

View File

@ -223,6 +223,8 @@ export abstract class BaseChannelType implements NotificationChannelType {
// Apply the values for all present features that are enabled
for (const feature of DEFAULT_NOTIFICATION_FEATURES) {
const featNode = this.features.find((node): boolean => node.value === feature);
if (featNode) {
const objects = data.getObjects(subject, feature, null);
if (objects.length === 1) {
// Will always succeed since we are iterating over a list which was built using `featureDefinitions`
@ -237,6 +239,7 @@ export abstract class BaseChannelType implements NotificationChannelType {
(channel as Record<typeof key, string | number>)[key] = val;
}
}
}
return channel;
}

View File

@ -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> => {
for (const feature of DEFAULT_NOTIFICATION_FEATURES) {
const badData = new Store(data.getQuads(null, null, null, null));