Skip to content

Commit

Permalink
fix(server): get album's assets in getAlbumInfo route (#5325)
Browse files Browse the repository at this point in the history
* fix(server): get album's assets in getAlbumInfo route

* unit test

* test: e2e tests
  • Loading branch information
alextran1502 committed Nov 27, 2023
1 parent 034b308 commit 4e5eef1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
6 changes: 3 additions & 3 deletions server/src/domain/album/album.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand All @@ -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']),
Expand All @@ -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']));
});

Expand Down
2 changes: 1 addition & 1 deletion server/src/domain/album/album.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class AlbumService {
async get(authUser: AuthUserDto, id: string, dto: AlbumInfoDto): Promise<AlbumResponseDto> {
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]);

Expand Down
22 changes: 22 additions & 0 deletions server/test/e2e/album.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 4e5eef1

Please sign in to comment.