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

WFRxThrottledBatchedApplyOverlayToIdsTest.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2020 Adobe
All Rights Reserved.

NOTICE: All information contained herein is, and remains
the property of Adobe and its suppliers, if any. The intellectual
and technical concepts contained herein are proprietary to Adobe
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.

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

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

	-- WF.core.utils
local WFRxThrottledBatchedApplyOverlayToIds = require 'WFRxThrottledBatchedApplyOverlayToIds'
local KSIdGenerator = require 'KSIdGenerator'

	-- WF.oz_client.managed_catalog
local WFCatMockCatalog = require 'WFCatMockCatalog'


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

local createFakeWFCatalog = WFCatMockCatalog.createFakeWFCatalog


--==============================================================================

local WFRxThrottledBatchedApplyOverlayToIdsTest = {}

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

local function batchedBulkHelper( rxTest, docStore )

	local assetIds = {}

	for i=1,100 do

		local assetId = KSIdGenerator.uuidInLowercaseHex()

		rxTest:expectSingleValue(

			docStore:setDocValue {
					_id = assetId,
					type = 'asset',
					subtype = 'jpeg',
					_localOnly = {
						batchTest = true,
					}
				},

			':ignore:' )

		assetIds[ i ] = assetId

	end

	local overlay = {
		_localOnly = {
				batchTest = false,
		}
	}

	return assetIds, overlay
	
end

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

function WFRxThrottledBatchedApplyOverlayToIdsTest.rxTestThrottledBasic( rxTest )

	rxTest:setTimeLimit( 10 )

	local fakeWFCatalog = createFakeWFCatalog( rxTest )

	local docStore = fakeWFCatalog:docStore()

	local assetIds, overlay = batchedBulkHelper( rxTest, docStore )
	
	-- Check that the local only annotation is present
	
	for _, assetId in ipairs( assetIds ) do
	
		local batchTest = docStore:docValue( assetId )
			:pluck( "_localOnly", "batchTest" )
		
		rxTest:expectSingleValue( batchTest, true )
		
	end
	
	rxTest:expectSingleValue( WFRxThrottledBatchedApplyOverlayToIds( "Test", docStore, overlay, assetIds, 10, 10 ), true )
	
	-- Check that the local only annotation is gone
	
	for _, assetId in ipairs( assetIds ) do
	
		local batchTest = docStore:docValue( assetId )
			:pluck( "_localOnly", "batchTest" )
		
		rxTest:expectSingleValue( batchTest, false )
		
	end
	
end

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

return WFRxTestCase.wrapSuite( 'WFRxThrottledBatchedApplyOverlayToIdsTest', WFRxThrottledBatchedApplyOverlayToIdsTest )
