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

ADOBE CONFIDENTIAL
------------------
Copyright 2020 Adobe Inc
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.os
local WFPlatformInfo = require 'WFPlatformInfo'

if not WFPlatformInfo.isiOS then

	return {}
		-- This test suite only runs on iOS
		
end

local KSIdGenerator = require 'KSIdGenerator'

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

	-- lrmobile.models.test
local LrmDocValueTestFactory = require 'LrmDocValueTestFactory'

	-- WF.managed_catalog
local WFCatTestSession = require 'WFCatTestSession'

	-- lrmobile.models
local LriBlobConsistencyModel = require 'LriBlobConsistencyModel'

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

local LriBlobConsistencyModelTest = {}

local TEST_TIMEOUT = 10

local catalog

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

local function setUpTest( rxTest )

	local catalogTestSession = WFCatTestSession( rxTest, nil, 'LrmCatalogIndexDefinitions.lua' )

	rxTest:waitFor(
		catalogTestSession:catalog()
			:tap( function( _catalog )
				catalog = _catalog
			end ) )
			
	rxTest:finally( function()
		if catalog then
			catalog:close()
			catalog = nil
		end
	end )
	
end

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

function LriBlobConsistencyModelTest.rxTestNoTHLibrary( rxTest )

	rxTest:setTimeLimit( TEST_TIMEOUT )
	
	setUpTest( rxTest )
	
	rxTest:expectOnlyError( LriBlobConsistencyModel.makeModel( catalog ).value, 
		"LrmTHLibrary not loaded or LrmTHLibrary.isLocallyAvailable not implemented" ) 

end

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

local function mockLocallyAvailable( strippedDoc, renditionList )
	return renditionList
end

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

function LriBlobConsistencyModelTest.rxTestMockedNoCacheReferences( rxTest )

	rxTest:setTimeLimit( TEST_TIMEOUT )
	
	setUpTest( rxTest )
	
	rxTest:expectSingleValue( LriBlobConsistencyModel.makeModel( catalog, mockLocallyAvailable ).value, 
		{ totalCount = 0, missingBlobs = 0 } ) 

end

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

function LriBlobConsistencyModelTest.rxTestMockedOneCacheReference( rxTest )

	rxTest:setTimeLimit( TEST_TIMEOUT )	

	setUpTest( rxTest )

	local docValue = LrmDocValueTestFactory.makeCompleteAsset()
	docValue._id = KSIdGenerator.uuidInLowercaseHex()
	docValue.type = 'asset'

	rxTest:expectSingleValue( catalog:docStore():applyOverlay( docValue ), ':ignore:' )

	rxTest:expectSingleValue( LriBlobConsistencyModel.makeModel( catalog, mockLocallyAvailable ).value, 
		{ totalCount = 1, missingBlobs = 1 } ) 

end

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

return WFRxTestCase.wrapSuite( LriBlobConsistencyModelTest )
