|
|
|
@@ -44,7 +44,8 @@ describe(AlbumService.name, () => {
|
|
|
|
|
describe('getAll', () => {
|
|
|
|
|
it('gets list of albums for auth user', async () => {
|
|
|
|
|
const album = AlbumFactory.from().albumUser().build();
|
|
|
|
|
const sharedWithUserAlbum = AlbumFactory.from().owner(album.owner).albumUser().build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
const sharedWithUserAlbum = AlbumFactory.from().owner(owner).albumUser().build();
|
|
|
|
|
mocks.album.getOwned.mockResolvedValue([getForAlbum(album), getForAlbum(sharedWithUserAlbum)]);
|
|
|
|
|
mocks.album.getMetadataForIds.mockResolvedValue([
|
|
|
|
|
{
|
|
|
|
@@ -63,7 +64,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const result = await sut.getAll(AuthFactory.create(album.owner), {});
|
|
|
|
|
const result = await sut.getAll(AuthFactory.create(owner), {});
|
|
|
|
|
expect(result).toHaveLength(2);
|
|
|
|
|
expect(result[0].id).toEqual(album.id);
|
|
|
|
|
expect(result[1].id).toEqual(sharedWithUserAlbum.id);
|
|
|
|
@@ -76,6 +77,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
.asset({}, (builder) => builder.exif())
|
|
|
|
|
.asset({}, (builder) => builder.exif())
|
|
|
|
|
.build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.album.getByAssetId.mockResolvedValue([getForAlbum(album)]);
|
|
|
|
|
mocks.album.getMetadataForIds.mockResolvedValue([
|
|
|
|
|
{
|
|
|
|
@@ -87,7 +89,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const result = await sut.getAll(AuthFactory.create(album.owner), { assetId: album.assets[0].id });
|
|
|
|
|
const result = await sut.getAll(AuthFactory.create(owner), { assetId: album.assets[0].id });
|
|
|
|
|
expect(result).toHaveLength(1);
|
|
|
|
|
expect(result[0].id).toEqual(album.id);
|
|
|
|
|
expect(mocks.album.getByAssetId).toHaveBeenCalledTimes(1);
|
|
|
|
@@ -95,6 +97,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
it('gets list of albums that are shared', async () => {
|
|
|
|
|
const album = AlbumFactory.from().albumUser().build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.album.getShared.mockResolvedValue([getForAlbum(album)]);
|
|
|
|
|
mocks.album.getMetadataForIds.mockResolvedValue([
|
|
|
|
|
{
|
|
|
|
@@ -106,7 +109,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const result = await sut.getAll(AuthFactory.create(album.owner), { shared: true });
|
|
|
|
|
const result = await sut.getAll(AuthFactory.create(owner), { shared: true });
|
|
|
|
|
expect(result).toHaveLength(1);
|
|
|
|
|
expect(result[0].id).toEqual(album.id);
|
|
|
|
|
expect(mocks.album.getShared).toHaveBeenCalledTimes(1);
|
|
|
|
@@ -114,6 +117,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
it('gets list of albums that are NOT shared', async () => {
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.album.getNotShared.mockResolvedValue([getForAlbum(album)]);
|
|
|
|
|
mocks.album.getMetadataForIds.mockResolvedValue([
|
|
|
|
|
{
|
|
|
|
@@ -125,7 +129,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const result = await sut.getAll(AuthFactory.create(album.owner), { shared: false });
|
|
|
|
|
const result = await sut.getAll(AuthFactory.create(owner), { shared: false });
|
|
|
|
|
expect(result).toHaveLength(1);
|
|
|
|
|
expect(result[0].id).toEqual(album.id);
|
|
|
|
|
expect(mocks.album.getNotShared).toHaveBeenCalledTimes(1);
|
|
|
|
@@ -134,6 +138,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
it('counts assets correctly', async () => {
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.album.getOwned.mockResolvedValue([getForAlbum(album)]);
|
|
|
|
|
mocks.album.getMetadataForIds.mockResolvedValue([
|
|
|
|
|
{
|
|
|
|
@@ -145,7 +150,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const result = await sut.getAll(AuthFactory.create(album.owner), {});
|
|
|
|
|
const result = await sut.getAll(AuthFactory.create(owner), {});
|
|
|
|
|
expect(result).toHaveLength(1);
|
|
|
|
|
expect(result[0].assetCount).toEqual(1);
|
|
|
|
|
expect(mocks.album.getOwned).toHaveBeenCalledTimes(1);
|
|
|
|
@@ -159,13 +164,14 @@ describe(AlbumService.name, () => {
|
|
|
|
|
.asset({ id: assetId }, (asset) => asset.exif())
|
|
|
|
|
.albumUser(albumUser)
|
|
|
|
|
.build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
|
|
|
|
|
mocks.album.create.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.user.get.mockResolvedValue(UserFactory.create(album.albumUsers[0].user));
|
|
|
|
|
mocks.user.getMetadata.mockResolvedValue([]);
|
|
|
|
|
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set([assetId]));
|
|
|
|
|
|
|
|
|
|
await sut.create(AuthFactory.create(album.owner), {
|
|
|
|
|
await sut.create(AuthFactory.create(owner), {
|
|
|
|
|
albumName: 'test',
|
|
|
|
|
albumUsers: [albumUser],
|
|
|
|
|
description: 'description',
|
|
|
|
@@ -174,20 +180,27 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.create).toHaveBeenCalledWith(
|
|
|
|
|
{
|
|
|
|
|
ownerId: album.owner.id,
|
|
|
|
|
albumName: 'test',
|
|
|
|
|
description: 'description',
|
|
|
|
|
order: album.order,
|
|
|
|
|
albumThumbnailAssetId: assetId,
|
|
|
|
|
},
|
|
|
|
|
[assetId],
|
|
|
|
|
[{ userId: albumUser.userId, role: AlbumUserRole.Editor }],
|
|
|
|
|
[
|
|
|
|
|
{ userId: owner.id, role: AlbumUserRole.Owner },
|
|
|
|
|
{ userId: albumUser.userId, role: AlbumUserRole.Editor },
|
|
|
|
|
],
|
|
|
|
|
owner.id,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(mocks.user.get).toHaveBeenCalledWith(albumUser.userId, {});
|
|
|
|
|
expect(mocks.user.getMetadata).toHaveBeenCalledWith(album.owner.id);
|
|
|
|
|
expect(mocks.access.asset.checkOwnerAccess).toHaveBeenCalledWith(album.owner.id, new Set([assetId]), false);
|
|
|
|
|
expect(mocks.event.emit).toHaveBeenCalledWith('AlbumInvite', { id: album.id, userId: albumUser.userId });
|
|
|
|
|
expect(mocks.user.getMetadata).toHaveBeenCalledWith(owner.id);
|
|
|
|
|
expect(mocks.access.asset.checkOwnerAccess).toHaveBeenCalledWith(owner.id, new Set([assetId]), false);
|
|
|
|
|
expect(mocks.event.emit).toHaveBeenCalledWith('AlbumInvite', {
|
|
|
|
|
id: album.id,
|
|
|
|
|
userId: albumUser.userId,
|
|
|
|
|
senderName: owner.name,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('creates album with assetOrder from user preferences', async () => {
|
|
|
|
@@ -197,8 +210,10 @@ describe(AlbumService.name, () => {
|
|
|
|
|
.asset({ id: assetId }, (asset) => asset.exif())
|
|
|
|
|
.albumUser(albumUser)
|
|
|
|
|
.build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.album.create.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.user.get.mockResolvedValue(album.albumUsers[0].user);
|
|
|
|
|
mocks.albumUser.create.mockResolvedValue(album.albumUsers[0]);
|
|
|
|
|
mocks.user.get.mockResolvedValue(UserFactory.create(album.albumUsers[1].user));
|
|
|
|
|
mocks.user.getMetadata.mockResolvedValue([
|
|
|
|
|
{
|
|
|
|
|
key: UserMetadataKey.Preferences,
|
|
|
|
@@ -211,7 +226,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
]);
|
|
|
|
|
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set([assetId]));
|
|
|
|
|
|
|
|
|
|
await sut.create(AuthFactory.create(album.owner), {
|
|
|
|
|
await sut.create(AuthFactory.create(owner), {
|
|
|
|
|
albumName: album.albumName,
|
|
|
|
|
albumUsers: [albumUser],
|
|
|
|
|
description: album.description,
|
|
|
|
@@ -220,20 +235,24 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.create).toHaveBeenCalledWith(
|
|
|
|
|
{
|
|
|
|
|
ownerId: album.owner.id,
|
|
|
|
|
albumName: album.albumName,
|
|
|
|
|
description: album.description,
|
|
|
|
|
order: 'asc',
|
|
|
|
|
albumThumbnailAssetId: assetId,
|
|
|
|
|
},
|
|
|
|
|
[assetId],
|
|
|
|
|
[albumUser],
|
|
|
|
|
[{ userId: owner.id, role: AlbumUserRole.Owner }, albumUser],
|
|
|
|
|
owner.id,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(mocks.user.get).toHaveBeenCalledWith(albumUser.userId, {});
|
|
|
|
|
expect(mocks.user.getMetadata).toHaveBeenCalledWith(album.owner.id);
|
|
|
|
|
expect(mocks.access.asset.checkOwnerAccess).toHaveBeenCalledWith(album.owner.id, new Set([assetId]), false);
|
|
|
|
|
expect(mocks.event.emit).toHaveBeenCalledWith('AlbumInvite', { id: album.id, userId: albumUser.userId });
|
|
|
|
|
expect(mocks.user.getMetadata).toHaveBeenCalledWith(owner.id);
|
|
|
|
|
expect(mocks.access.asset.checkOwnerAccess).toHaveBeenCalledWith(owner.id, new Set([assetId]), false);
|
|
|
|
|
expect(mocks.event.emit).toHaveBeenCalledWith('AlbumInvite', {
|
|
|
|
|
id: album.id,
|
|
|
|
|
userId: albumUser.userId,
|
|
|
|
|
senderName: owner.name,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should require valid userIds', async () => {
|
|
|
|
@@ -254,12 +273,13 @@ describe(AlbumService.name, () => {
|
|
|
|
|
.asset({ id: assetId }, (asset) => asset.exif())
|
|
|
|
|
.albumUser()
|
|
|
|
|
.build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.user.get.mockResolvedValue(album.albumUsers[0].user);
|
|
|
|
|
mocks.album.create.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.user.getMetadata.mockResolvedValue([]);
|
|
|
|
|
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set([assetId]));
|
|
|
|
|
|
|
|
|
|
await sut.create(AuthFactory.create(album.owner), {
|
|
|
|
|
await sut.create(AuthFactory.create(owner), {
|
|
|
|
|
albumName: album.albumName,
|
|
|
|
|
description: album.description,
|
|
|
|
|
assetIds: [assetId, 'asset-2'],
|
|
|
|
@@ -267,29 +287,26 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.create).toHaveBeenCalledWith(
|
|
|
|
|
{
|
|
|
|
|
ownerId: album.owner.id,
|
|
|
|
|
albumName: album.albumName,
|
|
|
|
|
description: album.description,
|
|
|
|
|
order: 'desc',
|
|
|
|
|
albumThumbnailAssetId: assetId,
|
|
|
|
|
},
|
|
|
|
|
[assetId],
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.access.asset.checkOwnerAccess).toHaveBeenCalledWith(
|
|
|
|
|
album.owner.id,
|
|
|
|
|
new Set([assetId, 'asset-2']),
|
|
|
|
|
false,
|
|
|
|
|
[{ userId: owner.id, role: AlbumUserRole.Owner }],
|
|
|
|
|
owner.id,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.access.asset.checkOwnerAccess).toHaveBeenCalledWith(owner.id, new Set([assetId, 'asset-2']), false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should throw an error if the userId is the ownerId', async () => {
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
mocks.user.get.mockResolvedValue(album.owner);
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.user.get.mockResolvedValue(owner);
|
|
|
|
|
await expect(
|
|
|
|
|
sut.create(AuthFactory.create(album.owner), {
|
|
|
|
|
sut.create(AuthFactory.create(owner), {
|
|
|
|
|
albumName: 'Empty album',
|
|
|
|
|
albumUsers: [{ userId: album.owner.id, role: AlbumUserRole.Editor }],
|
|
|
|
|
albumUsers: [{ userId: owner.id, role: AlbumUserRole.Editor }],
|
|
|
|
|
}),
|
|
|
|
|
).rejects.toBeInstanceOf(BadRequestException);
|
|
|
|
|
expect(mocks.album.create).not.toHaveBeenCalled();
|
|
|
|
@@ -312,20 +329,22 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
it('should prevent updating a not owned album (shared with auth user)', async () => {
|
|
|
|
|
const album = AlbumFactory.from().albumUser().build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set());
|
|
|
|
|
await expect(
|
|
|
|
|
sut.update(AuthFactory.create(album.owner), album.id, { albumName: 'new album name' }),
|
|
|
|
|
sut.update(AuthFactory.create(owner), album.id, { albumName: 'new album name' }),
|
|
|
|
|
).rejects.toBeInstanceOf(BadRequestException);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should require a valid thumbnail asset id', async () => {
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.album.getAssetIds.mockResolvedValue(new Set());
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
sut.update(AuthFactory.create(album.owner), album.id, { albumThumbnailAssetId: 'not-in-album' }),
|
|
|
|
|
sut.update(AuthFactory.create(owner), album.id, { albumThumbnailAssetId: 'not-in-album' }),
|
|
|
|
|
).rejects.toBeInstanceOf(BadRequestException);
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.getAssetIds).toHaveBeenCalledWith(album.id, ['not-in-album']);
|
|
|
|
@@ -334,43 +353,51 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
it('should allow the owner to update the album', async () => {
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.album.update.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
|
|
|
|
|
await sut.update(AuthFactory.create(album.owner), album.id, { albumName: 'new album name' });
|
|
|
|
|
await sut.update(AuthFactory.create(owner), album.id, { albumName: 'new album name' });
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledWith(album.id, { id: album.id, albumName: 'new album name' });
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledWith(
|
|
|
|
|
album.id,
|
|
|
|
|
{ id: album.id, albumName: 'new album name' },
|
|
|
|
|
owner.id,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('delete', () => {
|
|
|
|
|
it('should require permissions', async () => {
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set());
|
|
|
|
|
|
|
|
|
|
await expect(sut.delete(AuthFactory.create(album.owner), album.id)).rejects.toBeInstanceOf(BadRequestException);
|
|
|
|
|
await expect(sut.delete(AuthFactory.create(owner), album.id)).rejects.toBeInstanceOf(BadRequestException);
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.delete).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not let a shared user delete the album', async () => {
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set());
|
|
|
|
|
|
|
|
|
|
await expect(sut.delete(AuthFactory.create(album.owner), album.id)).rejects.toBeInstanceOf(BadRequestException);
|
|
|
|
|
await expect(sut.delete(AuthFactory.create(owner), album.id)).rejects.toBeInstanceOf(BadRequestException);
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.delete).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should let the owner delete an album', async () => {
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
|
|
|
|
|
await sut.delete(AuthFactory.create(album.owner), album.id);
|
|
|
|
|
await sut.delete(AuthFactory.create(owner), album.id);
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.delete).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(mocks.album.delete).toHaveBeenCalledWith(album.id);
|
|
|
|
@@ -391,10 +418,11 @@ describe(AlbumService.name, () => {
|
|
|
|
|
it('should throw an error if the userId is already added', async () => {
|
|
|
|
|
const userId = newUuid();
|
|
|
|
|
const album = AlbumFactory.from().albumUser({ userId }).build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
await expect(
|
|
|
|
|
sut.addUsers(AuthFactory.create(album.owner), album.id, { albumUsers: [{ userId }] }),
|
|
|
|
|
sut.addUsers(AuthFactory.create(owner), album.id, { albumUsers: [{ userId }] }),
|
|
|
|
|
).rejects.toBeInstanceOf(BadRequestException);
|
|
|
|
|
expect(mocks.album.update).not.toHaveBeenCalled();
|
|
|
|
|
expect(mocks.user.get).not.toHaveBeenCalled();
|
|
|
|
@@ -402,11 +430,12 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
it('should throw an error if the userId does not exist', async () => {
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.user.get.mockResolvedValue(void 0);
|
|
|
|
|
await expect(
|
|
|
|
|
sut.addUsers(AuthFactory.create(album.owner), album.id, { albumUsers: [{ userId: 'unknown-user' }] }),
|
|
|
|
|
sut.addUsers(AuthFactory.create(owner), album.id, { albumUsers: [{ userId: 'unknown-user' }] }),
|
|
|
|
|
).rejects.toBeInstanceOf(BadRequestException);
|
|
|
|
|
expect(mocks.album.update).not.toHaveBeenCalled();
|
|
|
|
|
expect(mocks.user.get).toHaveBeenCalledWith('unknown-user', {});
|
|
|
|
@@ -414,11 +443,12 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
it('should throw an error if the userId is the ownerId', async () => {
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
await expect(
|
|
|
|
|
sut.addUsers(AuthFactory.create(album.owner), album.id, {
|
|
|
|
|
albumUsers: [{ userId: album.owner.id }],
|
|
|
|
|
sut.addUsers(AuthFactory.create(owner), album.id, {
|
|
|
|
|
albumUsers: [{ userId: owner.id }],
|
|
|
|
|
}),
|
|
|
|
|
).rejects.toBeInstanceOf(BadRequestException);
|
|
|
|
|
expect(mocks.album.update).not.toHaveBeenCalled();
|
|
|
|
@@ -427,6 +457,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
it('should add valid shared users', async () => {
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
const user = UserFactory.create();
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
@@ -434,7 +465,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
mocks.user.get.mockResolvedValue(user);
|
|
|
|
|
mocks.albumUser.create.mockResolvedValue(AlbumUserFactory.from().album(album).user(user).build());
|
|
|
|
|
|
|
|
|
|
await sut.addUsers(AuthFactory.create(album.owner), album.id, { albumUsers: [{ userId: user.id }] });
|
|
|
|
|
await sut.addUsers(AuthFactory.create(owner), album.id, { albumUsers: [{ userId: user.id }] });
|
|
|
|
|
|
|
|
|
|
expect(mocks.albumUser.create).toHaveBeenCalledWith({
|
|
|
|
|
userId: user.id,
|
|
|
|
@@ -443,6 +474,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
expect(mocks.event.emit).toHaveBeenCalledWith('AlbumInvite', {
|
|
|
|
|
id: album.id,
|
|
|
|
|
userId: user.id,
|
|
|
|
|
senderName: owner.name,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
@@ -460,15 +492,16 @@ describe(AlbumService.name, () => {
|
|
|
|
|
it('should remove a shared user from an owned album', async () => {
|
|
|
|
|
const userId = newUuid();
|
|
|
|
|
const album = AlbumFactory.from().albumUser({ userId }).build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.albumUser.delete.mockResolvedValue();
|
|
|
|
|
|
|
|
|
|
await expect(sut.removeUser(AuthFactory.create(album.owner), album.id, userId)).resolves.toBeUndefined();
|
|
|
|
|
await expect(sut.removeUser(AuthFactory.create(owner), album.id, userId)).resolves.toBeUndefined();
|
|
|
|
|
|
|
|
|
|
expect(mocks.albumUser.delete).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(mocks.albumUser.delete).toHaveBeenCalledWith({ albumId: album.id, userId });
|
|
|
|
|
expect(mocks.album.getById).toHaveBeenCalledWith(album.id, { withAssets: false });
|
|
|
|
|
expect(mocks.album.getById).toHaveBeenCalledWith(album.id, { withAssets: false }, owner.id);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should prevent removing a shared user from a not-owned album (shared with auth user)', async () => {
|
|
|
|
@@ -511,9 +544,10 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
it('should not allow the owner to be removed', async () => {
|
|
|
|
|
const album = AlbumFactory.from().albumUser().build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
|
|
|
|
|
await expect(sut.removeUser(AuthFactory.create(album.owner), album.id, album.owner.id)).rejects.toBeInstanceOf(
|
|
|
|
|
await expect(sut.removeUser(AuthFactory.create(owner), album.id, owner.id)).rejects.toBeInstanceOf(
|
|
|
|
|
BadRequestException,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
@@ -522,9 +556,10 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
it('should throw an error for a user not in the album', async () => {
|
|
|
|
|
const album = AlbumFactory.from().albumUser().build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
|
|
|
|
|
await expect(sut.removeUser(AuthFactory.create(album.owner), album.id, 'user-3')).rejects.toBeInstanceOf(
|
|
|
|
|
await expect(sut.removeUser(AuthFactory.create(owner), album.id, 'user-3')).rejects.toBeInstanceOf(
|
|
|
|
|
BadRequestException,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
@@ -536,10 +571,11 @@ describe(AlbumService.name, () => {
|
|
|
|
|
it('should update user role', async () => {
|
|
|
|
|
const user = UserFactory.create();
|
|
|
|
|
const album = AlbumFactory.from().albumUser({ userId: user.id }).build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.albumUser.update.mockResolvedValue();
|
|
|
|
|
|
|
|
|
|
await sut.updateUser(AuthFactory.create(album.owner), album.id, user.id, { role: AlbumUserRole.Viewer });
|
|
|
|
|
await sut.updateUser(AuthFactory.create(owner), album.id, user.id, { role: AlbumUserRole.Viewer });
|
|
|
|
|
|
|
|
|
|
expect(mocks.albumUser.update).toHaveBeenCalledWith(
|
|
|
|
|
{ albumId: album.id, userId: user.id },
|
|
|
|
@@ -551,6 +587,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
describe('getAlbumInfo', () => {
|
|
|
|
|
it('should get a shared album', async () => {
|
|
|
|
|
const album = AlbumFactory.from().albumUser().build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.album.getMetadataForIds.mockResolvedValue([
|
|
|
|
@@ -563,10 +600,10 @@ describe(AlbumService.name, () => {
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
await sut.get(AuthFactory.create(album.owner), album.id);
|
|
|
|
|
await sut.get(AuthFactory.create(owner), album.id);
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.getById).toHaveBeenCalledWith(album.id, { withAssets: false });
|
|
|
|
|
expect(mocks.access.album.checkOwnerAccess).toHaveBeenCalledWith(album.owner.id, new Set([album.id]));
|
|
|
|
|
expect(mocks.album.getById).toHaveBeenCalledWith(album.id, { withAssets: false }, owner.id);
|
|
|
|
|
expect(mocks.access.album.checkOwnerAccess).toHaveBeenCalledWith(owner.id, new Set([album.id]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should get a shared album via a shared link', async () => {
|
|
|
|
@@ -586,7 +623,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
const auth = AuthFactory.from().sharedLink().build();
|
|
|
|
|
await sut.get(auth, album.id);
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.getById).toHaveBeenCalledWith(album.id, { withAssets: false });
|
|
|
|
|
expect(mocks.album.getById).toHaveBeenCalledWith(album.id, { withAssets: false }, auth.user.id);
|
|
|
|
|
expect(mocks.access.album.checkSharedLinkAccess).toHaveBeenCalledWith(auth.sharedLink!.id, new Set([album.id]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@@ -607,7 +644,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
await sut.get(AuthFactory.create(user), album.id);
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.getById).toHaveBeenCalledWith(album.id, { withAssets: false });
|
|
|
|
|
expect(mocks.album.getById).toHaveBeenCalledWith(album.id, { withAssets: false }, user.id);
|
|
|
|
|
expect(mocks.access.album.checkSharedAlbumAccess).toHaveBeenCalledWith(
|
|
|
|
|
user.id,
|
|
|
|
|
new Set([album.id]),
|
|
|
|
@@ -631,7 +668,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
describe('addAssets', () => {
|
|
|
|
|
it('should allow the owner to add assets', async () => {
|
|
|
|
|
const owner = UserFactory.create({ isAdmin: true });
|
|
|
|
|
const album = AlbumFactory.from({ ownerId: owner.id }).owner(owner).build();
|
|
|
|
|
const album = AlbumFactory.from().owner(owner).build();
|
|
|
|
|
const [asset1, asset2, asset3] = [AssetFactory.create(), AssetFactory.create(), AssetFactory.create()];
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set([asset1.id, asset2.id, asset3.id]));
|
|
|
|
@@ -646,37 +683,47 @@ describe(AlbumService.name, () => {
|
|
|
|
|
{ success: true, id: asset3.id },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledWith(album.id, {
|
|
|
|
|
id: album.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
});
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledWith(
|
|
|
|
|
album.id,
|
|
|
|
|
{
|
|
|
|
|
id: album.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
},
|
|
|
|
|
owner.id,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.album.addAssetIds).toHaveBeenCalledWith(album.id, [asset1.id, asset2.id, asset3.id]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not set the thumbnail if the album has one already', async () => {
|
|
|
|
|
const [asset1, asset2] = [AssetFactory.create(), AssetFactory.create()];
|
|
|
|
|
const album = AlbumFactory.from({ albumThumbnailAssetId: asset1.id }).build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set([asset2.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.album.getAssetIds.mockResolvedValueOnce(new Set());
|
|
|
|
|
|
|
|
|
|
await expect(sut.addAssets(AuthFactory.create(album.owner), album.id, { ids: [asset2.id] })).resolves.toEqual([
|
|
|
|
|
await expect(sut.addAssets(AuthFactory.create(owner), album.id, { ids: [asset2.id] })).resolves.toEqual([
|
|
|
|
|
{ success: true, id: asset2.id },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledWith(album.id, {
|
|
|
|
|
id: album.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
});
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledWith(
|
|
|
|
|
album.id,
|
|
|
|
|
{
|
|
|
|
|
id: album.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
},
|
|
|
|
|
owner.id,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.album.addAssetIds).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should allow a shared user to add assets', async () => {
|
|
|
|
|
const user = UserFactory.create();
|
|
|
|
|
const album = AlbumFactory.from().albumUser({ userId: user.id, role: AlbumUserRole.Editor }).build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
const [asset1, asset2, asset3] = [AssetFactory.create(), AssetFactory.create(), AssetFactory.create()];
|
|
|
|
|
mocks.access.album.checkSharedAlbumAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set([asset1.id, asset2.id, asset3.id]));
|
|
|
|
@@ -691,15 +738,19 @@ describe(AlbumService.name, () => {
|
|
|
|
|
{ success: true, id: asset3.id },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledWith(album.id, {
|
|
|
|
|
id: album.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
});
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledWith(
|
|
|
|
|
album.id,
|
|
|
|
|
{
|
|
|
|
|
id: album.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
},
|
|
|
|
|
user.id,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.album.addAssetIds).toHaveBeenCalledWith(album.id, [asset1.id, asset2.id, asset3.id]);
|
|
|
|
|
expect(mocks.event.emit).toHaveBeenCalledWith('AlbumUpdate', {
|
|
|
|
|
id: album.id,
|
|
|
|
|
recipientId: album.ownerId,
|
|
|
|
|
recipientId: owner.id,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@@ -719,33 +770,39 @@ describe(AlbumService.name, () => {
|
|
|
|
|
|
|
|
|
|
it('should allow adding assets shared via partner sharing', async () => {
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
const asset = AssetFactory.create();
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.access.asset.checkPartnerAccess.mockResolvedValue(new Set([asset.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.album.getAssetIds.mockResolvedValueOnce(new Set());
|
|
|
|
|
|
|
|
|
|
await expect(sut.addAssets(AuthFactory.create(album.owner), album.id, { ids: [asset.id] })).resolves.toEqual([
|
|
|
|
|
await expect(sut.addAssets(AuthFactory.create(owner), album.id, { ids: [asset.id] })).resolves.toEqual([
|
|
|
|
|
{ success: true, id: asset.id },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledWith(album.id, {
|
|
|
|
|
id: album.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset.id,
|
|
|
|
|
});
|
|
|
|
|
expect(mocks.access.asset.checkPartnerAccess).toHaveBeenCalledWith(album.ownerId, new Set([asset.id]));
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledWith(
|
|
|
|
|
album.id,
|
|
|
|
|
{
|
|
|
|
|
id: album.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset.id,
|
|
|
|
|
},
|
|
|
|
|
owner.id,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.access.asset.checkPartnerAccess).toHaveBeenCalledWith(owner.id, new Set([asset.id]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should skip duplicate assets', async () => {
|
|
|
|
|
const asset = AssetFactory.create();
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set([asset.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.album.getAssetIds.mockResolvedValueOnce(new Set([asset.id]));
|
|
|
|
|
|
|
|
|
|
await expect(sut.addAssets(AuthFactory.create(album.owner), album.id, { ids: [asset.id] })).resolves.toEqual([
|
|
|
|
|
await expect(sut.addAssets(AuthFactory.create(owner), album.id, { ids: [asset.id] })).resolves.toEqual([
|
|
|
|
|
{ success: false, id: asset.id, error: BulkIdErrorReason.DUPLICATE },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
@@ -755,16 +812,17 @@ describe(AlbumService.name, () => {
|
|
|
|
|
it('should skip assets not shared with user', async () => {
|
|
|
|
|
const asset = AssetFactory.create();
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.album.getAssetIds.mockResolvedValueOnce(new Set());
|
|
|
|
|
|
|
|
|
|
await expect(sut.addAssets(AuthFactory.create(album.owner), album.id, { ids: [asset.id] })).resolves.toEqual([
|
|
|
|
|
await expect(sut.addAssets(AuthFactory.create(owner), album.id, { ids: [asset.id] })).resolves.toEqual([
|
|
|
|
|
{ success: false, id: asset.id, error: BulkIdErrorReason.NO_PERMISSION },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
expect(mocks.access.asset.checkOwnerAccess).toHaveBeenCalledWith(album.ownerId, new Set([asset.id]), false);
|
|
|
|
|
expect(mocks.access.asset.checkPartnerAccess).toHaveBeenCalledWith(album.ownerId, new Set([asset.id]));
|
|
|
|
|
expect(mocks.access.asset.checkOwnerAccess).toHaveBeenCalledWith(owner.id, new Set([asset.id]), false);
|
|
|
|
|
expect(mocks.access.asset.checkPartnerAccess).toHaveBeenCalledWith(owner.id, new Set([asset.id]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not allow unauthorized access to the album', async () => {
|
|
|
|
@@ -797,6 +855,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
describe('addAssetsToAlbums', () => {
|
|
|
|
|
it('should allow the owner to add assets', async () => {
|
|
|
|
|
const album1 = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album1.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
const album2 = AlbumFactory.create();
|
|
|
|
|
const [asset1, asset2, asset3] = [AssetFactory.create(), AssetFactory.create(), AssetFactory.create()];
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValueOnce(new Set([album1.id, album2.id]));
|
|
|
|
@@ -805,23 +864,33 @@ describe(AlbumService.name, () => {
|
|
|
|
|
mocks.album.getAssetIds.mockResolvedValueOnce(new Set()).mockResolvedValueOnce(new Set());
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
sut.addAssetsToAlbums(AuthFactory.create(album1.owner), {
|
|
|
|
|
sut.addAssetsToAlbums(AuthFactory.create(owner), {
|
|
|
|
|
albumIds: [album1.id, album2.id],
|
|
|
|
|
assetIds: [asset1.id, asset2.id, asset3.id],
|
|
|
|
|
}),
|
|
|
|
|
).resolves.toEqual({ success: true, error: undefined });
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledTimes(2);
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(1, album1.id, {
|
|
|
|
|
id: album1.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
});
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(2, album2.id, {
|
|
|
|
|
id: album2.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
});
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(
|
|
|
|
|
1,
|
|
|
|
|
album1.id,
|
|
|
|
|
{
|
|
|
|
|
id: album1.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
},
|
|
|
|
|
owner.id,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(
|
|
|
|
|
2,
|
|
|
|
|
album2.id,
|
|
|
|
|
{
|
|
|
|
|
id: album2.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
},
|
|
|
|
|
owner.id,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
|
|
|
|
|
{ albumId: album1.id, assetId: asset1.id },
|
|
|
|
|
{ albumId: album1.id, assetId: asset2.id },
|
|
|
|
@@ -835,6 +904,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
it('should not set the thumbnail if the album has one already', async () => {
|
|
|
|
|
const asset = AssetFactory.create();
|
|
|
|
|
const album1 = AlbumFactory.from({ albumThumbnailAssetId: asset.id }).build();
|
|
|
|
|
const { user: owner } = album1.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
const album2 = AlbumFactory.from({ albumThumbnailAssetId: asset.id }).build();
|
|
|
|
|
const [asset1, asset2, asset3] = [AssetFactory.create(), AssetFactory.create(), AssetFactory.create()];
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValueOnce(new Set([album1.id, album2.id]));
|
|
|
|
@@ -843,23 +913,33 @@ describe(AlbumService.name, () => {
|
|
|
|
|
mocks.album.getAssetIds.mockResolvedValueOnce(new Set()).mockResolvedValueOnce(new Set());
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
sut.addAssetsToAlbums(AuthFactory.create(album1.owner), {
|
|
|
|
|
sut.addAssetsToAlbums(AuthFactory.create(owner), {
|
|
|
|
|
albumIds: [album1.id, album2.id],
|
|
|
|
|
assetIds: [asset1.id, asset2.id, asset3.id],
|
|
|
|
|
}),
|
|
|
|
|
).resolves.toEqual({ success: true, error: undefined });
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledTimes(2);
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(1, album1.id, {
|
|
|
|
|
id: album1.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset.id,
|
|
|
|
|
});
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(2, album2.id, {
|
|
|
|
|
id: album2.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset.id,
|
|
|
|
|
});
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(
|
|
|
|
|
1,
|
|
|
|
|
album1.id,
|
|
|
|
|
{
|
|
|
|
|
id: album1.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset.id,
|
|
|
|
|
},
|
|
|
|
|
owner.id,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(
|
|
|
|
|
2,
|
|
|
|
|
album2.id,
|
|
|
|
|
{
|
|
|
|
|
id: album2.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset.id,
|
|
|
|
|
},
|
|
|
|
|
owner.id,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
|
|
|
|
|
{ albumId: album1.id, assetId: asset1.id },
|
|
|
|
|
{ albumId: album1.id, assetId: asset2.id },
|
|
|
|
@@ -873,7 +953,9 @@ describe(AlbumService.name, () => {
|
|
|
|
|
it('should allow a shared user to add assets', async () => {
|
|
|
|
|
const user = UserFactory.create();
|
|
|
|
|
const album1 = AlbumFactory.from().albumUser({ userId: user.id, role: AlbumUserRole.Editor }).build();
|
|
|
|
|
const { user: owner1 } = album1.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
const album2 = AlbumFactory.from().albumUser({ userId: user.id, role: AlbumUserRole.Editor }).build();
|
|
|
|
|
const { user: owner2 } = album2.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
const [asset1, asset2, asset3] = [AssetFactory.create(), AssetFactory.create(), AssetFactory.create()];
|
|
|
|
|
mocks.access.album.checkSharedAlbumAccess.mockResolvedValueOnce(new Set([album1.id, album2.id]));
|
|
|
|
|
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set([asset1.id, asset2.id, asset3.id]));
|
|
|
|
@@ -888,16 +970,26 @@ describe(AlbumService.name, () => {
|
|
|
|
|
).resolves.toEqual({ success: true, error: undefined });
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledTimes(2);
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(1, album1.id, {
|
|
|
|
|
id: album1.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
});
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(2, album2.id, {
|
|
|
|
|
id: album2.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
});
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(
|
|
|
|
|
1,
|
|
|
|
|
album1.id,
|
|
|
|
|
{
|
|
|
|
|
id: album1.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
},
|
|
|
|
|
user.id,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(
|
|
|
|
|
2,
|
|
|
|
|
album2.id,
|
|
|
|
|
{
|
|
|
|
|
id: album2.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
},
|
|
|
|
|
user.id,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
|
|
|
|
|
{ albumId: album1.id, assetId: asset1.id },
|
|
|
|
|
{ albumId: album1.id, assetId: asset2.id },
|
|
|
|
@@ -908,11 +1000,11 @@ describe(AlbumService.name, () => {
|
|
|
|
|
]);
|
|
|
|
|
expect(mocks.event.emit).toHaveBeenCalledWith('AlbumUpdate', {
|
|
|
|
|
id: album1.id,
|
|
|
|
|
recipientId: album1.ownerId,
|
|
|
|
|
recipientId: owner1.id,
|
|
|
|
|
});
|
|
|
|
|
expect(mocks.event.emit).toHaveBeenCalledWith('AlbumUpdate', {
|
|
|
|
|
id: album2.id,
|
|
|
|
|
recipientId: album2.ownerId,
|
|
|
|
|
recipientId: owner2.id,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@@ -942,6 +1034,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
it('should allow adding assets shared via partner sharing', async () => {
|
|
|
|
|
const user = UserFactory.create();
|
|
|
|
|
const album1 = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album1.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
const album2 = AlbumFactory.create();
|
|
|
|
|
const [asset1, asset2, asset3] = [
|
|
|
|
|
AssetFactory.create({ ownerId: user.id }),
|
|
|
|
@@ -954,23 +1047,33 @@ describe(AlbumService.name, () => {
|
|
|
|
|
mocks.album.getAssetIds.mockResolvedValueOnce(new Set()).mockResolvedValueOnce(new Set());
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
sut.addAssetsToAlbums(AuthFactory.create(album1.owner), {
|
|
|
|
|
sut.addAssetsToAlbums(AuthFactory.create(owner), {
|
|
|
|
|
albumIds: [album1.id, album2.id],
|
|
|
|
|
assetIds: [asset1.id, asset2.id, asset3.id],
|
|
|
|
|
}),
|
|
|
|
|
).resolves.toEqual({ success: true, error: undefined });
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledTimes(2);
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(1, album1.id, {
|
|
|
|
|
id: album1.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
});
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(2, album2.id, {
|
|
|
|
|
id: album2.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
});
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(
|
|
|
|
|
1,
|
|
|
|
|
album1.id,
|
|
|
|
|
{
|
|
|
|
|
id: album1.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
},
|
|
|
|
|
owner.id,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(
|
|
|
|
|
2,
|
|
|
|
|
album2.id,
|
|
|
|
|
{
|
|
|
|
|
id: album2.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
},
|
|
|
|
|
owner.id,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
|
|
|
|
|
{ albumId: album1.id, assetId: asset1.id },
|
|
|
|
|
{ albumId: album1.id, assetId: asset2.id },
|
|
|
|
@@ -980,7 +1083,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
{ albumId: album2.id, assetId: asset3.id },
|
|
|
|
|
]);
|
|
|
|
|
expect(mocks.access.asset.checkPartnerAccess).toHaveBeenCalledWith(
|
|
|
|
|
album1.ownerId,
|
|
|
|
|
owner.id,
|
|
|
|
|
new Set([asset1.id, asset2.id, asset3.id]),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
@@ -988,7 +1091,9 @@ describe(AlbumService.name, () => {
|
|
|
|
|
it('should skip some duplicate assets', async () => {
|
|
|
|
|
const [asset1, asset2, asset3] = [AssetFactory.create(), AssetFactory.create(), AssetFactory.create()];
|
|
|
|
|
const album1 = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album1.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
const album2 = AlbumFactory.create();
|
|
|
|
|
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValueOnce(new Set([album1.id, album2.id]));
|
|
|
|
|
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set([asset1.id, asset2.id, asset3.id]));
|
|
|
|
|
mocks.album.getAssetIds
|
|
|
|
@@ -997,18 +1102,23 @@ describe(AlbumService.name, () => {
|
|
|
|
|
mocks.album.getById.mockResolvedValueOnce(getForAlbum(album1)).mockResolvedValueOnce(getForAlbum(album2));
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
sut.addAssetsToAlbums(AuthFactory.create(album1.owner), {
|
|
|
|
|
sut.addAssetsToAlbums(AuthFactory.create(owner), {
|
|
|
|
|
albumIds: [album1.id, album2.id],
|
|
|
|
|
assetIds: [asset1.id, asset2.id, asset3.id],
|
|
|
|
|
}),
|
|
|
|
|
).resolves.toEqual({ success: true, error: undefined });
|
|
|
|
|
|
|
|
|
|
expect(mocks.album.update).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(1, album2.id, {
|
|
|
|
|
id: album2.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
});
|
|
|
|
|
expect(mocks.album.update).toHaveBeenNthCalledWith(
|
|
|
|
|
1,
|
|
|
|
|
album2.id,
|
|
|
|
|
{
|
|
|
|
|
id: album2.id,
|
|
|
|
|
updatedAt: expect.any(Date),
|
|
|
|
|
albumThumbnailAssetId: asset1.id,
|
|
|
|
|
},
|
|
|
|
|
owner.id,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
|
|
|
|
|
{ albumId: album2.id, assetId: asset1.id },
|
|
|
|
|
{ albumId: album2.id, assetId: asset2.id },
|
|
|
|
@@ -1019,6 +1129,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
it('should skip all duplicate assets', async () => {
|
|
|
|
|
const [asset1, asset2, asset3] = [AssetFactory.create(), AssetFactory.create(), AssetFactory.create()];
|
|
|
|
|
const album1 = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album1.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
const album2 = AlbumFactory.create();
|
|
|
|
|
mocks.access.album.checkOwnerAccess
|
|
|
|
|
.mockResolvedValueOnce(new Set([album1.id]))
|
|
|
|
@@ -1028,7 +1139,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
mocks.album.getAssetIds.mockResolvedValue(new Set([asset1.id, asset2.id, asset3.id]));
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
sut.addAssetsToAlbums(AuthFactory.create(album1.owner), {
|
|
|
|
|
sut.addAssetsToAlbums(AuthFactory.create(owner), {
|
|
|
|
|
albumIds: [album1.id, album2.id],
|
|
|
|
|
assetIds: [asset1.id, asset2.id, asset3.id],
|
|
|
|
|
}),
|
|
|
|
@@ -1044,6 +1155,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
it('should skip assets not shared with user', async () => {
|
|
|
|
|
const user = UserFactory.create();
|
|
|
|
|
const album1 = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album1.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
const album2 = AlbumFactory.create();
|
|
|
|
|
const [asset1, asset2, asset3] = [
|
|
|
|
|
AssetFactory.create({ ownerId: user.id }),
|
|
|
|
@@ -1057,7 +1169,7 @@ describe(AlbumService.name, () => {
|
|
|
|
|
mocks.album.getAssetIds.mockResolvedValueOnce(new Set()).mockResolvedValueOnce(new Set());
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
sut.addAssetsToAlbums(AuthFactory.create(album1.owner), {
|
|
|
|
|
sut.addAssetsToAlbums(AuthFactory.create(owner), {
|
|
|
|
|
albumIds: [album1.id, album2.id],
|
|
|
|
|
assetIds: [asset1.id, asset2.id, asset3.id],
|
|
|
|
|
}),
|
|
|
|
@@ -1069,12 +1181,12 @@ describe(AlbumService.name, () => {
|
|
|
|
|
expect(mocks.album.update).not.toHaveBeenCalled();
|
|
|
|
|
expect(mocks.album.addAssetIds).not.toHaveBeenCalled();
|
|
|
|
|
expect(mocks.access.asset.checkOwnerAccess).toHaveBeenCalledWith(
|
|
|
|
|
album1.ownerId,
|
|
|
|
|
owner.id,
|
|
|
|
|
new Set([asset1.id, asset2.id, asset3.id]),
|
|
|
|
|
false,
|
|
|
|
|
);
|
|
|
|
|
expect(mocks.access.asset.checkPartnerAccess).toHaveBeenCalledWith(
|
|
|
|
|
album1.ownerId,
|
|
|
|
|
owner.id,
|
|
|
|
|
new Set([asset1.id, asset2.id, asset3.id]),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
@@ -1126,12 +1238,13 @@ describe(AlbumService.name, () => {
|
|
|
|
|
it('should allow the owner to remove assets', async () => {
|
|
|
|
|
const asset = AssetFactory.create();
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set([asset.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.album.getAssetIds.mockResolvedValue(new Set([asset.id]));
|
|
|
|
|
|
|
|
|
|
await expect(sut.removeAssets(AuthFactory.create(album.owner), album.id, { ids: [asset.id] })).resolves.toEqual([
|
|
|
|
|
await expect(sut.removeAssets(AuthFactory.create(owner), album.id, { ids: [asset.id] })).resolves.toEqual([
|
|
|
|
|
{ success: true, id: asset.id },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
@@ -1141,11 +1254,12 @@ describe(AlbumService.name, () => {
|
|
|
|
|
it('should skip assets not in the album', async () => {
|
|
|
|
|
const asset = AssetFactory.create();
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.album.getAssetIds.mockResolvedValue(new Set());
|
|
|
|
|
|
|
|
|
|
await expect(sut.removeAssets(AuthFactory.create(album.owner), album.id, { ids: [asset.id] })).resolves.toEqual([
|
|
|
|
|
await expect(sut.removeAssets(AuthFactory.create(owner), album.id, { ids: [asset.id] })).resolves.toEqual([
|
|
|
|
|
{ success: false, id: asset.id, error: BulkIdErrorReason.NOT_FOUND },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
@@ -1155,11 +1269,12 @@ describe(AlbumService.name, () => {
|
|
|
|
|
it('should allow owner to remove all assets from the album', async () => {
|
|
|
|
|
const asset = AssetFactory.create();
|
|
|
|
|
const album = AlbumFactory.create();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.album.getAssetIds.mockResolvedValue(new Set([asset.id]));
|
|
|
|
|
|
|
|
|
|
await expect(sut.removeAssets(AuthFactory.create(album.owner), album.id, { ids: [asset.id] })).resolves.toEqual([
|
|
|
|
|
await expect(sut.removeAssets(AuthFactory.create(owner), album.id, { ids: [asset.id] })).resolves.toEqual([
|
|
|
|
|
{ success: true, id: asset.id },
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
@@ -1168,12 +1283,13 @@ describe(AlbumService.name, () => {
|
|
|
|
|
const asset1 = AssetFactory.create();
|
|
|
|
|
const asset2 = AssetFactory.create();
|
|
|
|
|
const album = AlbumFactory.from({ albumThumbnailAssetId: asset1.id }).build();
|
|
|
|
|
const { user: owner } = album.albumUsers.find(({ role }) => role === AlbumUserRole.Owner)!;
|
|
|
|
|
mocks.access.album.checkOwnerAccess.mockResolvedValue(new Set([album.id]));
|
|
|
|
|
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set([asset1.id]));
|
|
|
|
|
mocks.album.getById.mockResolvedValue(getForAlbum(album));
|
|
|
|
|
mocks.album.getAssetIds.mockResolvedValue(new Set([asset1.id, asset2.id]));
|
|
|
|
|
|
|
|
|
|
await expect(sut.removeAssets(AuthFactory.create(album.owner), album.id, { ids: [asset1.id] })).resolves.toEqual([
|
|
|
|
|
await expect(sut.removeAssets(AuthFactory.create(owner), album.id, { ids: [asset1.id] })).resolves.toEqual([
|
|
|
|
|
{ success: true, id: asset1.id },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|