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

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

NOTICE: All information contained herein is, and remain 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 may be covered by U.S. and Foreign
Patents, patents in process, and are protected by trade secret or copyright
law.  Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

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

	-- WF.core.self_test
local WFRxTestCase = require 'WFRxTestCase'

	-- WF.core.utils
local WFTableMerge = require 'WFTableMerge'

	-- Lrmobile_models
local LrmOzRenditionServerUtils = require 'LrmOzRenditionServerUtils'	

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

local LrmOzRenditionServerUtilsTest = {}

local shouldDownload = LrmOzRenditionServerUtils.shouldDownloadOzRendition

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

function LrmOzRenditionServerUtilsTest.rxTestShouldDownload( rxTest )

	local revId = string.rep( 'a', 32 )
	
	local docValue = {
		_revId = revId,
		_serverProvidedMetadata = {
			links = {
				[ '/rels/rendition_type/thumbnail2x' ] = {
					href = 'ffff/renditions/aaaa',
				}
			},
			revision_ids = {
				revId,
			},
		}
	}
	
	rxTest:expectEqual( shouldDownload( nil, 'thumbnail2x' ), false )
	
	rxTest:expectEqual( shouldDownload( docValue, 'thumbnail2x' ), true )
	
	docValue = WFTableMerge.applyOverlay( docValue, {
			_localOnly = {
				thumbnail2x = {
					revId = 'ffff',
					renditionId = 'aaaa',
					md5 = '<hash>',
				}
			},
		} )
		
	rxTest:expectEqual( shouldDownload( docValue, 'thumbnail2x' ), false )
	
	docValue = WFTableMerge.applyOverlay( docValue, {
			_serverProvidedMetadata = {
				links = {
					[ '/rels/rendition_type/thumbnail2x' ] = {
						href = 'ffff/renditions/aaaa',
						invalid = true,
					}
				},
			}
		} )
		
	rxTest:expectEqual( shouldDownload( docValue, 'thumbnail2x' ), false )
	
	docValue = WFTableMerge.applyOverlay( docValue, {
			_serverProvidedMetadata = {
				links = {
					[ '/rels/rendition_type/thumbnail2x' ] = {
						href = 'gggg/renditions/dddd',
						invalid = true,
					}
				},
			}
		} )
		
	rxTest:expectEqual( shouldDownload( docValue, 'thumbnail2x' ), false )
	
	docValue = WFTableMerge.applyOverlay( docValue, {
			_serverProvidedMetadata = {
				links = {
					[ '/rels/rendition_type/thumbnail2x' ] = {
						href = 'gggg/renditions/dddd',
						invalid = false
					}
				},
			}
		} )
		
	rxTest:expectEqual( shouldDownload( docValue, 'thumbnail2x' ), true )
	
	docValue = {
		_serverProvidedMetadata = {
			links = {
				[ '/rels/rendition_type/2048' ] = {
					href = 'ffff/renditions/aaaa',
				}
			},
		}
	}
	
	rxTest:expectEqual( shouldDownload( docValue, 'preview' ), true )
	
	docValue = {
		_localOnly = {
				thumbnail2x = {
					revId = 'ffff',
					renditionId = 'aaaa',
					md5 = '<hash>',
				}
			},
		_serverProvidedMetadata = {
			links = {
				[ '/rels/rendition_type/thumbnail2x' ] = {
					href = 'ffff/renditions/aaab',
				}
			},
		}
	}
	
	rxTest:expectEqual( shouldDownload( docValue, 'thumbnail2x' ), false )
	
	docValue = {
		_localOnly = {
				thumbnail2x = {
					revId = 'ffff',
					renditionId = 'aaaa',
					md5 = '<hash>',
				}
			},
		_serverProvidedMetadata = {
			links = {
			},
		}
	}
	
	rxTest:expectEqual( shouldDownload( docValue, 'thumbnail2x' ), false )
	
	docValue = {
		_localOnly = {
				thumbnail2x = {
					revId = 'pending',
					renditionId = 'aaaa',
					md5 = '<hash>',
				}
			},
		_serverProvidedMetadata = {
			links = {
				[ '/rels/rendition_type/thumbnail2x' ] = {
					href = 'ffff/renditions/aaaa',
				}
			},
		}
	}
	
	rxTest:expectEqual( shouldDownload( docValue, 'thumbnail2x' ), false )
	
end

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

return WFRxTestCase.wrapSuite( 'LrmOzRenditionServerUtilsTest',  LrmOzRenditionServerUtilsTest )

