refactor(server): use helpers for shared link queries (#27088)

* fix(server): prevent album shared link from breaking after uploads

* update test

* add withSharedAssets helper

* remove options

* add more helpers

* update selects
This commit is contained in:
Michel Heusschen
2026-03-26 18:51:00 +01:00
committed by GitHub
parent 1bd2d474d7
commit 144a57ddff
3 changed files with 212 additions and 153 deletions
@@ -372,6 +372,43 @@ describe(SharedLinkService.name, () => {
});
describe('get', () => {
it('should return an album shared link with assets', async () => {
const { sut, ctx } = setup();
const { user } = await ctx.newUser();
const auth = factory.auth({ user });
const { album } = await ctx.newAlbum({ ownerId: user.id });
const [{ asset: asset1 }, { asset: asset2 }] = await Promise.all([
ctx.newAsset({ ownerId: user.id }),
ctx.newAsset({ ownerId: user.id }),
]);
await Promise.all([
ctx.newExif({ assetId: asset1.id, make: 'Canon' }),
ctx.newExif({ assetId: asset2.id, make: 'Canon' }),
]);
const sharedLinkRepo = ctx.get(SharedLinkRepository);
const sharedLink = await sharedLinkRepo.create({
key: randomBytes(16),
id: factory.uuid(),
userId: user.id,
albumId: album.id,
allowUpload: true,
type: SharedLinkType.Album,
});
await sharedLinkRepo.addAssets(sharedLink.id, [asset1.id, asset2.id]);
const result = await sut.get(auth, sharedLink.id);
const assetIds = result.assets.map((asset) => asset.id);
expect(result).toMatchObject({
id: sharedLink.id,
album: expect.objectContaining({ id: album.id }),
});
expect(assetIds).toHaveLength(2);
expect(assetIds).toEqual(expect.arrayContaining([asset1.id, asset2.id]));
});
it('should not return trashed assets for an individual shared link', async () => {
const { sut, ctx } = setup();
const { user } = await ctx.newUser();