diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9b0944ff4e..1d6c7772b9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,11 +2,12 @@ name: Test on: workflow_dispatch: pull_request: - push: { branches: master } + push: + branches: [main] jobs: - test-server-e2e: - name: Run test suite + e2e-tests: + name: Run end-to-end test suites runs-on: ubuntu-latest @@ -16,3 +17,13 @@ jobs: - name: Run Immich Server 2E2 Test run: docker-compose -f ./docker/docker-compose.test.yml --env-file ./docker/.env.test up --abort-on-container-exit --exit-code-from immich-server-test + + unit-tests: + name: Run unit test suites + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Run tests + run: cd server && npm install && npm run test \ No newline at end of file diff --git a/server/apps/immich/src/api-v1/album/album.service.spec.ts b/server/apps/immich/src/api-v1/album/album.service.spec.ts index 5fe331b3ba..c60ad62046 100644 --- a/server/apps/immich/src/api-v1/album/album.service.spec.ts +++ b/server/apps/immich/src/api-v1/album/album.service.spec.ts @@ -4,6 +4,7 @@ import { AuthUserDto } from '../../decorators/auth-user.decorator'; import { BadRequestException, NotFoundException, ForbiddenException } from '@nestjs/common'; import { AlbumEntity } from '@app/database/entities/album.entity'; import { AlbumResponseDto } from './response-dto/album-response.dto'; +import { AssetAlbumEntity } from '@app/database/entities/asset-album.entity'; describe('Album service', () => { let sut: AlbumService; @@ -12,7 +13,7 @@ describe('Album service', () => { id: '1111', email: 'auth@test.com', }); - const albumId = '0001'; + const albumId = 'f19ab956-4761-41ea-a5d6-bae948308d58'; const sharedAlbumOwnerId = '2222'; const sharedAlbumSharedAlsoWithId = '3333'; const ownedAlbumSharedWithId = '4444'; @@ -148,7 +149,7 @@ describe('Album service', () => { it('gets an owned album', async () => { const ownerId = authUser.id; - const albumId = '0001'; + const albumId = 'f19ab956-4761-41ea-a5d6-bae948308d58'; const albumEntity = _getOwnedAlbum(); albumRepositoryMock.get.mockImplementation(() => Promise.resolve(albumEntity)); @@ -157,11 +158,12 @@ describe('Album service', () => { albumName: 'name', albumThumbnailAssetId: null, createdAt: 'date', - id: '0001', + id: 'f19ab956-4761-41ea-a5d6-bae948308d58', ownerId, shared: false, assets: [], sharedUsers: [], + assetCount: 0, }; await expect(sut.getAlbumInfo(authUser, albumId)).resolves.toEqual(expectedResult); }); @@ -270,6 +272,7 @@ describe('Album service', () => { authUser, { albumName: updatedAlbumName, + albumThumbnailAssetId: updatedAlbumThumbnailAssetId, }, albumId, ); @@ -279,7 +282,7 @@ describe('Album service', () => { expect(albumRepositoryMock.updateAlbum).toHaveBeenCalledTimes(1); expect(albumRepositoryMock.updateAlbum).toHaveBeenCalledWith(albumEntity, { albumName: updatedAlbumName, - thumbnailAssetId: updatedAlbumThumbnailAssetId, + albumThumbnailAssetId: updatedAlbumThumbnailAssetId, }); }); @@ -366,14 +369,14 @@ describe('Album service', () => { sut.removeAssetsFromAlbum( authUser, { - assetIds: ['1'], + assetIds: ['f19ab956-4761-41ea-a5d6-bae948308d60'], }, albumEntity.id, ), ).resolves.toBeUndefined(); expect(albumRepositoryMock.removeAssets).toHaveBeenCalledTimes(1); expect(albumRepositoryMock.removeAssets).toHaveBeenCalledWith(albumEntity, { - assetIds: ['1'], + assetIds: ['f19ab956-4761-41ea-a5d6-bae948308d60'], }); }); @@ -414,4 +417,33 @@ describe('Album service', () => { ), ).rejects.toBeInstanceOf(ForbiddenException); }); + + it('counts assets correctly', async () => { + const albumEntity = new AlbumEntity(); + + albumEntity.ownerId = authUser.id; + albumEntity.id = albumId; + albumEntity.albumName = 'name'; + albumEntity.createdAt = 'date'; + albumEntity.sharedUsers = []; + albumEntity.assets = [ + { + id: '1', + albumId: '2', + assetId: '3', + //@ts-expect-error Partial stub + albumInfo: {}, + //@ts-expect-error Partial stub + assetInfo: {}, + }, + ]; + albumEntity.albumThumbnailAssetId = null; + + albumRepositoryMock.getList.mockImplementation(() => Promise.resolve([albumEntity])); + + const result = await sut.getAllAlbums(authUser, {}); + + expect(result).toHaveLength(1); + expect(result[0].assetCount).toEqual(1); + }); });