refactor: enum casing (#19946)

This commit is contained in:
Jason Rasmussen
2025-07-15 14:50:13 -04:00
committed by GitHub
parent 920d7de349
commit e73abe0762
174 changed files with 2675 additions and 2459 deletions

View File

@@ -131,7 +131,7 @@ describe(NotificationService.name, () => {
it('should queue the generate thumbnail job', async () => {
await sut.onAssetShow({ assetId: 'asset-id', userId: 'user-id' });
expect(mocks.job.queue).toHaveBeenCalledWith({
name: JobName.GENERATE_THUMBNAILS,
name: JobName.GenerateThumbnails,
data: { id: 'asset-id', notify: true },
});
});
@@ -146,7 +146,7 @@ describe(NotificationService.name, () => {
it('should queue notify signup event if notify is true', async () => {
await sut.onUserSignup({ id: '', notify: true });
expect(mocks.job.queue).toHaveBeenCalledWith({
name: JobName.NOTIFY_SIGNUP,
name: JobName.NotifySignup,
data: { id: '', tempPassword: undefined },
});
});
@@ -156,7 +156,7 @@ describe(NotificationService.name, () => {
it('should queue notify album update event', async () => {
await sut.onAlbumUpdate({ id: 'album', recipientId: '42' });
expect(mocks.job.queue).toHaveBeenCalledWith({
name: JobName.NOTIFY_ALBUM_UPDATE,
name: JobName.NotifyAlbumUpdate,
data: { id: 'album', recipientId: '42', delay: 300_000 },
});
});
@@ -166,7 +166,7 @@ describe(NotificationService.name, () => {
it('should queue notify album invite event', async () => {
await sut.onAlbumInvite({ id: '', userId: '42' });
expect(mocks.job.queue).toHaveBeenCalledWith({
name: JobName.NOTIFY_ALBUM_INVITE,
name: JobName.NotifyAlbumInvite,
data: { id: '', recipientId: '42' },
});
});
@@ -242,7 +242,7 @@ describe(NotificationService.name, () => {
describe('handleUserSignup', () => {
it('should skip if user could not be found', async () => {
await expect(sut.handleUserSignup({ id: '' })).resolves.toBe(JobStatus.SKIPPED);
await expect(sut.handleUserSignup({ id: '' })).resolves.toBe(JobStatus.Skipped);
});
it('should be successful', async () => {
@@ -250,9 +250,9 @@ describe(NotificationService.name, () => {
mocks.systemMetadata.get.mockResolvedValue({ server: {} });
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
await expect(sut.handleUserSignup({ id: '' })).resolves.toBe(JobStatus.SUCCESS);
await expect(sut.handleUserSignup({ id: '' })).resolves.toBe(JobStatus.Success);
expect(mocks.job.queue).toHaveBeenCalledWith({
name: JobName.SEND_EMAIL,
name: JobName.SendMail,
data: expect.objectContaining({ subject: 'Welcome to Immich' }),
});
});
@@ -260,14 +260,14 @@ describe(NotificationService.name, () => {
describe('handleAlbumInvite', () => {
it('should skip if album could not be found', async () => {
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.SKIPPED);
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.Skipped);
expect(mocks.user.get).not.toHaveBeenCalled();
});
it('should skip if recipient could not be found', async () => {
mocks.album.getById.mockResolvedValue(albumStub.empty);
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.SKIPPED);
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.Skipped);
expect(mocks.job.queue).not.toHaveBeenCalled();
});
@@ -277,13 +277,13 @@ describe(NotificationService.name, () => {
...userStub.user1,
metadata: [
{
key: UserMetadataKey.PREFERENCES,
key: UserMetadataKey.Preferences,
value: { emailNotifications: { enabled: false, albumInvite: true } },
},
],
});
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.SKIPPED);
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.Skipped);
});
it('should skip if the recipient has email notifications for album invite disabled', async () => {
@@ -292,13 +292,13 @@ describe(NotificationService.name, () => {
...userStub.user1,
metadata: [
{
key: UserMetadataKey.PREFERENCES,
key: UserMetadataKey.Preferences,
value: { emailNotifications: { enabled: true, albumInvite: false } },
},
],
});
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.SKIPPED);
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.Skipped);
});
it('should send invite email', async () => {
@@ -307,7 +307,7 @@ describe(NotificationService.name, () => {
...userStub.user1,
metadata: [
{
key: UserMetadataKey.PREFERENCES,
key: UserMetadataKey.Preferences,
value: { emailNotifications: { enabled: true, albumInvite: true } },
},
],
@@ -315,9 +315,9 @@ describe(NotificationService.name, () => {
mocks.systemMetadata.get.mockResolvedValue({ server: {} });
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.SUCCESS);
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.Success);
expect(mocks.job.queue).toHaveBeenCalledWith({
name: JobName.SEND_EMAIL,
name: JobName.SendMail,
data: expect.objectContaining({ subject: expect.stringContaining('You have been added to a shared album') }),
});
});
@@ -328,7 +328,7 @@ describe(NotificationService.name, () => {
...userStub.user1,
metadata: [
{
key: UserMetadataKey.PREFERENCES,
key: UserMetadataKey.Preferences,
value: { emailNotifications: { enabled: true, albumInvite: true } },
},
],
@@ -337,13 +337,13 @@ describe(NotificationService.name, () => {
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([]);
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.SUCCESS);
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.Success);
expect(mocks.assetJob.getAlbumThumbnailFiles).toHaveBeenCalledWith(
albumStub.emptyWithValidThumbnail.albumThumbnailAssetId,
AssetFileType.THUMBNAIL,
AssetFileType.Thumbnail,
);
expect(mocks.job.queue).toHaveBeenCalledWith({
name: JobName.SEND_EMAIL,
name: JobName.SendMail,
data: expect.objectContaining({
subject: expect.stringContaining('You have been added to a shared album'),
imageAttachments: undefined,
@@ -357,7 +357,7 @@ describe(NotificationService.name, () => {
...userStub.user1,
metadata: [
{
key: UserMetadataKey.PREFERENCES,
key: UserMetadataKey.Preferences,
value: { emailNotifications: { enabled: true, albumInvite: true } },
},
],
@@ -365,16 +365,16 @@ describe(NotificationService.name, () => {
mocks.systemMetadata.get.mockResolvedValue({ server: {} });
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([
{ id: '1', type: AssetFileType.THUMBNAIL, path: 'path-to-thumb.jpg' },
{ id: '1', type: AssetFileType.Thumbnail, path: 'path-to-thumb.jpg' },
]);
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.SUCCESS);
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.Success);
expect(mocks.assetJob.getAlbumThumbnailFiles).toHaveBeenCalledWith(
albumStub.emptyWithValidThumbnail.albumThumbnailAssetId,
AssetFileType.THUMBNAIL,
AssetFileType.Thumbnail,
);
expect(mocks.job.queue).toHaveBeenCalledWith({
name: JobName.SEND_EMAIL,
name: JobName.SendMail,
data: expect.objectContaining({
subject: expect.stringContaining('You have been added to a shared album'),
imageAttachments: [{ filename: 'album-thumbnail.jpg', path: expect.anything(), cid: expect.anything() }],
@@ -388,7 +388,7 @@ describe(NotificationService.name, () => {
...userStub.user1,
metadata: [
{
key: UserMetadataKey.PREFERENCES,
key: UserMetadataKey.Preferences,
value: { emailNotifications: { enabled: true, albumInvite: true } },
},
],
@@ -397,13 +397,13 @@ describe(NotificationService.name, () => {
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([assetStub.image.files[2]]);
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.SUCCESS);
await expect(sut.handleAlbumInvite({ id: '', recipientId: '' })).resolves.toBe(JobStatus.Success);
expect(mocks.assetJob.getAlbumThumbnailFiles).toHaveBeenCalledWith(
albumStub.emptyWithValidThumbnail.albumThumbnailAssetId,
AssetFileType.THUMBNAIL,
AssetFileType.Thumbnail,
);
expect(mocks.job.queue).toHaveBeenCalledWith({
name: JobName.SEND_EMAIL,
name: JobName.SendMail,
data: expect.objectContaining({
subject: expect.stringContaining('You have been added to a shared album'),
imageAttachments: [{ filename: 'album-thumbnail.ext', path: expect.anything(), cid: expect.anything() }],
@@ -414,14 +414,14 @@ describe(NotificationService.name, () => {
describe('handleAlbumUpdate', () => {
it('should skip if album could not be found', async () => {
await expect(sut.handleAlbumUpdate({ id: '', recipientId: '1' })).resolves.toBe(JobStatus.SKIPPED);
await expect(sut.handleAlbumUpdate({ id: '', recipientId: '1' })).resolves.toBe(JobStatus.Skipped);
expect(mocks.user.get).not.toHaveBeenCalled();
});
it('should skip if owner could not be found', async () => {
mocks.album.getById.mockResolvedValue(albumStub.emptyWithValidThumbnail);
await expect(sut.handleAlbumUpdate({ id: '', recipientId: '1' })).resolves.toBe(JobStatus.SKIPPED);
await expect(sut.handleAlbumUpdate({ id: '', recipientId: '1' })).resolves.toBe(JobStatus.Skipped);
expect(mocks.systemMetadata.get).not.toHaveBeenCalled();
});
@@ -448,7 +448,7 @@ describe(NotificationService.name, () => {
...userStub.user1,
metadata: [
{
key: UserMetadataKey.PREFERENCES,
key: UserMetadataKey.Preferences,
value: { emailNotifications: { enabled: false, albumUpdate: true } },
},
],
@@ -470,7 +470,7 @@ describe(NotificationService.name, () => {
...userStub.user1,
metadata: [
{
key: UserMetadataKey.PREFERENCES,
key: UserMetadataKey.Preferences,
value: { emailNotifications: { enabled: true, albumUpdate: false } },
},
],
@@ -500,9 +500,9 @@ describe(NotificationService.name, () => {
it('should add new recipients for new images if job is already queued', async () => {
await sut.onAlbumUpdate({ id: '1', recipientId: '2' } as INotifyAlbumUpdateJob);
expect(mocks.job.removeJob).toHaveBeenCalledWith(JobName.NOTIFY_ALBUM_UPDATE, '1/2');
expect(mocks.job.removeJob).toHaveBeenCalledWith(JobName.NotifyAlbumUpdate, '1/2');
expect(mocks.job.queue).toHaveBeenCalledWith({
name: JobName.NOTIFY_ALBUM_UPDATE,
name: JobName.NotifyAlbumUpdate,
data: {
id: '1',
delay: 300_000,
@@ -515,7 +515,7 @@ describe(NotificationService.name, () => {
describe('handleSendEmail', () => {
it('should skip if smtp notifications are disabled', async () => {
mocks.systemMetadata.get.mockResolvedValue({ notifications: { smtp: { enabled: false } } });
await expect(sut.handleSendEmail({ html: '', subject: '', text: '', to: '' })).resolves.toBe(JobStatus.SKIPPED);
await expect(sut.handleSendEmail({ html: '', subject: '', text: '', to: '' })).resolves.toBe(JobStatus.Skipped);
});
it('should send mail successfully', async () => {
@@ -524,7 +524,7 @@ describe(NotificationService.name, () => {
});
mocks.email.sendEmail.mockResolvedValue({ messageId: '', response: '' });
await expect(sut.handleSendEmail({ html: '', subject: '', text: '', to: '' })).resolves.toBe(JobStatus.SUCCESS);
await expect(sut.handleSendEmail({ html: '', subject: '', text: '', to: '' })).resolves.toBe(JobStatus.Success);
expect(mocks.email.sendEmail).toHaveBeenCalledWith(expect.objectContaining({ replyTo: 'test@immich.app' }));
});
@@ -534,7 +534,7 @@ describe(NotificationService.name, () => {
});
mocks.email.sendEmail.mockResolvedValue({ messageId: '', response: '' });
await expect(sut.handleSendEmail({ html: '', subject: '', text: '', to: '' })).resolves.toBe(JobStatus.SUCCESS);
await expect(sut.handleSendEmail({ html: '', subject: '', text: '', to: '' })).resolves.toBe(JobStatus.Success);
expect(mocks.email.sendEmail).toHaveBeenCalledWith(expect.objectContaining({ replyTo: 'demo@immich.app' }));
});
});