mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
feat: notifications (#17701)
* feat: notifications * UI works * chore: pr feedback * initial fetch and clear notification upon logging out * fix: merge --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
23717ce981
commit
1b5fc9c665
55 changed files with 3186 additions and 196 deletions
|
|
@ -3,7 +3,6 @@ import { defaults, SystemConfig } from 'src/config';
|
|||
import { AlbumUser } from 'src/database';
|
||||
import { SystemConfigDto } from 'src/dtos/system-config.dto';
|
||||
import { AssetFileType, JobName, JobStatus, UserMetadataKey } from 'src/enum';
|
||||
import { EmailTemplate } from 'src/repositories/email.repository';
|
||||
import { NotificationService } from 'src/services/notification.service';
|
||||
import { INotifyAlbumUpdateJob } from 'src/types';
|
||||
import { albumStub } from 'test/fixtures/album.stub';
|
||||
|
|
@ -241,82 +240,6 @@ describe(NotificationService.name, () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('sendTestEmail', () => {
|
||||
it('should throw error if user could not be found', async () => {
|
||||
await expect(sut.sendTestEmail('', configs.smtpTransport.notifications.smtp)).rejects.toThrow('User not found');
|
||||
});
|
||||
|
||||
it('should throw error if smtp validation fails', async () => {
|
||||
mocks.user.get.mockResolvedValue(userStub.admin);
|
||||
mocks.email.verifySmtp.mockRejectedValue('');
|
||||
|
||||
await expect(sut.sendTestEmail('', configs.smtpTransport.notifications.smtp)).rejects.toThrow(
|
||||
'Failed to verify SMTP configuration',
|
||||
);
|
||||
});
|
||||
|
||||
it('should send email to default domain', async () => {
|
||||
mocks.user.get.mockResolvedValue(userStub.admin);
|
||||
mocks.email.verifySmtp.mockResolvedValue(true);
|
||||
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
||||
mocks.email.sendEmail.mockResolvedValue({ messageId: 'message-1', response: '' });
|
||||
|
||||
await expect(sut.sendTestEmail('', configs.smtpTransport.notifications.smtp)).resolves.not.toThrow();
|
||||
expect(mocks.email.renderEmail).toHaveBeenCalledWith({
|
||||
template: EmailTemplate.TEST_EMAIL,
|
||||
data: { baseUrl: 'https://my.immich.app', displayName: userStub.admin.name },
|
||||
});
|
||||
expect(mocks.email.sendEmail).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
subject: 'Test email from Immich',
|
||||
smtp: configs.smtpTransport.notifications.smtp.transport,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should send email to external domain', async () => {
|
||||
mocks.user.get.mockResolvedValue(userStub.admin);
|
||||
mocks.email.verifySmtp.mockResolvedValue(true);
|
||||
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
||||
mocks.systemMetadata.get.mockResolvedValue({ server: { externalDomain: 'https://demo.immich.app' } });
|
||||
mocks.email.sendEmail.mockResolvedValue({ messageId: 'message-1', response: '' });
|
||||
|
||||
await expect(sut.sendTestEmail('', configs.smtpTransport.notifications.smtp)).resolves.not.toThrow();
|
||||
expect(mocks.email.renderEmail).toHaveBeenCalledWith({
|
||||
template: EmailTemplate.TEST_EMAIL,
|
||||
data: { baseUrl: 'https://demo.immich.app', displayName: userStub.admin.name },
|
||||
});
|
||||
expect(mocks.email.sendEmail).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
subject: 'Test email from Immich',
|
||||
smtp: configs.smtpTransport.notifications.smtp.transport,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should send email with replyTo', async () => {
|
||||
mocks.user.get.mockResolvedValue(userStub.admin);
|
||||
mocks.email.verifySmtp.mockResolvedValue(true);
|
||||
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
||||
mocks.email.sendEmail.mockResolvedValue({ messageId: 'message-1', response: '' });
|
||||
|
||||
await expect(
|
||||
sut.sendTestEmail('', { ...configs.smtpTransport.notifications.smtp, replyTo: 'demo@immich.app' }),
|
||||
).resolves.not.toThrow();
|
||||
expect(mocks.email.renderEmail).toHaveBeenCalledWith({
|
||||
template: EmailTemplate.TEST_EMAIL,
|
||||
data: { baseUrl: 'https://my.immich.app', displayName: userStub.admin.name },
|
||||
});
|
||||
expect(mocks.email.sendEmail).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
subject: 'Test email from Immich',
|
||||
smtp: configs.smtpTransport.notifications.smtp.transport,
|
||||
replyTo: 'demo@immich.app',
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleUserSignup', () => {
|
||||
it('should skip if user could not be found', async () => {
|
||||
await expect(sut.handleUserSignup({ id: '' })).resolves.toBe(JobStatus.SKIPPED);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue