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

WFRxThrottledBatchedBulkApplyOverlayTest.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2016 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.core.self_test
local WFRxTestCase = require 'WFRxTestCase'

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

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


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

local createFakeWFCatalog = WFCatMockCatalog.createFakeWFCatalog


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

local WFRxThrottledBatchedBulkApplyOverlayTest = {}

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

local function batchedBulkHelper( rxTest, docStore )

	local assetIds = {}
	local bulkOverlay = {}
	
	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

		bulkOverlay[ i ] = {
			_id = assetId,
			_localOnly = {
				batchTest = false,
			}
		}

	end

	return assetIds, bulkOverlay
	
end

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

function WFRxThrottledBatchedBulkApplyOverlayTest.rxTestThrottledBasic( rxTest )

	rxTest:setTimeLimit( 10 )

	local fakeWFCatalog = createFakeWFCatalog( rxTest )

	local docStore = fakeWFCatalog:docStore()

	local assetIds, bulkOverlay = 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( WFRxThrottledBatchedBulkApplyOverlay( "Test", docStore, bulkOverlay, 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( WFRxThrottledBatchedBulkApplyOverlayTest )
