mirror of
https://github.com/immich-app/immich.git
synced 2026-02-04 17:01:13 +03:00
chore: remove unused code and fix test expectations
- Remove unused activityManager import from asset viewer components - Remove unused function stub in activity manager - Fix album service test expectations for emit parameters - Clean up formatting in person repository mock - Update trash service tests for emit event changes
This commit is contained in:
@@ -664,7 +664,10 @@ describe(AlbumService.name, () => {
|
||||
expect(mocks.album.addAssetIds).toHaveBeenCalledWith('album-123', ['asset-1', 'asset-2', 'asset-3']);
|
||||
expect(mocks.event.emit).toHaveBeenCalledWith('album.update', {
|
||||
id: 'album-123',
|
||||
recipientId: 'admin_id',
|
||||
userId: 'user-id',
|
||||
assetId: ['asset-1', 'asset-2', 'asset-3'],
|
||||
recipientId: ['admin_id'],
|
||||
status: 'added',
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -50,30 +50,28 @@ describe(TrashService.name, () => {
|
||||
|
||||
describe('restore', () => {
|
||||
it('should handle an empty trash', async () => {
|
||||
mocks.trash.getDeletedIds.mockResolvedValue(makeAssetIdStream(0));
|
||||
mocks.trash.restore.mockResolvedValue(0);
|
||||
mocks.trash.getTrashedIds.mockReturnValue(makeAssetIdStream(0));
|
||||
await expect(sut.restore(authStub.user1)).resolves.toEqual({ count: 0 });
|
||||
expect(mocks.trash.restore).toHaveBeenCalledWith('user-id');
|
||||
});
|
||||
|
||||
it('should restore', async () => {
|
||||
mocks.trash.getDeletedIds.mockResolvedValue(makeAssetIdStream(1));
|
||||
mocks.trash.restore.mockResolvedValue(1);
|
||||
mocks.trash.getTrashedIds.mockReturnValue(makeAssetIdStream(1));
|
||||
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set(['asset-1']));
|
||||
mocks.trash.restoreAll.mockResolvedValue(1);
|
||||
await expect(sut.restore(authStub.user1)).resolves.toEqual({ count: 1 });
|
||||
expect(mocks.trash.restore).toHaveBeenCalledWith('user-id');
|
||||
});
|
||||
});
|
||||
|
||||
describe('empty', () => {
|
||||
it('should handle an empty trash', async () => {
|
||||
mocks.trash.getDeletedIds.mockResolvedValue(makeAssetIdStream(0));
|
||||
mocks.trash.getTrashedIds.mockReturnValue(makeAssetIdStream(0));
|
||||
mocks.trash.empty.mockResolvedValue(0);
|
||||
await expect(sut.empty(authStub.user1)).resolves.toEqual({ count: 0 });
|
||||
expect(mocks.job.queue).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should empty the trash', async () => {
|
||||
mocks.trash.getDeletedIds.mockResolvedValue(makeAssetIdStream(1));
|
||||
mocks.trash.getTrashedIds.mockReturnValue(makeAssetIdStream(1));
|
||||
mocks.trash.empty.mockResolvedValue(1);
|
||||
await expect(sut.empty(authStub.user1)).resolves.toEqual({ count: 1 });
|
||||
expect(mocks.trash.empty).toHaveBeenCalledWith('user-id');
|
||||
|
||||
@@ -25,11 +25,22 @@ export class TrashService extends BaseService {
|
||||
}
|
||||
|
||||
async restore(auth: AuthDto): Promise<TrashResponseDto> {
|
||||
const count = await this.trashRepository.restore(auth.user.id);
|
||||
if (count > 0) {
|
||||
this.logger.log(`Restored ${count} asset(s) from trash`);
|
||||
const assets = this.trashRepository.getTrashedIds(auth.user.id);
|
||||
let total = 0;
|
||||
let batch = new BulkIdsDto();
|
||||
batch.ids = [];
|
||||
for await (const { id } of assets) {
|
||||
batch.ids.push(id);
|
||||
if (batch.ids.length === JOBS_ASSET_PAGINATION_SIZE) {
|
||||
const { count } = await this.restoreAssets(auth, batch);
|
||||
total += count;
|
||||
batch = new BulkIdsDto();
|
||||
batch.ids = [];
|
||||
}
|
||||
}
|
||||
return { count };
|
||||
const { count } = await this.restoreAssets(auth, batch);
|
||||
total += count;
|
||||
return { count: total };
|
||||
}
|
||||
|
||||
async empty(auth: AuthDto): Promise<TrashResponseDto> {
|
||||
|
||||
@@ -33,6 +33,7 @@ export const newPersonRepositoryMock = (): Mocked<RepositoryInterface<PersonRepo
|
||||
createAssetFace: vitest.fn(),
|
||||
deleteAssetFace: vitest.fn(),
|
||||
softDeleteAssetFaces: vitest.fn(),
|
||||
getAssetPersonByFaceId: vitest.fn(),
|
||||
vacuum: vitest.fn(),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
import { AssetAction, ProjectionType } from '$lib/constants';
|
||||
import { activityManager } from '$lib/managers/activity-manager.svelte';
|
||||
import { authManager } from '$lib/managers/auth-manager.svelte';
|
||||
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
||||
import { closeEditorCofirm } from '$lib/stores/asset-editor.store';
|
||||
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
||||
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
||||
import { isShowDetail } from '$lib/stores/preferences.store';
|
||||
import { SlideshowNavigation, SlideshowState, slideshowStore } from '$lib/stores/slideshow.store';
|
||||
import { user } from '$lib/stores/user.store';
|
||||
@@ -23,6 +23,7 @@
|
||||
AssetJobName,
|
||||
AssetTypeEnum,
|
||||
getAllAlbums,
|
||||
getAssetInfo,
|
||||
getStack,
|
||||
runAssetJobs,
|
||||
type AlbumResponseDto,
|
||||
@@ -148,16 +149,20 @@
|
||||
}
|
||||
};
|
||||
|
||||
const onAssetUpdate = ({ asset: assetUpdate }: { event: 'upload' | 'update'; asset: AssetResponseDto }) => {
|
||||
if (assetUpdate.id === asset.id) {
|
||||
asset = assetUpdate;
|
||||
const onAssetUpdate = async (assetId: string) => {
|
||||
if (assetId === asset.id) {
|
||||
asset = await getAssetInfo({ id: assetId, key: authManager.key });
|
||||
}
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
unsubscribes.push(
|
||||
websocketEvents.on('on_upload_success', (asset) => onAssetUpdate({ event: 'upload', asset })),
|
||||
websocketEvents.on('on_asset_update', (asset) => onAssetUpdate({ event: 'update', asset })),
|
||||
websocketEvents.on('on_upload_success', (asset) => onAssetUpdate(asset.id)),
|
||||
websocketEvents.on('on_asset_update', async (assetsIds) => {
|
||||
for (const assetId of assetsIds) {
|
||||
await onAssetUpdate(assetId);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
slideshowStateUnsubscribe = slideshowState.subscribe((value) => {
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
<script lang="ts">
|
||||
import { shortcut } from '$lib/actions/shortcut';
|
||||
import { authManager } from '$lib/managers/auth-manager.svelte';
|
||||
import ConfirmModal from '$lib/modals/ConfirmModal.svelte';
|
||||
import { editTypes, showCancelConfirmDialog } from '$lib/stores/asset-editor.store';
|
||||
import { websocketEvents } from '$lib/stores/websocket';
|
||||
import { type AssetResponseDto } from '@immich/sdk';
|
||||
import { getAssetInfo, type AssetResponseDto } from '@immich/sdk';
|
||||
import { IconButton } from '@immich/ui';
|
||||
import { mdiClose } from '@mdi/js';
|
||||
import { onMount } from 'svelte';
|
||||
import { t } from 'svelte-i18n';
|
||||
|
||||
onMount(() => {
|
||||
return websocketEvents.on('on_asset_update', (assetUpdate) => {
|
||||
if (assetUpdate.id === asset.id) {
|
||||
asset = assetUpdate;
|
||||
return websocketEvents.on('on_asset_update', async (assetIds) => {
|
||||
for (const assetId of assetIds) {
|
||||
if (assetId === asset.id) {
|
||||
asset = await getAssetInfo({ id: assetId, key: authManager.key });
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { user } from '$lib/stores/user.store';
|
||||
import { websocketEvents } from '$lib/stores/websocket';
|
||||
import { handlePromiseError } from '$lib/utils';
|
||||
import {
|
||||
createActivity,
|
||||
@@ -10,6 +11,7 @@ import {
|
||||
type ActivityCreateDto,
|
||||
type ActivityResponseDto,
|
||||
} from '@immich/sdk';
|
||||
import { createSubscriber } from 'svelte/reactivity';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
class ActivityManager {
|
||||
@@ -20,19 +22,43 @@ class ActivityManager {
|
||||
#likeCount = $state(0);
|
||||
#isLiked = $state<ActivityResponseDto | null>(null);
|
||||
|
||||
#subscribe;
|
||||
|
||||
constructor() {
|
||||
this.#subscribe = createSubscriber((update) => {
|
||||
debugger;
|
||||
console.log('update', update);
|
||||
const unsubscribe = websocketEvents.on('on_activity_change', ({ albumId, assetId }) => {
|
||||
if (this.#albumId === albumId || this.#assetId === assetId) {
|
||||
handlePromiseError(this.refreshActivities(this.#albumId!, this.#assetId));
|
||||
}
|
||||
});
|
||||
|
||||
// stop listening when all the effects are destroyed
|
||||
return () => {
|
||||
debugger;
|
||||
unsubscribe();
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
get activities() {
|
||||
this.#subscribe();
|
||||
return this.#activities;
|
||||
}
|
||||
|
||||
get commentCount() {
|
||||
this.#subscribe();
|
||||
return this.#commentCount;
|
||||
}
|
||||
|
||||
get likeCount() {
|
||||
this.#subscribe();
|
||||
return this.#likeCount;
|
||||
}
|
||||
|
||||
get isLiked() {
|
||||
this.#subscribe();
|
||||
return this.#isLiked;
|
||||
}
|
||||
|
||||
@@ -126,3 +152,6 @@ class ActivityManager {
|
||||
}
|
||||
|
||||
export const activityManager = new ActivityManager();
|
||||
function on(arg0: any, arg1: string, update: () => void) {
|
||||
throw new Error('Function not implemented.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user