2022-08-27 07:53:37 +02:00
|
|
|
import { AssetRepository, IAssetRepository } from './asset-repository';
|
|
|
|
import { AuthUserDto } from '../../decorators/auth-user.decorator';
|
|
|
|
import { AssetService } from './asset.service';
|
|
|
|
import { Repository } from 'typeorm';
|
|
|
|
import { AssetEntity, AssetType } from '@app/database/entities/asset.entity';
|
|
|
|
import { CreateAssetDto } from './dto/create-asset.dto';
|
|
|
|
|
|
|
|
describe('AssetService', () => {
|
|
|
|
let sui: AssetService;
|
|
|
|
let a: Repository<AssetEntity>; // TO BE DELETED AFTER FINISHED REFACTORING
|
|
|
|
let assetRepositoryMock: jest.Mocked<IAssetRepository>;
|
|
|
|
|
|
|
|
const authUser: AuthUserDto = Object.freeze({
|
|
|
|
id: '3ea54709-e168-42b7-90b0-a0dfe8a7ecbd',
|
|
|
|
email: 'auth@test.com',
|
|
|
|
});
|
|
|
|
|
|
|
|
const _getCreateAssetDto = (): CreateAssetDto => {
|
|
|
|
const createAssetDto = new CreateAssetDto();
|
|
|
|
createAssetDto.deviceAssetId = 'deviceAssetId';
|
|
|
|
createAssetDto.deviceId = 'deviceId';
|
|
|
|
createAssetDto.assetType = AssetType.OTHER;
|
|
|
|
createAssetDto.createdAt = '2022-06-19T23:41:36.910Z';
|
|
|
|
createAssetDto.modifiedAt = '2022-06-19T23:41:36.910Z';
|
|
|
|
createAssetDto.isFavorite = false;
|
|
|
|
createAssetDto.duration = '0:00:00.000000';
|
|
|
|
|
|
|
|
return createAssetDto;
|
|
|
|
};
|
|
|
|
const _getAsset = () => {
|
|
|
|
const assetEntity = new AssetEntity();
|
|
|
|
|
|
|
|
assetEntity.id = 'e8edabfd-7d8a-45d0-9d61-7c7ca60f2c67';
|
|
|
|
assetEntity.userId = '3ea54709-e168-42b7-90b0-a0dfe8a7ecbd';
|
|
|
|
assetEntity.deviceAssetId = '4967046344801';
|
|
|
|
assetEntity.deviceId = '116766fd-2ef2-52dc-a3ef-149988997291';
|
|
|
|
assetEntity.type = AssetType.VIDEO;
|
|
|
|
assetEntity.originalPath =
|
|
|
|
'upload/3ea54709-e168-42b7-90b0-a0dfe8a7ecbd/original/116766fd-2ef2-52dc-a3ef-149988997291/51c97f95-244f-462d-bdf0-e1dc19913516.jpg';
|
|
|
|
assetEntity.resizePath = '';
|
|
|
|
assetEntity.createdAt = '2022-06-19T23:41:36.910Z';
|
|
|
|
assetEntity.modifiedAt = '2022-06-19T23:41:36.910Z';
|
|
|
|
assetEntity.isFavorite = false;
|
|
|
|
assetEntity.mimeType = 'image/jpeg';
|
|
|
|
assetEntity.webpPath = '';
|
|
|
|
assetEntity.encodedVideoPath = '';
|
|
|
|
assetEntity.duration = '0:00:00.000000';
|
|
|
|
|
|
|
|
return assetEntity;
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
assetRepositoryMock = {
|
|
|
|
create: jest.fn(),
|
|
|
|
getAllByUserId: jest.fn(),
|
|
|
|
getAllByDeviceId: jest.fn(),
|
2022-09-04 15:34:39 +02:00
|
|
|
getAssetCountByTimeBucket: jest.fn(),
|
2022-08-27 07:53:37 +02:00
|
|
|
getById: jest.fn(),
|
|
|
|
getDetectedObjectsByUserId: jest.fn(),
|
|
|
|
getLocationsByUserId: jest.fn(),
|
|
|
|
getSearchPropertiesByUserId: jest.fn(),
|
2022-09-04 15:34:39 +02:00
|
|
|
getAssetByTimeBucket: jest.fn(),
|
2022-09-05 21:45:38 +02:00
|
|
|
getAssetByChecksum: jest.fn(),
|
2022-09-07 22:16:18 +02:00
|
|
|
getAssetCountByUserId: jest.fn(),
|
2022-08-27 07:53:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
sui = new AssetService(assetRepositoryMock, a);
|
|
|
|
});
|
|
|
|
|
2022-09-04 15:34:39 +02:00
|
|
|
// Currently failing due to calculate checksum from a file
|
|
|
|
// it('create an asset', async () => {
|
|
|
|
// const assetEntity = _getAsset();
|
2022-08-27 07:53:37 +02:00
|
|
|
|
2022-09-04 15:34:39 +02:00
|
|
|
// assetRepositoryMock.create.mockImplementation(() => Promise.resolve<AssetEntity>(assetEntity));
|
2022-08-27 07:53:37 +02:00
|
|
|
|
2022-09-04 15:34:39 +02:00
|
|
|
// const originalPath =
|
|
|
|
// 'upload/3ea54709-e168-42b7-90b0-a0dfe8a7ecbd/original/116766fd-2ef2-52dc-a3ef-149988997291/51c97f95-244f-462d-bdf0-e1dc19913516.jpg';
|
|
|
|
// const mimeType = 'image/jpeg';
|
|
|
|
// const createAssetDto = _getCreateAssetDto();
|
|
|
|
// const result = await sui.createUserAsset(authUser, createAssetDto, originalPath, mimeType);
|
2022-08-27 07:53:37 +02:00
|
|
|
|
2022-09-04 15:34:39 +02:00
|
|
|
// expect(result.userId).toEqual(authUser.id);
|
|
|
|
// expect(result.resizePath).toEqual('');
|
|
|
|
// expect(result.webpPath).toEqual('');
|
|
|
|
// });
|
2022-08-27 07:53:37 +02:00
|
|
|
|
|
|
|
it('get assets by device id', async () => {
|
|
|
|
assetRepositoryMock.getAllByDeviceId.mockImplementation(() => Promise.resolve<string[]>(['4967046344801']));
|
|
|
|
|
|
|
|
const deviceId = '116766fd-2ef2-52dc-a3ef-149988997291';
|
|
|
|
const result = await sui.getUserAssetsByDeviceId(authUser, deviceId);
|
|
|
|
|
|
|
|
expect(result.length).toEqual(1);
|
|
|
|
expect(result[0]).toEqual('4967046344801');
|
|
|
|
});
|
|
|
|
});
|