Ocelot-Social/backend/src/emails/sendNotificationMail.spec.ts
Ulf Gebhardt a0c205b379
feat(backend): file upload chat backend (#8657)
* Prepare image uploads in chat

* files instead of images

* Fix file type and query

* Add dummy data to resolver

* fix graphql types

* Fix file upload, remove unncessary code

* Re-add fetch

* Fix room order after sent message

* Update backend/src/graphql/queries/messageQuery.ts

* Move room to top of list when a message is received

* working prototype chat file upload

* remove console

* allow to upload all kinds of files

* multiple images

* revert changes in S3 Images

* tag mimetype

* accept any file

* lint fix

* remove snapshot flakyness

* remove whitelist test

* fix messages spec

* fix query

* more query fixes

* fix seed

* made message resolver tests independent

* lint

* started specc for attachments

* more tests & fixes

* fix empty room error

* remove console logs

* fix tests

* fix createRoom last Messsage error properly

* lint fixes

* reduce changeset

* simplify config check

* reduce changeset

* missing change

* allow speech capture

* Fix file download

* Implement proper download

---------

Co-authored-by: Maximilian Harz <maxharz@gmail.com>
2025-06-13 19:02:37 +00:00

481 lines
12 KiB
TypeScript

import CONFIG from '@config/index'
CONFIG.SUPPORT_EMAIL = 'devops@ocelot.social'
// eslint-disable-next-line import/first
import { sendNotificationMail } from './sendEmail'
describe('sendNotificationMail', () => {
let locale = 'en'
describe('English', () => {
beforeEach(() => {
locale = 'en'
})
it('followed_user_posted template', async () => {
await expect(
sendNotificationMail({
reason: 'followed_user_posted',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
id: 'p1',
slug: 'new-post',
title: 'New Post',
author: {
id: 'u2',
name: 'Peter Lustig',
slug: 'peter-lustig',
},
},
}),
).resolves.toMatchSnapshot()
})
it('post_in_group template', async () => {
await expect(
sendNotificationMail({
reason: 'post_in_group',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
id: 'p1',
slug: 'new-post',
title: 'New Post',
author: {
id: 'u2',
name: 'Peter Lustig',
slug: 'peter-lustig',
},
},
}),
).resolves.toMatchSnapshot()
})
it('mentioned_in_post template', async () => {
await expect(
sendNotificationMail({
reason: 'mentioned_in_post',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
id: 'p1',
slug: 'new-post',
title: 'New Post',
author: {
id: 'u2',
name: 'Peter Lustig',
slug: 'peter-lustig',
},
},
}),
).resolves.toMatchSnapshot()
})
it('commented_on_post template', async () => {
await expect(
sendNotificationMail({
reason: 'commented_on_post',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
__typename: 'Comment',
id: 'c1',
slug: 'new-comment',
author: {
id: 'u2',
name: 'Peter Lustig',
slug: 'peter-lustig',
},
post: {
id: 'p1',
slug: 'new-post',
title: 'New Post',
},
},
}),
).resolves.toMatchSnapshot()
})
it('mentioned_in_comment template', async () => {
await expect(
sendNotificationMail({
reason: 'mentioned_in_comment',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
__typename: 'Comment',
id: 'c1',
slug: 'new-comment',
author: {
id: 'u2',
name: 'Peter Lustig',
slug: 'peter-lustig',
},
post: {
id: 'p1',
slug: 'new-post',
title: 'New Post',
},
},
}),
).resolves.toMatchSnapshot()
})
it('changed_group_member_role template', async () => {
await expect(
sendNotificationMail({
reason: 'changed_group_member_role',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
__typename: 'Group',
id: 'g1',
slug: 'the-group',
name: 'The Group',
},
}),
).resolves.toMatchSnapshot()
})
it('user_joined_group template', async () => {
await expect(
sendNotificationMail({
reason: 'user_joined_group',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
__typename: 'Group',
id: 'g1',
slug: 'the-group',
name: 'The Group',
},
relatedUser: {
id: 'u2',
name: 'Peter Lustig',
slug: 'peter-lustig',
},
}),
).resolves.toMatchSnapshot()
})
it('user_left_group template', async () => {
await expect(
sendNotificationMail({
reason: 'user_left_group',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
__typename: 'Group',
id: 'g1',
slug: 'the-group',
name: 'The Group',
},
relatedUser: {
id: 'u2',
name: 'Peter Lustig',
slug: 'peter-lustig',
},
}),
).resolves.toMatchSnapshot()
})
it('removed_user_from_group template', async () => {
await expect(
sendNotificationMail({
reason: 'removed_user_from_group',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
__typename: 'Group',
id: 'g1',
slug: 'the-group',
name: 'The Group',
},
}),
).resolves.toMatchSnapshot()
})
})
describe('German', () => {
beforeEach(() => {
locale = 'de'
})
it('followed_user_posted template', async () => {
await expect(
sendNotificationMail({
reason: 'followed_user_posted',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
id: 'p1',
slug: 'new-post',
title: 'New Post',
author: {
id: 'u2',
name: 'Peter Lustig',
slug: 'peter-lustig',
},
},
}),
).resolves.toMatchSnapshot()
})
it('post_in_group template', async () => {
await expect(
sendNotificationMail({
reason: 'post_in_group',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
id: 'p1',
slug: 'new-post',
title: 'New Post',
author: {
id: 'u2',
name: 'Peter Lustig',
slug: 'peter-lustig',
},
},
}),
).resolves.toMatchSnapshot()
})
it('mentioned_in_post template', async () => {
await expect(
sendNotificationMail({
reason: 'mentioned_in_post',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
id: 'p1',
slug: 'new-post',
title: 'New Post',
author: {
id: 'u2',
name: 'Peter Lustig',
slug: 'peter-lustig',
},
},
}),
).resolves.toMatchSnapshot()
})
it('commented_on_post template', async () => {
await expect(
sendNotificationMail({
reason: 'commented_on_post',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
__typename: 'Comment',
id: 'c1',
slug: 'new-comment',
author: {
id: 'u2',
name: 'Peter Lustig',
slug: 'peter-lustig',
},
post: {
id: 'p1',
slug: 'new-post',
title: 'New Post',
},
},
}),
).resolves.toMatchSnapshot()
})
it('mentioned_in_comment template', async () => {
await expect(
sendNotificationMail({
reason: 'mentioned_in_comment',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
__typename: 'Comment',
id: 'c1',
slug: 'new-comment',
author: {
id: 'u2',
name: 'Peter Lustig',
slug: 'peter-lustig',
},
post: {
id: 'p1',
slug: 'new-post',
title: 'New Post',
},
},
}),
).resolves.toMatchSnapshot()
})
it('changed_group_member_role template', async () => {
await expect(
sendNotificationMail({
reason: 'changed_group_member_role',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
__typename: 'Group',
id: 'g1',
slug: 'the-group',
name: 'The Group',
},
}),
).resolves.toMatchSnapshot()
})
it('user_joined_group template', async () => {
await expect(
sendNotificationMail({
reason: 'user_joined_group',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
__typename: 'Group',
id: 'g1',
slug: 'the-group',
name: 'The Group',
},
relatedUser: {
id: 'u2',
name: 'Peter Lustig',
slug: 'peter-lustig',
},
}),
).resolves.toMatchSnapshot()
})
it('user_left_group template', async () => {
await expect(
sendNotificationMail({
reason: 'user_left_group',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
__typename: 'Group',
id: 'g1',
slug: 'the-group',
name: 'The Group',
},
relatedUser: {
id: 'u2',
name: 'Peter Lustig',
slug: 'peter-lustig',
},
}),
).resolves.toMatchSnapshot()
})
it('removed_user_from_group template', async () => {
await expect(
sendNotificationMail({
reason: 'removed_user_from_group',
email: 'user@example.org',
to: {
name: 'Jenny Rostock',
id: 'u1',
slug: 'jenny-rostock',
locale,
},
from: {
__typename: 'Group',
id: 'g1',
slug: 'the-group',
name: 'The Group',
},
}),
).resolves.toMatchSnapshot()
})
})
})