mirror of
https://github.com/samsonjs/immich.git
synced 2026-04-27 15:07:45 +00:00
chore: remove album stubs (#26130)
This commit is contained in:
parent
1c1a000c78
commit
222c90b7b7
6 changed files with 82 additions and 161 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
import { MapService } from 'src/services/map.service';
|
import { MapService } from 'src/services/map.service';
|
||||||
import { albumStub } from 'test/fixtures/album.stub';
|
import { AlbumFactory } from 'test/factories/album.factory';
|
||||||
import { assetStub } from 'test/fixtures/asset.stub';
|
import { assetStub } from 'test/fixtures/asset.stub';
|
||||||
import { authStub } from 'test/fixtures/auth.stub';
|
import { authStub } from 'test/fixtures/auth.stub';
|
||||||
|
import { userStub } from 'test/fixtures/user.stub';
|
||||||
import { factory } from 'test/small.factory';
|
import { factory } from 'test/small.factory';
|
||||||
import { newTestService, ServiceMocks } from 'test/utils';
|
import { newTestService, ServiceMocks } from 'test/utils';
|
||||||
|
|
||||||
|
|
@ -72,8 +73,8 @@ describe(MapService.name, () => {
|
||||||
};
|
};
|
||||||
mocks.partner.getAll.mockResolvedValue([]);
|
mocks.partner.getAll.mockResolvedValue([]);
|
||||||
mocks.map.getMapMarkers.mockResolvedValue([marker]);
|
mocks.map.getMapMarkers.mockResolvedValue([marker]);
|
||||||
mocks.album.getOwned.mockResolvedValue([albumStub.empty]);
|
mocks.album.getOwned.mockResolvedValue([AlbumFactory.create()]);
|
||||||
mocks.album.getShared.mockResolvedValue([albumStub.sharedWithUser]);
|
mocks.album.getShared.mockResolvedValue([AlbumFactory.from().albumUser({ userId: userStub.user1.id }).build()]);
|
||||||
|
|
||||||
const markers = await sut.getMapMarkers(authStub.user1, { withSharedAlbums: true });
|
const markers = await sut.getMapMarkers(authStub.user1, { withSharedAlbums: true });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
import { plainToInstance } from 'class-transformer';
|
import { plainToInstance } from 'class-transformer';
|
||||||
import { defaults, SystemConfig } from 'src/config';
|
import { defaults, SystemConfig } from 'src/config';
|
||||||
import { AlbumUser } from 'src/database';
|
|
||||||
import { SystemConfigDto } from 'src/dtos/system-config.dto';
|
import { SystemConfigDto } from 'src/dtos/system-config.dto';
|
||||||
import { AssetFileType, JobName, JobStatus, UserMetadataKey } from 'src/enum';
|
import { AssetFileType, JobName, JobStatus, UserMetadataKey } from 'src/enum';
|
||||||
import { NotificationService } from 'src/services/notification.service';
|
import { NotificationService } from 'src/services/notification.service';
|
||||||
import { INotifyAlbumUpdateJob } from 'src/types';
|
import { INotifyAlbumUpdateJob } from 'src/types';
|
||||||
import { albumStub } from 'test/fixtures/album.stub';
|
import { AlbumFactory } from 'test/factories/album.factory';
|
||||||
import { assetStub } from 'test/fixtures/asset.stub';
|
import { AssetFileFactory } from 'test/factories/asset-file.factory';
|
||||||
|
import { UserFactory } from 'test/factories/user.factory';
|
||||||
import { notificationStub } from 'test/fixtures/notification.stub';
|
import { notificationStub } from 'test/fixtures/notification.stub';
|
||||||
import { userStub } from 'test/fixtures/user.stub';
|
import { userStub } from 'test/fixtures/user.stub';
|
||||||
|
import { newUuid } from 'test/small.factory';
|
||||||
import { newTestService, ServiceMocks } from 'test/utils';
|
import { newTestService, ServiceMocks } from 'test/utils';
|
||||||
|
|
||||||
const configs = {
|
const configs = {
|
||||||
|
|
@ -267,14 +268,14 @@ describe(NotificationService.name, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should skip if recipient could not be found', async () => {
|
it('should skip if recipient could not be found', async () => {
|
||||||
mocks.album.getById.mockResolvedValue(albumStub.empty);
|
mocks.album.getById.mockResolvedValue(AlbumFactory.create());
|
||||||
|
|
||||||
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();
|
expect(mocks.job.queue).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should skip if the recipient has email notifications disabled', async () => {
|
it('should skip if the recipient has email notifications disabled', async () => {
|
||||||
mocks.album.getById.mockResolvedValue(albumStub.empty);
|
mocks.album.getById.mockResolvedValue(AlbumFactory.create());
|
||||||
mocks.user.get.mockResolvedValue({
|
mocks.user.get.mockResolvedValue({
|
||||||
...userStub.user1,
|
...userStub.user1,
|
||||||
metadata: [
|
metadata: [
|
||||||
|
|
@ -290,7 +291,7 @@ describe(NotificationService.name, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should skip if the recipient has email notifications for album invite disabled', async () => {
|
it('should skip if the recipient has email notifications for album invite disabled', async () => {
|
||||||
mocks.album.getById.mockResolvedValue(albumStub.empty);
|
mocks.album.getById.mockResolvedValue(AlbumFactory.create());
|
||||||
mocks.user.get.mockResolvedValue({
|
mocks.user.get.mockResolvedValue({
|
||||||
...userStub.user1,
|
...userStub.user1,
|
||||||
metadata: [
|
metadata: [
|
||||||
|
|
@ -306,7 +307,7 @@ describe(NotificationService.name, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send invite email', async () => {
|
it('should send invite email', async () => {
|
||||||
mocks.album.getById.mockResolvedValue(albumStub.empty);
|
mocks.album.getById.mockResolvedValue(AlbumFactory.create());
|
||||||
mocks.user.get.mockResolvedValue({
|
mocks.user.get.mockResolvedValue({
|
||||||
...userStub.user1,
|
...userStub.user1,
|
||||||
metadata: [
|
metadata: [
|
||||||
|
|
@ -328,7 +329,8 @@ describe(NotificationService.name, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send invite email without album thumbnail if thumbnail asset does not exist', async () => {
|
it('should send invite email without album thumbnail if thumbnail asset does not exist', async () => {
|
||||||
mocks.album.getById.mockResolvedValue(albumStub.emptyWithValidThumbnail);
|
const album = AlbumFactory.create({ albumThumbnailAssetId: newUuid() });
|
||||||
|
mocks.album.getById.mockResolvedValue(album);
|
||||||
mocks.user.get.mockResolvedValue({
|
mocks.user.get.mockResolvedValue({
|
||||||
...userStub.user1,
|
...userStub.user1,
|
||||||
metadata: [
|
metadata: [
|
||||||
|
|
@ -345,7 +347,7 @@ describe(NotificationService.name, () => {
|
||||||
|
|
||||||
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(
|
expect(mocks.assetJob.getAlbumThumbnailFiles).toHaveBeenCalledWith(
|
||||||
albumStub.emptyWithValidThumbnail.albumThumbnailAssetId,
|
album.albumThumbnailAssetId,
|
||||||
AssetFileType.Thumbnail,
|
AssetFileType.Thumbnail,
|
||||||
);
|
);
|
||||||
expect(mocks.job.queue).toHaveBeenCalledWith({
|
expect(mocks.job.queue).toHaveBeenCalledWith({
|
||||||
|
|
@ -358,7 +360,9 @@ describe(NotificationService.name, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send invite email with album thumbnail as jpeg', async () => {
|
it('should send invite email with album thumbnail as jpeg', async () => {
|
||||||
mocks.album.getById.mockResolvedValue(albumStub.emptyWithValidThumbnail);
|
const assetFile = AssetFileFactory.create({ type: AssetFileType.Thumbnail });
|
||||||
|
const album = AlbumFactory.create({ albumThumbnailAssetId: assetFile.assetId });
|
||||||
|
mocks.album.getById.mockResolvedValue(album);
|
||||||
mocks.user.get.mockResolvedValue({
|
mocks.user.get.mockResolvedValue({
|
||||||
...userStub.user1,
|
...userStub.user1,
|
||||||
metadata: [
|
metadata: [
|
||||||
|
|
@ -371,13 +375,11 @@ describe(NotificationService.name, () => {
|
||||||
mocks.systemMetadata.get.mockResolvedValue({ server: {} });
|
mocks.systemMetadata.get.mockResolvedValue({ server: {} });
|
||||||
mocks.notification.create.mockResolvedValue(notificationStub.albumEvent);
|
mocks.notification.create.mockResolvedValue(notificationStub.albumEvent);
|
||||||
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
||||||
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([
|
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([assetFile]);
|
||||||
{ id: '1', type: AssetFileType.Thumbnail, path: 'path-to-thumb.jpg', isEdited: false },
|
|
||||||
]);
|
|
||||||
|
|
||||||
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(
|
expect(mocks.assetJob.getAlbumThumbnailFiles).toHaveBeenCalledWith(
|
||||||
albumStub.emptyWithValidThumbnail.albumThumbnailAssetId,
|
album.albumThumbnailAssetId,
|
||||||
AssetFileType.Thumbnail,
|
AssetFileType.Thumbnail,
|
||||||
);
|
);
|
||||||
expect(mocks.job.queue).toHaveBeenCalledWith({
|
expect(mocks.job.queue).toHaveBeenCalledWith({
|
||||||
|
|
@ -390,7 +392,9 @@ describe(NotificationService.name, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send invite email with album thumbnail and arbitrary extension', async () => {
|
it('should send invite email with album thumbnail and arbitrary extension', async () => {
|
||||||
mocks.album.getById.mockResolvedValue(albumStub.emptyWithValidThumbnail);
|
const assetFile = AssetFileFactory.create({ path: 'some-thumb.ext', type: AssetFileType.Thumbnail });
|
||||||
|
const album = AlbumFactory.create({ albumThumbnailAssetId: assetFile.assetId });
|
||||||
|
mocks.album.getById.mockResolvedValue(album);
|
||||||
mocks.user.get.mockResolvedValue({
|
mocks.user.get.mockResolvedValue({
|
||||||
...userStub.user1,
|
...userStub.user1,
|
||||||
metadata: [
|
metadata: [
|
||||||
|
|
@ -403,11 +407,11 @@ describe(NotificationService.name, () => {
|
||||||
mocks.systemMetadata.get.mockResolvedValue({ server: {} });
|
mocks.systemMetadata.get.mockResolvedValue({ server: {} });
|
||||||
mocks.notification.create.mockResolvedValue(notificationStub.albumEvent);
|
mocks.notification.create.mockResolvedValue(notificationStub.albumEvent);
|
||||||
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
||||||
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([{ ...assetStub.image.files[2], isEdited: false }]);
|
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([assetFile]);
|
||||||
|
|
||||||
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(
|
expect(mocks.assetJob.getAlbumThumbnailFiles).toHaveBeenCalledWith(
|
||||||
albumStub.emptyWithValidThumbnail.albumThumbnailAssetId,
|
album.albumThumbnailAssetId,
|
||||||
AssetFileType.Thumbnail,
|
AssetFileType.Thumbnail,
|
||||||
);
|
);
|
||||||
expect(mocks.job.queue).toHaveBeenCalledWith({
|
expect(mocks.job.queue).toHaveBeenCalledWith({
|
||||||
|
|
@ -427,85 +431,74 @@ describe(NotificationService.name, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should skip if owner could not be found', async () => {
|
it('should skip if owner could not be found', async () => {
|
||||||
mocks.album.getById.mockResolvedValue(albumStub.emptyWithValidThumbnail);
|
mocks.album.getById.mockResolvedValue(AlbumFactory.create({ ownerId: 'non-existent' }));
|
||||||
|
|
||||||
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();
|
expect(mocks.systemMetadata.get).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should skip recipient that could not be looked up', async () => {
|
it('should skip recipient that could not be looked up', async () => {
|
||||||
mocks.album.getById.mockResolvedValue({
|
const album = AlbumFactory.from().albumUser({ userId: 'non-existent' }).build();
|
||||||
...albumStub.emptyWithValidThumbnail,
|
mocks.album.getById.mockResolvedValue(album);
|
||||||
albumUsers: [{ user: { id: userStub.user1.id } } as AlbumUser],
|
mocks.user.get.mockResolvedValueOnce(album.owner);
|
||||||
});
|
|
||||||
mocks.user.get.mockResolvedValueOnce(userStub.user1);
|
|
||||||
mocks.notification.create.mockResolvedValue(notificationStub.albumEvent);
|
mocks.notification.create.mockResolvedValue(notificationStub.albumEvent);
|
||||||
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
||||||
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([]);
|
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([]);
|
||||||
|
|
||||||
await sut.handleAlbumUpdate({ id: '', recipientId: userStub.user1.id });
|
await sut.handleAlbumUpdate({ id: '', recipientId: 'non-existent' });
|
||||||
expect(mocks.user.get).toHaveBeenCalledWith(userStub.user1.id, { withDeleted: false });
|
expect(mocks.user.get).toHaveBeenCalledWith('non-existent', { withDeleted: false });
|
||||||
expect(mocks.email.renderEmail).not.toHaveBeenCalled();
|
expect(mocks.email.renderEmail).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should skip recipient with disabled email notifications', async () => {
|
it('should skip recipient with disabled email notifications', async () => {
|
||||||
mocks.album.getById.mockResolvedValue({
|
const user = UserFactory.from()
|
||||||
...albumStub.emptyWithValidThumbnail,
|
.metadata({
|
||||||
albumUsers: [{ user: { id: userStub.user1.id } } as AlbumUser],
|
key: UserMetadataKey.Preferences,
|
||||||
});
|
value: { emailNotifications: { enabled: false, albumUpdate: true } },
|
||||||
mocks.user.get.mockResolvedValue({
|
})
|
||||||
...userStub.user1,
|
.build();
|
||||||
metadata: [
|
const album = AlbumFactory.from().albumUser({ userId: user.id }).build();
|
||||||
{
|
mocks.album.getById.mockResolvedValue(album);
|
||||||
key: UserMetadataKey.Preferences,
|
mocks.user.get.mockResolvedValue(user);
|
||||||
value: { emailNotifications: { enabled: false, albumUpdate: true } },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
mocks.notification.create.mockResolvedValue(notificationStub.albumEvent);
|
mocks.notification.create.mockResolvedValue(notificationStub.albumEvent);
|
||||||
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
||||||
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([]);
|
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([]);
|
||||||
|
|
||||||
await sut.handleAlbumUpdate({ id: '', recipientId: userStub.user1.id });
|
await sut.handleAlbumUpdate({ id: '', recipientId: user.id });
|
||||||
expect(mocks.user.get).toHaveBeenCalledWith(userStub.user1.id, { withDeleted: false });
|
expect(mocks.user.get).toHaveBeenCalledWith(user.id, { withDeleted: false });
|
||||||
expect(mocks.email.renderEmail).not.toHaveBeenCalled();
|
expect(mocks.email.renderEmail).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should skip recipient with disabled email notifications for the album update event', async () => {
|
it('should skip recipient with disabled email notifications for the album update event', async () => {
|
||||||
mocks.album.getById.mockResolvedValue({
|
const user = UserFactory.from()
|
||||||
...albumStub.emptyWithValidThumbnail,
|
.metadata({
|
||||||
albumUsers: [{ user: { id: userStub.user1.id } } as AlbumUser],
|
key: UserMetadataKey.Preferences,
|
||||||
});
|
value: { emailNotifications: { enabled: true, albumUpdate: false } },
|
||||||
mocks.user.get.mockResolvedValue({
|
})
|
||||||
...userStub.user1,
|
.build();
|
||||||
metadata: [
|
const album = AlbumFactory.from().albumUser({ userId: user.id }).build();
|
||||||
{
|
mocks.album.getById.mockResolvedValue(album);
|
||||||
key: UserMetadataKey.Preferences,
|
mocks.user.get.mockResolvedValue(user);
|
||||||
value: { emailNotifications: { enabled: true, albumUpdate: false } },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
mocks.notification.create.mockResolvedValue(notificationStub.albumEvent);
|
mocks.notification.create.mockResolvedValue(notificationStub.albumEvent);
|
||||||
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
||||||
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([]);
|
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([]);
|
||||||
|
|
||||||
await sut.handleAlbumUpdate({ id: '', recipientId: userStub.user1.id });
|
await sut.handleAlbumUpdate({ id: '', recipientId: user.id });
|
||||||
expect(mocks.user.get).toHaveBeenCalledWith(userStub.user1.id, { withDeleted: false });
|
expect(mocks.user.get).toHaveBeenCalledWith(user.id, { withDeleted: false });
|
||||||
expect(mocks.email.renderEmail).not.toHaveBeenCalled();
|
expect(mocks.email.renderEmail).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send email', async () => {
|
it('should send email', async () => {
|
||||||
mocks.album.getById.mockResolvedValue({
|
const user = UserFactory.create();
|
||||||
...albumStub.emptyWithValidThumbnail,
|
const album = AlbumFactory.from().albumUser({ userId: user.id }).build();
|
||||||
albumUsers: [{ user: { id: userStub.user1.id } } as AlbumUser],
|
mocks.album.getById.mockResolvedValue(album);
|
||||||
});
|
mocks.user.get.mockResolvedValue(user);
|
||||||
mocks.user.get.mockResolvedValue(userStub.user1);
|
|
||||||
mocks.notification.create.mockResolvedValue(notificationStub.albumEvent);
|
mocks.notification.create.mockResolvedValue(notificationStub.albumEvent);
|
||||||
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
mocks.email.renderEmail.mockResolvedValue({ html: '', text: '' });
|
||||||
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([]);
|
mocks.assetJob.getAlbumThumbnailFiles.mockResolvedValue([]);
|
||||||
|
|
||||||
await sut.handleAlbumUpdate({ id: '', recipientId: userStub.user1.id });
|
await sut.handleAlbumUpdate({ id: '', recipientId: user.id });
|
||||||
expect(mocks.user.get).toHaveBeenCalledWith(userStub.user1.id, { withDeleted: false });
|
expect(mocks.user.get).toHaveBeenCalledWith(user.id, { withDeleted: false });
|
||||||
expect(mocks.email.renderEmail).toHaveBeenCalled();
|
expect(mocks.email.renderEmail).toHaveBeenCalled();
|
||||||
expect(mocks.job.queue).toHaveBeenCalled();
|
expect(mocks.job.queue).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import _ from 'lodash';
|
||||||
import { AssetIdErrorReason } from 'src/dtos/asset-ids.response.dto';
|
import { AssetIdErrorReason } from 'src/dtos/asset-ids.response.dto';
|
||||||
import { SharedLinkType } from 'src/enum';
|
import { SharedLinkType } from 'src/enum';
|
||||||
import { SharedLinkService } from 'src/services/shared-link.service';
|
import { SharedLinkService } from 'src/services/shared-link.service';
|
||||||
import { albumStub } from 'test/fixtures/album.stub';
|
import { AlbumFactory } from 'test/factories/album.factory';
|
||||||
import { assetStub } from 'test/fixtures/asset.stub';
|
import { assetStub } from 'test/fixtures/asset.stub';
|
||||||
import { authStub } from 'test/fixtures/auth.stub';
|
import { authStub } from 'test/fixtures/auth.stub';
|
||||||
import { sharedLinkResponseStub, sharedLinkStub } from 'test/fixtures/shared-link.stub';
|
import { sharedLinkResponseStub, sharedLinkStub } from 'test/fixtures/shared-link.stub';
|
||||||
|
|
@ -120,19 +120,17 @@ describe(SharedLinkService.name, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create an album shared link', async () => {
|
it('should create an album shared link', async () => {
|
||||||
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([albumStub.oneAsset.id]));
|
const album = AlbumFactory.from().asset().build();
|
||||||
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
||||||
mocks.sharedLink.create.mockResolvedValue(sharedLinkStub.valid);
|
mocks.sharedLink.create.mockResolvedValue(sharedLinkStub.valid);
|
||||||
|
|
||||||
await sut.create(authStub.admin, { type: SharedLinkType.Album, albumId: albumStub.oneAsset.id });
|
await sut.create(authStub.admin, { type: SharedLinkType.Album, albumId: album.id });
|
||||||
|
|
||||||
expect(mocks.access.album.checkOwnerAccess).toHaveBeenCalledWith(
|
expect(mocks.access.album.checkOwnerAccess).toHaveBeenCalledWith(authStub.admin.user.id, new Set([album.id]));
|
||||||
authStub.admin.user.id,
|
|
||||||
new Set([albumStub.oneAsset.id]),
|
|
||||||
);
|
|
||||||
expect(mocks.sharedLink.create).toHaveBeenCalledWith({
|
expect(mocks.sharedLink.create).toHaveBeenCalledWith({
|
||||||
type: SharedLinkType.Album,
|
type: SharedLinkType.Album,
|
||||||
userId: authStub.admin.user.id,
|
userId: authStub.admin.user.id,
|
||||||
albumId: albumStub.oneAsset.id,
|
albumId: album.id,
|
||||||
allowDownload: true,
|
allowDownload: true,
|
||||||
allowUpload: true,
|
allowUpload: true,
|
||||||
description: null,
|
description: null,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { Stats } from 'node:fs';
|
||||||
import { defaults, SystemConfig } from 'src/config';
|
import { defaults, SystemConfig } from 'src/config';
|
||||||
import { AssetPathType, JobStatus } from 'src/enum';
|
import { AssetPathType, JobStatus } from 'src/enum';
|
||||||
import { StorageTemplateService } from 'src/services/storage-template.service';
|
import { StorageTemplateService } from 'src/services/storage-template.service';
|
||||||
import { albumStub } from 'test/fixtures/album.stub';
|
import { AlbumFactory } from 'test/factories/album.factory';
|
||||||
import { assetStub } from 'test/fixtures/asset.stub';
|
import { assetStub } from 'test/fixtures/asset.stub';
|
||||||
import { userStub } from 'test/fixtures/user.stub';
|
import { userStub } from 'test/fixtures/user.stub';
|
||||||
import { factory } from 'test/small.factory';
|
import { factory } from 'test/small.factory';
|
||||||
|
|
@ -143,7 +143,7 @@ describe(StorageTemplateService.name, () => {
|
||||||
it('should use handlebar if condition for album', async () => {
|
it('should use handlebar if condition for album', async () => {
|
||||||
const asset = assetStub.storageAsset();
|
const asset = assetStub.storageAsset();
|
||||||
const user = userStub.user1;
|
const user = userStub.user1;
|
||||||
const album = albumStub.oneAsset;
|
const album = AlbumFactory.from().asset().build();
|
||||||
const config = structuredClone(defaults);
|
const config = structuredClone(defaults);
|
||||||
config.storageTemplate.template = '{{y}}/{{#if album}}{{album}}{{else}}other/{{MM}}{{/if}}/{{filename}}';
|
config.storageTemplate.template = '{{y}}/{{#if album}}{{album}}{{else}}other/{{MM}}{{/if}}/{{filename}}';
|
||||||
|
|
||||||
|
|
@ -191,7 +191,7 @@ describe(StorageTemplateService.name, () => {
|
||||||
it('should handle album startDate', async () => {
|
it('should handle album startDate', async () => {
|
||||||
const asset = assetStub.storageAsset();
|
const asset = assetStub.storageAsset();
|
||||||
const user = userStub.user1;
|
const user = userStub.user1;
|
||||||
const album = albumStub.oneAsset;
|
const album = AlbumFactory.from().asset().build();
|
||||||
const config = structuredClone(defaults);
|
const config = structuredClone(defaults);
|
||||||
config.storageTemplate.template =
|
config.storageTemplate.template =
|
||||||
'{{#if album}}{{album-startDate-y}}/{{album-startDate-MM}} - {{album}}{{else}}{{y}}/{{MM}}/{{/if}}/{{filename}}';
|
'{{#if album}}{{album-startDate-y}}/{{album-startDate-MM}} - {{album}}{{else}}{{y}}/{{MM}}/{{/if}}/{{filename}}';
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import { UserLike } from 'test/factories/types';
|
||||||
import { newDate, newUuid, newUuidV7 } from 'test/small.factory';
|
import { newDate, newUuid, newUuidV7 } from 'test/small.factory';
|
||||||
|
|
||||||
export class UserFactory {
|
export class UserFactory {
|
||||||
|
#metadata: Selectable<UserMetadataTable>[] = [];
|
||||||
|
|
||||||
private constructor(private value: Selectable<UserTable>) {}
|
private constructor(private value: Selectable<UserTable>) {}
|
||||||
|
|
||||||
static create(dto: UserLike = {}) {
|
static create(dto: UserLike = {}) {
|
||||||
|
|
@ -37,10 +39,21 @@ export class UserFactory {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metadata(dto: Partial<Selectable<UserMetadataTable>> & Pick<Selectable<UserMetadataTable>, 'key' | 'value'>) {
|
||||||
|
this.#metadata.push({
|
||||||
|
updatedAt: newDate(),
|
||||||
|
updateId: newUuid(),
|
||||||
|
userId: newUuid(),
|
||||||
|
...dto,
|
||||||
|
});
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
return {
|
return {
|
||||||
...this.value,
|
...this.value,
|
||||||
metadata: [] as UserMetadataTable[],
|
metadata: this.#metadata,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
84
server/test/fixtures/album.stub.ts
vendored
84
server/test/fixtures/album.stub.ts
vendored
|
|
@ -1,84 +0,0 @@
|
||||||
import { AlbumUserRole, AssetOrder } from 'src/enum';
|
|
||||||
import { assetStub } from 'test/fixtures/asset.stub';
|
|
||||||
import { authStub } from 'test/fixtures/auth.stub';
|
|
||||||
import { userStub } from 'test/fixtures/user.stub';
|
|
||||||
|
|
||||||
export const albumStub = {
|
|
||||||
empty: Object.freeze({
|
|
||||||
id: 'album-1',
|
|
||||||
albumName: 'Empty album',
|
|
||||||
description: '',
|
|
||||||
ownerId: authStub.admin.user.id,
|
|
||||||
owner: userStub.admin,
|
|
||||||
assets: [],
|
|
||||||
albumThumbnailAsset: null,
|
|
||||||
albumThumbnailAssetId: null,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
deletedAt: null,
|
|
||||||
sharedLinks: [],
|
|
||||||
albumUsers: [],
|
|
||||||
isActivityEnabled: true,
|
|
||||||
order: AssetOrder.Desc,
|
|
||||||
updateId: '42',
|
|
||||||
}),
|
|
||||||
sharedWithUser: Object.freeze({
|
|
||||||
id: 'album-2',
|
|
||||||
albumName: 'Empty album shared with user',
|
|
||||||
description: '',
|
|
||||||
ownerId: authStub.admin.user.id,
|
|
||||||
owner: userStub.admin,
|
|
||||||
assets: [],
|
|
||||||
albumThumbnailAsset: null,
|
|
||||||
albumThumbnailAssetId: null,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
deletedAt: null,
|
|
||||||
sharedLinks: [],
|
|
||||||
albumUsers: [
|
|
||||||
{
|
|
||||||
user: userStub.user1,
|
|
||||||
role: AlbumUserRole.Editor,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
isActivityEnabled: true,
|
|
||||||
order: AssetOrder.Desc,
|
|
||||||
updateId: '42',
|
|
||||||
}),
|
|
||||||
oneAsset: Object.freeze({
|
|
||||||
id: 'album-4',
|
|
||||||
albumName: 'Album with one asset',
|
|
||||||
description: '',
|
|
||||||
ownerId: authStub.admin.user.id,
|
|
||||||
owner: userStub.admin,
|
|
||||||
assets: [assetStub.image],
|
|
||||||
albumThumbnailAsset: null,
|
|
||||||
albumThumbnailAssetId: null,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
deletedAt: null,
|
|
||||||
sharedLinks: [],
|
|
||||||
albumUsers: [],
|
|
||||||
isActivityEnabled: true,
|
|
||||||
order: AssetOrder.Desc,
|
|
||||||
updateId: '42',
|
|
||||||
}),
|
|
||||||
emptyWithValidThumbnail: Object.freeze({
|
|
||||||
id: 'album-5',
|
|
||||||
albumName: 'Empty album with valid thumbnail',
|
|
||||||
description: '',
|
|
||||||
ownerId: authStub.admin.user.id,
|
|
||||||
owner: userStub.admin,
|
|
||||||
assets: [],
|
|
||||||
albumThumbnailAsset: assetStub.image,
|
|
||||||
albumThumbnailAssetId: assetStub.image.id,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
deletedAt: null,
|
|
||||||
sharedLinks: [],
|
|
||||||
albumUsers: [],
|
|
||||||
isActivityEnabled: true,
|
|
||||||
order: AssetOrder.Desc,
|
|
||||||
updateId: '42',
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
Loading…
Reference in a new issue