From 2cc9220b4783d461d4d35cf8a149b7fb57526bb6 Mon Sep 17 00:00:00 2001 From: mgabor <> Date: Mon, 22 Apr 2024 13:50:28 +0200 Subject: [PATCH] fix e2e tests and some bugs --- e2e/src/api/specs/album.e2e-spec.ts | 28 +++++++++++++++++++++++----- server/src/entities/album.entity.ts | 2 +- server/src/services/album.service.ts | 11 ++--------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/e2e/src/api/specs/album.e2e-spec.ts b/e2e/src/api/specs/album.e2e-spec.ts index 1925cd00f2..9d025c0132 100644 --- a/e2e/src/api/specs/album.e2e-spec.ts +++ b/e2e/src/api/specs/album.e2e-spec.ts @@ -79,11 +79,28 @@ describe('/album', () => { }), ]); - await utils.updateAlbumUser(user2.accessToken, { - id: albums[3].id, - userId: user1.userId, - updateAlbumUserDto: { role: AlbumUserRole.Editor }, - }); + // Make editor + await Promise.all([ + utils.updateAlbumUser(user1.accessToken, { + id: albums[0].id, + userId: user2.userId, + updateAlbumUserDto: { role: AlbumUserRole.Editor }, + }), + utils.updateAlbumUser(user2.accessToken, { + id: albums[3].id, + userId: user1.userId, + updateAlbumUserDto: { role: AlbumUserRole.Editor }, + }), + utils.updateAlbumUser(user3.accessToken, { + id: albums[6].id, + userId: user1.userId, + updateAlbumUserDto: { role: AlbumUserRole.Editor }, + }), + ]); + + albums[0].albumUsers[0].role = AlbumUserRole.Editor; + albums[3].albumUsers[0].role = AlbumUserRole.Editor; + albums[6].albumUsers[0].role = AlbumUserRole.Editor; await addAssetsToAlbum( { id: albums[3].id, bulkIdsDto: { ids: [user1Asset1.id] } }, @@ -364,6 +381,7 @@ describe('/album', () => { albumThumbnailAssetId: null, shared: false, sharedUsers: [], + albumUsers: [], hasSharedLink: false, assets: [], assetCount: 0, diff --git a/server/src/entities/album.entity.ts b/server/src/entities/album.entity.ts index c5353de3db..39d5b72bf2 100644 --- a/server/src/entities/album.entity.ts +++ b/server/src/entities/album.entity.ts @@ -53,7 +53,7 @@ export class AlbumEntity { @Column({ comment: 'Asset ID to be used as thumbnail', nullable: true }) albumThumbnailAssetId!: string | null; - @OneToMany(() => AlbumUserEntity, ({ album }) => album) + @OneToMany(() => AlbumUserEntity, ({ album }) => album, { cascade: true, onDelete: 'CASCADE' }) albumUsers!: AlbumUserEntity[]; @ManyToMany(() => AssetEntity, (asset) => asset.albums) diff --git a/server/src/services/album.service.ts b/server/src/services/album.service.ts index 216c6b2b5d..764ff3136c 100644 --- a/server/src/services/album.service.ts +++ b/server/src/services/album.service.ts @@ -214,7 +214,7 @@ export class AlbumService { async addUsers(auth: AuthDto, id: string, dto: AddUsersDto): Promise { await this.access.requirePermission(auth, Permission.ALBUM_SHARE, id); - const album = await this.findOrFail(id, { withAssets: true }); + const album = await this.findOrFail(id, { withAssets: false }); for (const userId of dto.sharedUserIds) { if (album.ownerId === userId) { @@ -234,7 +234,7 @@ export class AlbumService { album.albumUsers.push(await this.albumUserRepository.create({ userId: userId, albumId: id })); } - return mapAlbumWithoutAssets(album); + return this.findOrFail(id, { withAssets: true }).then(mapAlbumWithoutAssets); } async removeUser(auth: AuthDto, id: string, userId: string | 'me'): Promise { @@ -264,13 +264,6 @@ export class AlbumService { async updateUser(auth: AuthDto, id: string, userId: string, dto: Partial): Promise { await this.access.requirePermission(auth, Permission.ALBUM_SHARE, id); - const album = await this.findOrFail(id, { withAssets: false }); - - const permission = album.albumUsers.find(({ user: { id } }) => id === userId); - if (!permission) { - throw new BadRequestException('Album not shared with user'); - } - await this.albumUserRepository.update({ albumId: id, userId }, { role: dto.role }); }