--[[----------------------------------------------------------------------------

WFCatImportManifestMergeAssetUtilsTest.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2017 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remains the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and are protected by all applicable
intellectual property laws, including trade secret and copyright laws.
Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

----------------------------------------------------------------------------]]--


	-- WF.oz_client.managed_catalog.import
local WFCatImportManifestMergeAssetUtils = require 'WFCatImportManifestMergeAssetUtils'


local kMergeTypes = WFCatImportManifestMergeAssetUtils.kMergeTypes
local kUserIdPlaceHolder = WFCatImportManifestMergeAssetUtils.kUserIdPlaceHolder

--------------------------------------------------------------------------------

local WFCatImportManifestMergeAssetUtilsTest = {
}

--------------------------------------------------------------------------------

function WFCatImportManifestMergeAssetUtilsTest:testMergeDoc( )
	
	local mergeSchema = {
		xmp = {
			dc = {
				description = kMergeTypes.override,
				title = kMergeTypes.override,
				copyright = kMergeTypes.override,
				subject = kMergeTypes.merge,
			}
		},

	}
	mergeSchema.ratings = {}
	mergeSchema.ratings[ kUserIdPlaceHolder ] = kMergeTypes.latest
	mergeSchema.reviews = {}
	mergeSchema.reviews[ kUserIdPlaceHolder ] = kMergeTypes.latest
	mergeSchema.develop = kMergeTypes.latest
	mergeSchema._localOnly = kMergeTypes.ignore
	

	local userId = "123456ABCD"
	
	local incomingDoc = {
		xmp = {
			dc = {
				rights = "John Stephen",
				title = "Taj Mahal",
				subject = {
					tiger = true,
					animal = true,
				}
			}
		},
		develop = { 
			processingModel = "lightroom",
			croppedHeight = 6000,
			userUpdated = "2017-02-28T08:36:48Z",
			croppedWidth = 4000,
			userOrientation = 6,
			xmpCameraRaw = "<x:xmpmeta xmlns../>",
			profiles = {
				lens = {
					filename = "NIKON D300 (Nikon AF-S DX NIKKOR 18-140mm f3.5-5.6G ED VR) - RAW.lcp",
				},
				camera = {
					filename = "Nikon D5200 Adobe Standard.dcp",
				}
			}
		},
		_localOnly = {
			xmpSidecarExists = false,
		}
	}
	incomingDoc.ratings = {}
	incomingDoc.ratings[ userId ] = {
		date = "2016-10-19T07:19:26.091Z",
		rating = 4,
	}
	incomingDoc.reviews = {}
	incomingDoc.reviews[ userId ] = {
		date = "2013-07-10T08:32:13Z",
		flag = "pick",
	}
	
	local existingDoc = {
		xmp = {
			dc = {
				rights = "John",
				subject = {
					forest = true,
					tiger = true,
				}
			}
		},
		develop = { 
			processingModel = "lightroom",
			croppedHeight = 1000,
			userUpdated = "2016-02-28T08:36:48Z",
			croppedWidth = 4000,
			userOrientation = 1,
			xmpCameraRaw = "<x:xmpmeta xmlns sdsdad../>",
			profiles = {
				lens = {
					filename = "NIKON D300 .lcp",
				},
				camera = {
					filename = "Nikon D5200 Camera Neutral.dcp",
				}
			}
		},
	}
	existingDoc.ratings = {}
	existingDoc.ratings[ userId ] = {
		date = "2016-11-19T07:19:26.091Z",
		rating = 3,
	}
	existingDoc.reviews = {}
	existingDoc.reviews[ userId ] = {
		date = "2012-07-10T08:32:13Z",
		flag = "reject",
	}
	
	local result = WFCatImportManifestMergeAssetUtils.mergeDoc( userId, mergeSchema, incomingDoc, existingDoc )
	
	assert( result.xmp.dc.rights == "John Stephen", "Rights merge error" )
	assert( result.xmp.dc.subject.animal == true, "Subject merge error" )
	assert( result.xmp.dc.subject.tiger == true, "Subject merge error" )
	assert( result.xmp.dc.subject.forest == true, "Subject merge error" )
	assert( result.xmp.dc.title == "Taj Mahal", "Title merge error" )
	assert( result.develop.croppedHeight == 6000, "Develop merge error" )
	assert( result.ratings[ userId ].rating == 3, "Ratings merge error" )
	assert( result.reviews[ userId ].flag == "pick", "Reviews merge error" )
	assert( result._localOnly == nil, "_localOnly merge error" )
end

--------------------------------------------------------------------------------

function WFCatImportManifestMergeAssetUtilsTest:testMergeWithParentRuleDoc( )
	
	local mergeSchema = {
		importSource = {
			[ WFCatImportManifestMergeAssetUtils.kKeyDefaultMergeType ] = kMergeTypes.add,
			lrcatStoreProviderId = kMergeTypes.override,
			lrcatImageId = kMergeTypes.override,
		},

	}

	local userId = "123456ABCD"
	
	local incomingDoc = {
		importSource = {
			fileName = "ABC.jpg",
			fileSize = "10233",
			importTimestamp = "2016-11-19T07:19:26.091Z",
			importedBy = "John",
			importedOnDevice = "MacbookPro",
			originalWidth = 1024,
			originalHeight = 1024,
			contentType = "image/jpeg",
			
			lrcatStoreProviderId = "11111111111",
			lrcatImageId = "1",
		},
		
	}
	
	local existingDoc = {
		importSource = {
			fileName = "PQR.jpg",
			fileSize = "222222",
			importTimestamp = "2017-01-29T07:19:26.091Z",
			importedBy = "Jane",
			importedOnDevice = "Windows",
			originalWidth = 2048,
			originalHeight = 2048,
			
			lrcatStoreProviderId = "222222222",
			lrcatImageId = "2",
		},
	}
	
	local result = WFCatImportManifestMergeAssetUtils.mergeDoc( userId, mergeSchema, incomingDoc, existingDoc )
	
	assert( result.importSource.lrcatStoreProviderId == "11111111111", "lrcatStoreProviderId merge error" )
	assert( result.importSource.lrcatImageId == "1", "lrcatImageId merge error" )
	assert( result.importSource.fileName == "PQR.jpg", "fileName merge error" )
	assert( result.importSource.importedBy == "Jane", "importedBy merge error" )
	assert( result.importSource.contentType == "image/jpeg", "contentType merge error( add failed )" )
	
	
	local mergeSchema2 = {
		importSource = {
			[ WFCatImportManifestMergeAssetUtils.kKeyDefaultMergeType ] = kMergeTypes.ignore,
			lrcatStoreProviderId = kMergeTypes.override,
			lrcatImageId = kMergeTypes.override,
		},
	}
	
	result = WFCatImportManifestMergeAssetUtils.mergeDoc( userId, mergeSchema2, incomingDoc, existingDoc )
	
	assert( result.importSource.lrcatStoreProviderId == "11111111111", "lrcatStoreProviderId merge error" )
	assert( result.importSource.lrcatImageId == "1", "lrcatImageId merge error" )
	assert( result.importSource.fileName == "PQR.jpg", "fileName merge error" )
	assert( result.importSource.importedBy == "Jane", "importedBy merge error" )
	assert( result.importSource.contentType == nil, "contentType merge error( ignore failed )" )
end

--------------------------------------------------------------------------------

return WFCatImportManifestMergeAssetUtilsTest
