@ -356,7 +356,7 @@ describe(MetadataService.name, () => {
} ) ;
it ( 'should extract the MotionPhotoVideo tag from Samsung HEIC motion photos' , async ( ) = > {
assetMock . getByIds . mockResolvedValue ( [ { . . . assetStub . livePhoto StillAsset , livePhotoVideoId : null } ] ) ;
assetMock . getByIds . mockResolvedValue ( [ { . . . assetStub . livePhoto WithOriginalFileName , livePhotoVideoId : null } ] ) ;
metadataMock . readTags . mockResolvedValue ( {
Directory : 'foo/bar/' ,
MotionPhotoVideo : new BinaryField ( 0 , '' ) ,
@ -372,23 +372,23 @@ describe(MetadataService.name, () => {
const video = randomBytes ( 512 ) ;
metadataMock . extractBinaryTag . mockResolvedValue ( video ) ;
await sut . handleMetadataExtraction ( { id : assetStub.livePhoto StillAsset .id } ) ;
await sut . handleMetadataExtraction ( { id : assetStub.livePhoto WithOriginalFileName .id } ) ;
expect ( metadataMock . extractBinaryTag ) . toHaveBeenCalledWith (
assetStub . livePhoto StillAsset . originalPath ,
assetStub . livePhoto WithOriginalFileName . originalPath ,
'MotionPhotoVideo' ,
) ;
expect ( assetMock . getByIds ) . toHaveBeenCalledWith ( [ assetStub . livePhoto StillAsset . id ] ) ;
expect ( assetMock . getByIds ) . toHaveBeenCalledWith ( [ assetStub . livePhoto WithOriginalFileName . id ] ) ;
expect ( assetMock . create ) . toHaveBeenCalled ( ) ; // This could have arguments added
expect ( userMock . updateUsage ) . toHaveBeenCalledWith ( assetStub . livePhotoMotionAsset . ownerId , 512 ) ;
expect ( storageMock . writeFile ) . toHaveBeenCalledWith ( assetStub . livePhotoMotionAsset . originalPath , video ) ;
expect ( assetMock . update ) . toHaveBeenNthCalledWith ( 1 , {
id : assetStub.livePhoto StillAsset .id,
id : assetStub.livePhoto WithOriginalFileName .id,
livePhotoVideoId : fileStub.livePhotoMotion.uuid ,
} ) ;
} ) ;
it ( 'should extract the EmbeddedVideo tag from Samsung JPEG motion photos' , async ( ) = > {
assetMock . getByIds . mockResolvedValue ( [ { . . . assetStub . livePhoto StillAsset , livePhotoVideoId : null } ] ) ;
assetMock . getByIds . mockResolvedValue ( [ { . . . assetStub . livePhoto WithOriginalFileName , livePhotoVideoId : null } ] ) ;
metadataMock . readTags . mockResolvedValue ( {
Directory : 'foo/bar/' ,
EmbeddedVideoFile : new BinaryField ( 0 , '' ) ,
@ -401,23 +401,23 @@ describe(MetadataService.name, () => {
const video = randomBytes ( 512 ) ;
metadataMock . extractBinaryTag . mockResolvedValue ( video ) ;
await sut . handleMetadataExtraction ( { id : assetStub.livePhoto StillAsset .id } ) ;
await sut . handleMetadataExtraction ( { id : assetStub.livePhoto WithOriginalFileName .id } ) ;
expect ( metadataMock . extractBinaryTag ) . toHaveBeenCalledWith (
assetStub . livePhoto StillAsset . originalPath ,
assetStub . livePhoto WithOriginalFileName . originalPath ,
'EmbeddedVideoFile' ,
) ;
expect ( assetMock . getByIds ) . toHaveBeenCalledWith ( [ assetStub . livePhoto StillAsset . id ] ) ;
expect ( assetMock . getByIds ) . toHaveBeenCalledWith ( [ assetStub . livePhoto WithOriginalFileName . id ] ) ;
expect ( assetMock . create ) . toHaveBeenCalled ( ) ; // This could have arguments added
expect ( userMock . updateUsage ) . toHaveBeenCalledWith ( assetStub . livePhotoMotionAsset . ownerId , 512 ) ;
expect ( storageMock . writeFile ) . toHaveBeenCalledWith ( assetStub . livePhotoMotionAsset . originalPath , video ) ;
expect ( assetMock . update ) . toHaveBeenNthCalledWith ( 1 , {
id : assetStub.livePhoto StillAsset .id,
id : assetStub.livePhoto WithOriginalFileName .id,
livePhotoVideoId : fileStub.livePhotoMotion.uuid ,
} ) ;
} ) ;
it ( 'should extract the motion photo video from the XMP directory entry ' , async ( ) = > {
assetMock . getByIds . mockResolvedValue ( [ { . . . assetStub . livePhoto StillAsset , livePhotoVideoId : null } ] ) ;
assetMock . getByIds . mockResolvedValue ( [ { . . . assetStub . livePhoto WithOriginalFileName , livePhotoVideoId : null } ] ) ;
metadataMock . readTags . mockResolvedValue ( {
Directory : 'foo/bar/' ,
MotionPhoto : 1 ,
@ -431,20 +431,23 @@ describe(MetadataService.name, () => {
const video = randomBytes ( 512 ) ;
storageMock . readFile . mockResolvedValue ( video ) ;
await sut . handleMetadataExtraction ( { id : assetStub.livePhotoStillAsset.id } ) ;
expect ( assetMock . getByIds ) . toHaveBeenCalledWith ( [ assetStub . livePhotoStillAsset . id ] ) ;
expect ( storageMock . readFile ) . toHaveBeenCalledWith ( assetStub . livePhotoStillAsset . originalPath , expect . any ( Object ) ) ;
await sut . handleMetadataExtraction ( { id : assetStub.livePhotoWithOriginalFileName.id } ) ;
expect ( assetMock . getByIds ) . toHaveBeenCalledWith ( [ assetStub . livePhotoWithOriginalFileName . id ] ) ;
expect ( storageMock . readFile ) . toHaveBeenCalledWith (
assetStub . livePhotoWithOriginalFileName . originalPath ,
expect . any ( Object ) ,
) ;
expect ( assetMock . create ) . toHaveBeenCalled ( ) ; // This could have arguments added
expect ( userMock . updateUsage ) . toHaveBeenCalledWith ( assetStub . livePhotoMotionAsset . ownerId , 512 ) ;
expect ( storageMock . writeFile ) . toHaveBeenCalledWith ( assetStub . livePhotoMotionAsset . originalPath , video ) ;
expect ( assetMock . update ) . toHaveBeenNthCalledWith ( 1 , {
id : assetStub.livePhoto StillAsset .id,
id : assetStub.livePhoto WithOriginalFileName .id,
livePhotoVideoId : fileStub.livePhotoMotion.uuid ,
} ) ;
} ) ;
it ( 'should delete old motion photo video assets if they do not match what is extracted' , async ( ) = > {
assetMock . getByIds . mockResolvedValue ( [ assetStub . livePhoto StillAsset ] ) ;
assetMock . getByIds . mockResolvedValue ( [ assetStub . livePhoto WithOriginalFileName ] ) ;
metadataMock . readTags . mockResolvedValue ( {
Directory : 'foo/bar/' ,
MotionPhoto : 1 ,
@ -457,10 +460,10 @@ describe(MetadataService.name, () => {
const video = randomBytes ( 512 ) ;
storageMock . readFile . mockResolvedValue ( video ) ;
await sut . handleMetadataExtraction ( { id : assetStub.livePhoto StillAsset .id } ) ;
await sut . handleMetadataExtraction ( { id : assetStub.livePhoto WithOriginalFileName .id } ) ;
expect ( jobMock . queue ) . toHaveBeenNthCalledWith ( 1 , {
name : JobName.ASSET_DELETION ,
data : { id : assetStub.livePhoto StillAsset .livePhotoVideoId } ,
data : { id : assetStub.livePhoto WithOriginalFileName .livePhotoVideoId } ,
} ) ;
expect ( jobMock . queue ) . toHaveBeenNthCalledWith ( 2 , {
name : JobName.METADATA_EXTRACTION ,