From 4e5eef129d47830e009c232d9111855abccc79a4 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 26 Nov 2023 21:21:04 -0600 Subject: [PATCH] fix(server): get album's assets in getAlbumInfo route (#5325) * fix(server): get album's assets in getAlbumInfo route * unit test * test: e2e tests --- server/src/domain/album/album.service.spec.ts | 6 ++--- server/src/domain/album/album.service.ts | 2 +- server/test/e2e/album.e2e-spec.ts | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/server/src/domain/album/album.service.spec.ts b/server/src/domain/album/album.service.spec.ts index c133428979540..e890305381b42 100644 --- a/server/src/domain/album/album.service.spec.ts +++ b/server/src/domain/album/album.service.spec.ts @@ -452,7 +452,7 @@ describe(AlbumService.name, () => { await sut.get(authStub.admin, albumStub.oneAsset.id, {}); - expect(albumMock.getById).toHaveBeenCalledWith(albumStub.oneAsset.id, { withAssets: false }); + expect(albumMock.getById).toHaveBeenCalledWith(albumStub.oneAsset.id, { withAssets: true }); expect(accessMock.album.checkOwnerAccess).toHaveBeenCalledWith( authStub.admin.id, new Set([albumStub.oneAsset.id]), @@ -473,7 +473,7 @@ describe(AlbumService.name, () => { await sut.get(authStub.adminSharedLink, 'album-123', {}); - expect(albumMock.getById).toHaveBeenCalledWith('album-123', { withAssets: false }); + expect(albumMock.getById).toHaveBeenCalledWith('album-123', { withAssets: true }); expect(accessMock.album.checkSharedLinkAccess).toHaveBeenCalledWith( authStub.adminSharedLink.sharedLinkId, new Set(['album-123']), @@ -494,7 +494,7 @@ describe(AlbumService.name, () => { await sut.get(authStub.user1, 'album-123', {}); - expect(albumMock.getById).toHaveBeenCalledWith('album-123', { withAssets: false }); + expect(albumMock.getById).toHaveBeenCalledWith('album-123', { withAssets: true }); expect(accessMock.album.checkSharedAlbumAccess).toHaveBeenCalledWith(authStub.user1.id, new Set(['album-123'])); }); diff --git a/server/src/domain/album/album.service.ts b/server/src/domain/album/album.service.ts index 6d9fa4e707baa..308735d43c945 100644 --- a/server/src/domain/album/album.service.ts +++ b/server/src/domain/album/album.service.ts @@ -102,7 +102,7 @@ export class AlbumService { async get(authUser: AuthUserDto, id: string, dto: AlbumInfoDto): Promise { await this.access.requirePermission(authUser, Permission.ALBUM_READ, id); await this.albumRepository.updateThumbnails(); - const withAssets = dto.withoutAssets === undefined ? false : !dto.withoutAssets; + const withAssets = dto.withoutAssets === undefined ? true : !dto.withoutAssets; const album = await this.findOrFail(id, { withAssets }); const [albumMetadataForIds] = await this.albumRepository.getMetadataForIds([album.id]); diff --git a/server/test/e2e/album.e2e-spec.ts b/server/test/e2e/album.e2e-spec.ts index 775bb0b6879a9..8058d9593c2c9 100644 --- a/server/test/e2e/album.e2e-spec.ts +++ b/server/test/e2e/album.e2e-spec.ts @@ -261,6 +261,28 @@ describe(`${AlbumController.name} (e2e)`, () => { expect(status).toBe(200); expect(body).toEqual(user2Albums[0]); }); + + it('should return album info with assets when withoutAssets is undefined', async () => { + const { status, body } = await request(server) + .get(`/album/${user1Albums[0].id}`) + .set('Authorization', `Bearer ${user1.accessToken}`); + + expect(status).toBe(200); + expect(body).toEqual(user1Albums[0]); + }); + + it('should return album info without assets when withoutAssets is true', async () => { + const { status, body } = await request(server) + .get(`/album/${user1Albums[0].id}?withoutAssets=true`) + .set('Authorization', `Bearer ${user1.accessToken}`); + + expect(status).toBe(200); + expect(body).toEqual({ + ...user1Albums[0], + assets: [], + assetCount: 1, + }); + }); }); describe('PUT /album/:id/assets', () => {