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

WFCatDoOnceTest.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.

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

	-- Rx
local Rx = require 'Rx'

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

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

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

local createFakeWFCatalog = WFCatMockCatalog.createFakeWFCatalog

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

local WFCatDoOnceTest = {}

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

function WFCatDoOnceTest.rxTestBasic( rxTest )

	rxTest:setTimeLimit( 10 )

	local wfCatalog = createFakeWFCatalog( rxTest )

	local docStore = wfCatalog:docStore()
	
	local doThingCount = 0
	
	local function doThing()
		doThingCount = doThingCount + 1
		return Rx.Observable.just( true )
	end
			
	local optArgs = {
		delay = 0,
	}
			

	rxTest:expectOnlyCompleted( WFCatDoOnce( docStore, 'DoThing', doThing, optArgs ) )
	rxTest:expectEqual( 1, doThingCount )
	
	rxTest:expectOnlyCompleted( WFCatDoOnce( docStore, 'DoThing', doThing, optArgs ) )
	rxTest:expectEqual( 1, doThingCount )
	
	rxTest:expectOnlyCompleted( WFCatDoOnce( docStore, 'DoThing', doThing, optArgs ) )
	rxTest:expectEqual( 1, doThingCount )

	rxTest:expectOnlyCompleted( WFCatDoOnce( docStore, 'DoThing2', doThing, optArgs ) )
	rxTest:expectEqual( 2, doThingCount )

	optArgs = {
		delay = 0,
		forceFunctionRun = true
	}

	rxTest:expectOnlyCompleted( WFCatDoOnce( docStore, 'DoThing', doThing, optArgs ) )
	rxTest:expectEqual( 3, doThingCount )

	

end

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

return WFRxTestCase.wrapSuite( 'WFCatDoOnceTest', WFCatDoOnceTest )
