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

WFRxBatchedBulkSetDocValueTest.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.core.self_test
local WFRxTestCase = require 'WFRxTestCase'

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

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


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

local createFakeWFCatalog = WFCatMockCatalog.createFakeWFCatalog


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

local WFRxBatchedBulkSetDocValueTest = {}

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

local function batchedBulkHelper( rxTest, docStore )

	local assetIds = {}
	local bulkDocs = {}
	
	for i=1, 100 do

		local assetId = KSIdGenerator.uuidInLowercaseHex()

		table.insert( bulkDocs, {
			_id = assetId,
			type = 'asset',
			subtype = 'jpeg',
			_localOnly = {
				batchTest = true,
			}
		} )

		assetIds[ i ] = assetId

	end

	return assetIds, bulkDocs
	
end

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

function WFRxBatchedBulkSetDocValueTest.rxTestBasic( rxTest )

	rxTest:setTimeLimit( 10 )

	local fakeWFCatalog = createFakeWFCatalog( rxTest )

	local docStore = fakeWFCatalog:docStore()

	local assetIds, bulkDocs = batchedBulkHelper( rxTest, docStore )
	
	rxTest:expectSingleValue( WFRxBatchedBulkSetDocValue( "test basic", docStore, bulkDocs, 3 ), true )
	
	-- Check the doc values
	
	for _, assetId in ipairs( assetIds ) do
	
		local batchTest = docStore:docValue( assetId )
			:pluck( "_localOnly", "batchTest" )
		
		rxTest:expectSingleValue( batchTest, true )
		
	end
	
end

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

return WFRxTestCase.wrapSuite( WFRxBatchedBulkSetDocValueTest )
