@@ -335,6 +335,82 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => {
|
||||
expect(notifications).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should not send to user entity if topic is disabled in settings', async () => {
|
||||
const client = await database.getClient();
|
||||
await client('user_settings').insert({
|
||||
user: 'user:default/mock',
|
||||
channel: 'Web',
|
||||
origin: 'external:test-service',
|
||||
topic: 'test-topic',
|
||||
enabled: false,
|
||||
});
|
||||
|
||||
const response = await sendNotification({
|
||||
recipients: {
|
||||
type: 'entity',
|
||||
entityRef: ['user:default/mock'],
|
||||
},
|
||||
payload: {
|
||||
title: 'test notification',
|
||||
topic: 'test-topic',
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toEqual([]);
|
||||
|
||||
const notifications = await client('notification')
|
||||
.where('user', 'user:default/mock')
|
||||
.select();
|
||||
expect(notifications).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should send to user entity if origin is enabled, but topic is disabled in settings', async () => {
|
||||
const client = await database.getClient();
|
||||
await client('user_settings').insert({
|
||||
user: 'user:default/mock',
|
||||
channel: 'Web',
|
||||
origin: 'external:test-service',
|
||||
enabled: true,
|
||||
});
|
||||
await client('user_settings').insert({
|
||||
user: 'user:default/mock',
|
||||
channel: 'Web',
|
||||
origin: 'external:test-service',
|
||||
topic: 'test-topic',
|
||||
enabled: false,
|
||||
});
|
||||
|
||||
const response = await sendNotification({
|
||||
recipients: {
|
||||
type: 'entity',
|
||||
entityRef: ['user:default/mock'],
|
||||
},
|
||||
payload: {
|
||||
title: 'test notification',
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toEqual([
|
||||
{
|
||||
created: expect.any(String),
|
||||
id: expect.any(String),
|
||||
origin: 'external:test-service',
|
||||
payload: {
|
||||
severity: 'normal',
|
||||
title: 'test notification',
|
||||
},
|
||||
user: 'user:default/mock',
|
||||
},
|
||||
]);
|
||||
|
||||
const notifications = await client('notification')
|
||||
.where('user', 'user:default/mock')
|
||||
.select();
|
||||
expect(notifications).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should fail without recipients', async () => {
|
||||
const response = await sendNotification({
|
||||
payload: {
|
||||
|
||||
@@ -134,6 +134,9 @@ export async function createRouter(
|
||||
topics: { origin: string; topic: string }[],
|
||||
) => {
|
||||
const existingChannel = settings.channels.find(c => c.id === channelId);
|
||||
if (existingChannel) {
|
||||
return existingChannel;
|
||||
}
|
||||
return {
|
||||
id: channelId,
|
||||
origins: origins.map(originId =>
|
||||
|
||||
Reference in New Issue
Block a user