2023-11-17 00:44:59 -05:00
|
|
|
import { IJobRepository, ILibraryRepository, JobName } from '@app/domain';
|
2023-09-20 13:16:33 +02:00
|
|
|
import { ASSET_CHECKSUM_CONSTRAINT, AssetEntity, AssetType, ExifEntity } from '@app/infra/entities';
|
2023-07-14 21:31:42 -04:00
|
|
|
import { BadRequestException } from '@nestjs/common';
|
2023-02-25 09:12:03 -05:00
|
|
|
import {
|
2023-09-04 15:45:59 -04:00
|
|
|
IAccessRepositoryMock,
|
2023-07-31 21:28:07 -04:00
|
|
|
assetStub,
|
2023-01-25 11:35:28 -05:00
|
|
|
authStub,
|
2023-02-25 09:12:03 -05:00
|
|
|
fileStub,
|
2023-06-06 16:18:38 -04:00
|
|
|
newAccessRepositoryMock,
|
2023-01-25 11:35:28 -05:00
|
|
|
newJobRepositoryMock,
|
2023-09-20 13:16:33 +02:00
|
|
|
newLibraryRepositoryMock,
|
2023-06-08 11:01:07 -04:00
|
|
|
} from '@test';
|
2023-02-25 09:12:03 -05:00
|
|
|
import { when } from 'jest-when';
|
2023-11-16 23:24:31 -05:00
|
|
|
import { QueryFailedError } from 'typeorm';
|
2023-06-16 15:54:17 -04:00
|
|
|
import { IAssetRepository } from './asset-repository';
|
|
|
|
|
import { AssetService } from './asset.service';
|
|
|
|
|
import { CreateAssetDto } from './dto/create-asset.dto';
|
2023-05-27 21:56:17 -04:00
|
|
|
import { AssetRejectReason, AssetUploadAction } from './response-dto/asset-check-response.dto';
|
2022-08-26 22:53:37 -07:00
|
|
|
|
2023-01-30 11:14:13 -05:00
|
|
|
const _getCreateAssetDto = (): CreateAssetDto => {
|
|
|
|
|
const createAssetDto = new CreateAssetDto();
|
|
|
|
|
createAssetDto.deviceAssetId = 'deviceAssetId';
|
|
|
|
|
createAssetDto.deviceId = 'deviceId';
|
2023-05-29 16:05:14 +02:00
|
|
|
createAssetDto.fileCreatedAt = new Date('2022-06-19T23:41:36.910Z');
|
|
|
|
|
createAssetDto.fileModifiedAt = new Date('2022-06-19T23:41:36.910Z');
|
2023-01-30 11:14:13 -05:00
|
|
|
createAssetDto.isFavorite = false;
|
2023-04-12 18:37:52 +03:00
|
|
|
createAssetDto.isArchived = false;
|
2023-01-30 11:14:13 -05:00
|
|
|
createAssetDto.duration = '0:00:00.000000';
|
2023-09-20 13:16:33 +02:00
|
|
|
createAssetDto.libraryId = 'libraryId';
|
2023-01-30 11:14:13 -05:00
|
|
|
|
|
|
|
|
return createAssetDto;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const _getAsset_1 = () => {
|
|
|
|
|
const asset_1 = new AssetEntity();
|
|
|
|
|
|
|
|
|
|
asset_1.id = 'id_1';
|
2023-02-19 16:44:53 +00:00
|
|
|
asset_1.ownerId = 'user_id_1';
|
2023-01-30 11:14:13 -05:00
|
|
|
asset_1.deviceAssetId = 'device_asset_id_1';
|
|
|
|
|
asset_1.deviceId = 'device_id_1';
|
|
|
|
|
asset_1.type = AssetType.VIDEO;
|
|
|
|
|
asset_1.originalPath = 'fake_path/asset_1.jpeg';
|
|
|
|
|
asset_1.resizePath = '';
|
2023-05-29 16:05:14 +02:00
|
|
|
asset_1.fileModifiedAt = new Date('2022-06-19T23:41:36.910Z');
|
|
|
|
|
asset_1.fileCreatedAt = new Date('2022-06-19T23:41:36.910Z');
|
|
|
|
|
asset_1.updatedAt = new Date('2022-06-19T23:41:36.910Z');
|
2023-01-30 11:14:13 -05:00
|
|
|
asset_1.isFavorite = false;
|
2023-04-12 18:37:52 +03:00
|
|
|
asset_1.isArchived = false;
|
2023-01-30 11:14:13 -05:00
|
|
|
asset_1.webpPath = '';
|
|
|
|
|
asset_1.encodedVideoPath = '';
|
|
|
|
|
asset_1.duration = '0:00:00.000000';
|
2023-05-06 03:33:30 +02:00
|
|
|
asset_1.exifInfo = new ExifEntity();
|
|
|
|
|
asset_1.exifInfo.latitude = 49.533547;
|
|
|
|
|
asset_1.exifInfo.longitude = 10.703075;
|
2023-01-30 11:14:13 -05:00
|
|
|
return asset_1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const _getAsset_2 = () => {
|
|
|
|
|
const asset_2 = new AssetEntity();
|
|
|
|
|
|
|
|
|
|
asset_2.id = 'id_2';
|
2023-02-19 16:44:53 +00:00
|
|
|
asset_2.ownerId = 'user_id_1';
|
2023-01-30 11:14:13 -05:00
|
|
|
asset_2.deviceAssetId = 'device_asset_id_2';
|
|
|
|
|
asset_2.deviceId = 'device_id_1';
|
|
|
|
|
asset_2.type = AssetType.VIDEO;
|
|
|
|
|
asset_2.originalPath = 'fake_path/asset_2.jpeg';
|
|
|
|
|
asset_2.resizePath = '';
|
2023-05-29 16:05:14 +02:00
|
|
|
asset_2.fileModifiedAt = new Date('2022-06-19T23:41:36.910Z');
|
|
|
|
|
asset_2.fileCreatedAt = new Date('2022-06-19T23:41:36.910Z');
|
|
|
|
|
asset_2.updatedAt = new Date('2022-06-19T23:41:36.910Z');
|
2023-01-30 11:14:13 -05:00
|
|
|
asset_2.isFavorite = false;
|
2023-04-12 18:37:52 +03:00
|
|
|
asset_2.isArchived = false;
|
2023-01-30 11:14:13 -05:00
|
|
|
asset_2.webpPath = '';
|
|
|
|
|
asset_2.encodedVideoPath = '';
|
|
|
|
|
asset_2.duration = '0:00:00.000000';
|
|
|
|
|
|
|
|
|
|
return asset_2;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const _getAssets = () => {
|
|
|
|
|
return [_getAsset_1(), _getAsset_2()];
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-26 22:53:37 -07:00
|
|
|
describe('AssetService', () => {
|
2023-01-30 11:14:13 -05:00
|
|
|
let sut: AssetService;
|
2023-06-28 09:56:24 -04:00
|
|
|
let accessMock: IAccessRepositoryMock;
|
2022-08-26 22:53:37 -07:00
|
|
|
let assetRepositoryMock: jest.Mocked<IAssetRepository>;
|
2023-01-21 23:13:36 -05:00
|
|
|
let jobMock: jest.Mocked<IJobRepository>;
|
2023-09-20 13:16:33 +02:00
|
|
|
let libraryMock: jest.Mocked<ILibraryRepository>;
|
2022-08-26 22:53:37 -07:00
|
|
|
|
2023-01-30 11:14:13 -05:00
|
|
|
beforeEach(() => {
|
2022-08-26 22:53:37 -07:00
|
|
|
assetRepositoryMock = {
|
2023-01-30 11:14:13 -05:00
|
|
|
get: jest.fn(),
|
2022-08-26 22:53:37 -07:00
|
|
|
create: jest.fn(),
|
2023-01-30 11:14:13 -05:00
|
|
|
|
2022-08-26 22:53:37 -07:00
|
|
|
getAllByUserId: jest.fn(),
|
|
|
|
|
getAllByDeviceId: jest.fn(),
|
|
|
|
|
getById: jest.fn(),
|
|
|
|
|
getDetectedObjectsByUserId: jest.fn(),
|
|
|
|
|
getLocationsByUserId: jest.fn(),
|
|
|
|
|
getSearchPropertiesByUserId: jest.fn(),
|
2023-05-24 23:08:21 +02:00
|
|
|
getAssetsByChecksums: jest.fn(),
|
2022-10-25 09:51:03 -05:00
|
|
|
getExistingAssets: jest.fn(),
|
feat(server): support for read-only assets and importing existing items in the filesystem (#2715)
* Added read-only flag for assets, endpoint to trigger file import vs upload
* updated fixtures with new property
* if upload is 'read-only', ensure there is no existing asset at the designated originalPath
* added test for file import as well as detecting existing image at read-only destination location
* Added storage service test for a case where it should not move read-only assets
* upload doesn't need the read-only flag available, just importing
* default isReadOnly on import endpoint to true
* formatting fixes
* create-asset dto needs isReadOnly, so set it to false by default on create, updated api generation
* updated code to reflect changes in MR
* fixed read stream promise return type
* new index for originalPath, check for existing path on import, reglardless of user, to prevent duplicates
* refactor: import asset
* chore: open api
* chore: tests
* Added externalPath support for individual users, updated UI to allow this to be set by admin
* added missing var for externalPath in ui
* chore: open api
* fix: compilation issues
* fix: server test
* built api, fixed user-response dto to include externalPath
* reverted accidental commit
* bad commit of duplicate externalPath in user response dto
* fixed tests to include externalPath on expected result
* fix: unit tests
* centralized supported filetypes, perform file type checking of asset and sidecar during file import process
* centralized supported filetype check method to keep regex DRY
* fixed typo
* combined migrations into one
* update api
* Removed externalPath from shared-link code, added column to admin user page whether external paths / import is enabled or not
* update mimetype
* Fixed detect correct mimetype
* revert asset-upload config
* reverted domain.constant
* refactor
* fix mime-type issue
* fix format
---------
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2023-06-21 22:33:20 -04:00
|
|
|
getByOriginalPath: jest.fn(),
|
2022-08-26 22:53:37 -07:00
|
|
|
};
|
|
|
|
|
|
2023-06-06 16:18:38 -04:00
|
|
|
accessMock = newAccessRepositoryMock();
|
2023-01-21 23:13:36 -05:00
|
|
|
jobMock = newJobRepositoryMock();
|
2023-09-20 13:16:33 +02:00
|
|
|
libraryMock = newLibraryRepositoryMock();
|
2023-01-21 23:13:36 -05:00
|
|
|
|
2023-11-17 00:44:59 -05:00
|
|
|
sut = new AssetService(accessMock, assetRepositoryMock, jobMock, libraryMock);
|
2023-02-25 09:12:03 -05:00
|
|
|
|
|
|
|
|
when(assetRepositoryMock.get)
|
2023-07-31 21:28:07 -04:00
|
|
|
.calledWith(assetStub.livePhotoStillAsset.id)
|
|
|
|
|
.mockResolvedValue(assetStub.livePhotoStillAsset);
|
2023-02-25 09:12:03 -05:00
|
|
|
when(assetRepositoryMock.get)
|
2023-07-31 21:28:07 -04:00
|
|
|
.calledWith(assetStub.livePhotoMotionAsset.id)
|
|
|
|
|
.mockResolvedValue(assetStub.livePhotoMotionAsset);
|
2022-08-26 22:53:37 -07:00
|
|
|
});
|
|
|
|
|
|
2023-01-30 11:14:13 -05:00
|
|
|
describe('uploadFile', () => {
|
|
|
|
|
it('should handle a file upload', async () => {
|
|
|
|
|
const assetEntity = _getAsset_1();
|
|
|
|
|
const file = {
|
|
|
|
|
originalPath: 'fake_path/asset_1.jpeg',
|
|
|
|
|
mimeType: 'image/jpeg',
|
|
|
|
|
checksum: Buffer.from('file hash', 'utf8'),
|
|
|
|
|
originalName: 'asset_1.jpeg',
|
|
|
|
|
};
|
|
|
|
|
const dto = _getCreateAssetDto();
|
|
|
|
|
|
2023-02-25 09:12:03 -05:00
|
|
|
assetRepositoryMock.create.mockResolvedValue(assetEntity);
|
2023-09-24 15:19:36 +02:00
|
|
|
accessMock.library.hasOwnerAccess.mockResolvedValue(true);
|
2023-01-30 11:14:13 -05:00
|
|
|
|
|
|
|
|
await expect(sut.uploadFile(authStub.user1, dto, file)).resolves.toEqual({ duplicate: false, id: 'id_1' });
|
2023-02-25 09:12:03 -05:00
|
|
|
|
|
|
|
|
expect(assetRepositoryMock.create).toHaveBeenCalled();
|
2023-01-30 11:14:13 -05:00
|
|
|
});
|
2022-08-26 22:53:37 -07:00
|
|
|
|
2023-01-30 11:14:13 -05:00
|
|
|
it('should handle a duplicate', async () => {
|
|
|
|
|
const file = {
|
|
|
|
|
originalPath: 'fake_path/asset_1.jpeg',
|
|
|
|
|
mimeType: 'image/jpeg',
|
|
|
|
|
checksum: Buffer.from('file hash', 'utf8'),
|
|
|
|
|
originalName: 'asset_1.jpeg',
|
|
|
|
|
};
|
|
|
|
|
const dto = _getCreateAssetDto();
|
|
|
|
|
const error = new QueryFailedError('', [], '');
|
2023-09-20 13:16:33 +02:00
|
|
|
(error as any).constraint = ASSET_CHECKSUM_CONSTRAINT;
|
2023-01-30 11:14:13 -05:00
|
|
|
|
|
|
|
|
assetRepositoryMock.create.mockRejectedValue(error);
|
2023-05-24 23:08:21 +02:00
|
|
|
assetRepositoryMock.getAssetsByChecksums.mockResolvedValue([_getAsset_1()]);
|
2023-09-24 15:19:36 +02:00
|
|
|
accessMock.library.hasOwnerAccess.mockResolvedValue(true);
|
2023-01-30 11:14:13 -05:00
|
|
|
|
|
|
|
|
await expect(sut.uploadFile(authStub.user1, dto, file)).resolves.toEqual({ duplicate: true, id: 'id_1' });
|
|
|
|
|
|
2023-02-25 09:12:03 -05:00
|
|
|
expect(jobMock.queue).toHaveBeenCalledWith({
|
|
|
|
|
name: JobName.DELETE_FILES,
|
feat(server): xmp sidecar metadata (#2466)
* initial commit for XMP sidecar support
* Added support for 'missing' metadata files to include those without sidecar files, now detects sidecar files in the filesystem for media already ingested but the sidecar was created afterwards
* didn't mean to commit default log level during testing
* new sidecar logic for video metadata as well
* Added xml mimetype for sidecars only
* don't need capture group for this regex
* wrong default value reverted
* simplified the move here - keep it in the same try catch since the outcome is to move the media back anyway
* simplified setter logic
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
* simplified logic per suggestions
* sidecar is now its own queue with a discover and sync, updated UI for the new job queueing
* queue a sidecar job for every asset based on discovery or sync, though the logic is almost identical aside from linking the sidecar
* now queue sidecar jobs for each assset, though logic is mostly the same between discovery and sync
* simplified logic of filename extraction and asset instantiation
* not sure how that got deleted..
* updated code per suggestions and comments in the PR
* stat was not being used, removed the variable set
* better type checking, using in-scope variables for exif getter instead of passing in every time
* removed commented out test
* ran and resolved all lints, formats, checks, and tests
* resolved suggested change in PR
* made getExifProperty more dynamic with multiple possible args for fallbacks, fixed typo, used generic in function for better type checking
* better error handling and moving files back to positions on move or save failure
* regenerated api
* format fixes
* Added XMP documentation
* documentation typo
* Merged in main
* missed merge conflict
* more changes due to a merge
* Resolving conflicts
* added icon for sidecar jobs
---------
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2023-05-24 21:59:30 -04:00
|
|
|
data: { files: ['fake_path/asset_1.jpeg', undefined, undefined] },
|
2023-01-30 11:14:13 -05:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should handle a live photo', async () => {
|
|
|
|
|
const dto = _getCreateAssetDto();
|
|
|
|
|
const error = new QueryFailedError('', [], '');
|
2023-09-20 13:16:33 +02:00
|
|
|
(error as any).constraint = ASSET_CHECKSUM_CONSTRAINT;
|
2023-01-30 11:14:13 -05:00
|
|
|
|
2023-07-31 21:28:07 -04:00
|
|
|
assetRepositoryMock.create.mockResolvedValueOnce(assetStub.livePhotoMotionAsset);
|
|
|
|
|
assetRepositoryMock.create.mockResolvedValueOnce(assetStub.livePhotoStillAsset);
|
2023-09-24 15:19:36 +02:00
|
|
|
accessMock.library.hasOwnerAccess.mockResolvedValue(true);
|
2023-01-30 11:14:13 -05:00
|
|
|
|
2023-02-25 09:12:03 -05:00
|
|
|
await expect(
|
|
|
|
|
sut.uploadFile(authStub.user1, dto, fileStub.livePhotoStill, fileStub.livePhotoMotion),
|
|
|
|
|
).resolves.toEqual({
|
2023-01-30 11:14:13 -05:00
|
|
|
duplicate: false,
|
2023-02-25 09:12:03 -05:00
|
|
|
id: 'live-photo-still-asset',
|
2023-01-30 11:14:13 -05:00
|
|
|
});
|
|
|
|
|
|
2023-02-25 09:12:03 -05:00
|
|
|
expect(jobMock.queue.mock.calls).toEqual([
|
2023-05-27 16:49:57 -05:00
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: JobName.METADATA_EXTRACTION,
|
2023-07-31 21:28:07 -04:00
|
|
|
data: { id: assetStub.livePhotoMotionAsset.id, source: 'upload' },
|
2023-05-27 16:49:57 -05:00
|
|
|
},
|
|
|
|
|
],
|
2023-07-31 21:28:07 -04:00
|
|
|
[{ name: JobName.METADATA_EXTRACTION, data: { id: assetStub.livePhotoStillAsset.id, source: 'upload' } }],
|
2023-01-30 11:14:13 -05:00
|
|
|
]);
|
|
|
|
|
});
|
2022-09-16 16:47:45 -05:00
|
|
|
});
|
2022-08-26 22:53:37 -07:00
|
|
|
|
|
|
|
|
it('get assets by device id', async () => {
|
2022-09-16 16:47:45 -05:00
|
|
|
const assets = _getAssets();
|
|
|
|
|
|
|
|
|
|
assetRepositoryMock.getAllByDeviceId.mockImplementation(() =>
|
|
|
|
|
Promise.resolve<string[]>(Array.from(assets.map((asset) => asset.deviceAssetId))),
|
|
|
|
|
);
|
2022-08-26 22:53:37 -07:00
|
|
|
|
2022-09-16 16:47:45 -05:00
|
|
|
const deviceId = 'device_id_1';
|
2023-01-30 11:14:13 -05:00
|
|
|
const result = await sut.getUserAssetsByDeviceId(authStub.user1, deviceId);
|
2022-08-26 22:53:37 -07:00
|
|
|
|
2022-09-16 16:47:45 -05:00
|
|
|
expect(result.length).toEqual(2);
|
|
|
|
|
expect(result).toEqual(assets.map((asset) => asset.deviceAssetId));
|
|
|
|
|
});
|
|
|
|
|
|
2023-05-27 21:56:17 -04:00
|
|
|
describe('bulkUploadCheck', () => {
|
|
|
|
|
it('should accept hex and base64 checksums', async () => {
|
|
|
|
|
const file1 = Buffer.from('d2947b871a706081be194569951b7db246907957', 'hex');
|
|
|
|
|
const file2 = Buffer.from('53be335e99f18a66ff12e9a901c7a6171dd76573', 'hex');
|
|
|
|
|
|
|
|
|
|
assetRepositoryMock.getAssetsByChecksums.mockResolvedValue([
|
|
|
|
|
{ id: 'asset-1', checksum: file1 },
|
|
|
|
|
{ id: 'asset-2', checksum: file2 },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
sut.bulkUploadCheck(authStub.admin, {
|
|
|
|
|
assets: [
|
|
|
|
|
{ id: '1', checksum: file1.toString('hex') },
|
|
|
|
|
{ id: '2', checksum: file2.toString('base64') },
|
|
|
|
|
],
|
|
|
|
|
}),
|
|
|
|
|
).resolves.toEqual({
|
|
|
|
|
results: [
|
|
|
|
|
{ id: '1', assetId: 'asset-1', action: AssetUploadAction.REJECT, reason: AssetRejectReason.DUPLICATE },
|
|
|
|
|
{ id: '2', assetId: 'asset-2', action: AssetUploadAction.REJECT, reason: AssetRejectReason.DUPLICATE },
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(assetRepositoryMock.getAssetsByChecksums).toHaveBeenCalledWith(authStub.admin.id, [file1, file2]);
|
|
|
|
|
});
|
|
|
|
|
});
|
2023-06-16 15:01:34 -04:00
|
|
|
|
|
|
|
|
describe('getAssetById', () => {
|
|
|
|
|
it('should allow owner access', async () => {
|
2023-06-28 09:56:24 -04:00
|
|
|
accessMock.asset.hasOwnerAccess.mockResolvedValue(true);
|
2023-07-31 21:28:07 -04:00
|
|
|
assetRepositoryMock.getById.mockResolvedValue(assetStub.image);
|
|
|
|
|
await sut.getAssetById(authStub.admin, assetStub.image.id);
|
|
|
|
|
expect(accessMock.asset.hasOwnerAccess).toHaveBeenCalledWith(authStub.admin.id, assetStub.image.id);
|
2023-06-16 15:01:34 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should allow shared link access', async () => {
|
2023-06-28 09:56:24 -04:00
|
|
|
accessMock.asset.hasSharedLinkAccess.mockResolvedValue(true);
|
2023-07-31 21:28:07 -04:00
|
|
|
assetRepositoryMock.getById.mockResolvedValue(assetStub.image);
|
|
|
|
|
await sut.getAssetById(authStub.adminSharedLink, assetStub.image.id);
|
2023-06-28 09:56:24 -04:00
|
|
|
expect(accessMock.asset.hasSharedLinkAccess).toHaveBeenCalledWith(
|
2023-06-16 15:01:34 -04:00
|
|
|
authStub.adminSharedLink.sharedLinkId,
|
2023-07-31 21:28:07 -04:00
|
|
|
assetStub.image.id,
|
2023-06-16 15:01:34 -04:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should allow partner sharing access', async () => {
|
2023-06-28 09:56:24 -04:00
|
|
|
accessMock.asset.hasOwnerAccess.mockResolvedValue(false);
|
|
|
|
|
accessMock.asset.hasPartnerAccess.mockResolvedValue(true);
|
2023-07-31 21:28:07 -04:00
|
|
|
assetRepositoryMock.getById.mockResolvedValue(assetStub.image);
|
|
|
|
|
await sut.getAssetById(authStub.admin, assetStub.image.id);
|
|
|
|
|
expect(accessMock.asset.hasPartnerAccess).toHaveBeenCalledWith(authStub.admin.id, assetStub.image.id);
|
2023-06-16 15:01:34 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should allow shared album access', async () => {
|
2023-06-28 09:56:24 -04:00
|
|
|
accessMock.asset.hasOwnerAccess.mockResolvedValue(false);
|
|
|
|
|
accessMock.asset.hasPartnerAccess.mockResolvedValue(false);
|
|
|
|
|
accessMock.asset.hasAlbumAccess.mockResolvedValue(true);
|
2023-07-31 21:28:07 -04:00
|
|
|
assetRepositoryMock.getById.mockResolvedValue(assetStub.image);
|
|
|
|
|
await sut.getAssetById(authStub.admin, assetStub.image.id);
|
|
|
|
|
expect(accessMock.asset.hasAlbumAccess).toHaveBeenCalledWith(authStub.admin.id, assetStub.image.id);
|
2023-06-16 15:01:34 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should throw an error for no access', async () => {
|
2023-06-28 09:56:24 -04:00
|
|
|
accessMock.asset.hasOwnerAccess.mockResolvedValue(false);
|
|
|
|
|
accessMock.asset.hasPartnerAccess.mockResolvedValue(false);
|
|
|
|
|
accessMock.asset.hasSharedLinkAccess.mockResolvedValue(false);
|
|
|
|
|
accessMock.asset.hasAlbumAccess.mockResolvedValue(false);
|
2023-07-31 21:28:07 -04:00
|
|
|
await expect(sut.getAssetById(authStub.admin, assetStub.image.id)).rejects.toBeInstanceOf(BadRequestException);
|
2023-06-16 15:01:34 -04:00
|
|
|
expect(assetRepositoryMock.getById).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should throw an error for an invalid shared link', async () => {
|
2023-06-28 09:56:24 -04:00
|
|
|
accessMock.asset.hasSharedLinkAccess.mockResolvedValue(false);
|
2023-07-31 21:28:07 -04:00
|
|
|
await expect(sut.getAssetById(authStub.adminSharedLink, assetStub.image.id)).rejects.toBeInstanceOf(
|
2023-06-28 09:56:24 -04:00
|
|
|
BadRequestException,
|
2023-06-16 15:01:34 -04:00
|
|
|
);
|
2023-06-28 09:56:24 -04:00
|
|
|
expect(accessMock.asset.hasOwnerAccess).not.toHaveBeenCalled();
|
2023-06-16 15:01:34 -04:00
|
|
|
expect(assetRepositoryMock.getById).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
});
|
2022-08-26 22:53:37 -07:00
|
|
|
});
|