1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-28 22:51:59 +00:00

Added test and github action for unit tests

This commit is contained in:
Alex Tran 2022-08-11 08:27:44 -05:00
parent 5c78f707fe
commit b6d3e578f2
No known key found for this signature in database
GPG key ID: E4954BC787B85C8A
2 changed files with 52 additions and 9 deletions

View file

@ -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

View file

@ -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>(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);
});
});