fixes tests

Signed-off-by: Billy Stalnaker <bstalnaker@roadie.com>
This commit is contained in:
Billy Stalnaker
2025-03-24 17:13:52 -04:00
parent 1fb5f06029
commit 26d1796c4e
2 changed files with 79 additions and 0 deletions
@@ -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 =>