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

WFCapabilitiesCacheTest.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2023 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.utils
local KSIdGenerator = require 'KSIdGenerator'
local WFCapabilities = require 'WFCapabilities'
local WFCapabilitiesCache = require 'WFCapabilitiesCache'

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

local WFCapabilitiesCacheTest = {}

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

function WFCapabilitiesCacheTest.testBasic()

	-- capability name has to be randomized for each test run so that it will
	-- start unset

	local capabilityName = 'test_capability_' .. KSIdGenerator.uuidInLowercaseHex()

	-- can pass capabilities table into constructor

	local capCache = WFCapabilitiesCache( { foo = true, bar = 'false' } )

	assert( capCache:get( 'foo' ) == true, 'incorrect value returned for key foo' )
	assert( capCache:get( 'bar' ) == 'false', 'incorrect value returned for key bar' )
	assert( capCache:get( capabilityName ) == false, 'incorrect value returned for unset_capability' )

	-- setting capability after it has been checked in cache will not have any impact

	WFCapabilities.setCapability( capabilityName, 'true' )

	assert( capCache:get( capabilityName ) == false, 'incorrect value returned for unset_capability' )

	-- can create new empty WFCapabilitiesCache

	capCache = WFCapabilitiesCache()

	assert( capCache:get( 'foo' ) == false, 'incorrect value returned for key foo' )
	assert( capCache:get( 'bar' ) == false, 'incorrect value returned for key bar' )

	-- new WFCapabilitiesCache will pick up already set capabilities

	assert( capCache:get( capabilityName ) == 'true', 'incorrect value returned for unset_capability' )

	-- can set new values in cache of any type

	capCache:setCapabilitiesForTests( { foo = 100, bar = { anything = 'goes' } } )

	assert( capCache:get( 'foo' ) == 100, 'incorrect value returned for key foo' )
	assert( capCache:get( 'bar' ).anything == 'goes', 'incorrect value returned for key bar' )

	-- can unset capabilities

	capCache:setCapabilitiesForTests( { foo = false, bar = false } )

	assert( capCache:get( 'foo' ) == false, 'incorrect value returned for key foo' )
	assert( capCache:get( 'bar' ) == false, 'incorrect value returned for key bar' )

end

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

return WFCapabilitiesCacheTest
