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

WFCatSpecTest.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2015 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.oz_client.managed_catalog
local WFCatSpec = require 'WFCatSpec'
local WFCatUser = require 'WFCatUser'


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

local WFCatSpecTest = {}

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

local kUser1 = string.rep( '1', 32 )
local kCatalogId = string.rep( 'c', 32 )

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

function WFCatSpecTest.rxTestBasic( rxTest )

	local user1 = WFCatUser( 'app://server-base', kUser1, ':memory:' )
	local spec = WFCatSpec( user1, kCatalogId )

	rxTest:expectEqual( 'app://server-base', spec:serverBaseUrl() )
	rxTest:expectEqual( kCatalogId, spec:catalogId() )
	rxTest:expectEqual( '/v2/', spec:baseHref() )
	rxTest:expectEqual( '/v2/catalogs/' .. kCatalogId, spec:catalogHref() )
	rxTest:expectEqual( kUser1, spec:ozUserId() )
	rxTest:expectEqual( user1, spec:wfOzUser() )
	rxTest:expectEqual( 'string', type( tostring( spec ) ) )
	rxTest:expectEqual( 'app://server-base/v2/catalogs/' .. kCatalogId .. "/updates", spec:catalogUpdatesUrl() )
	rxTest:expectEqual( 'app://server-base/v2/spaces/updates', spec:spaceUploadUrl() )
	
	spec = WFCatSpec( user1, '/v2/catalogs/' .. kCatalogId )
	rxTest:expectEqual( kCatalogId, spec:catalogId() )
	rxTest:expectEqual( '/v2/', spec:baseHref() )
	rxTest:expectEqual( '/v2/catalogs/' .. kCatalogId, spec:catalogHref() )

end

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

function WFCatSpecTest.rxTestInitValidatesArguments( rxTest )

	local user1 = WFCatUser( 'app://server-base', kUser1, ':memory:' )

	rxTest:expectError( function()

		return WFCatSpec( user1, '/' )

	end )

	rxTest:expectError( function()

		return WFCatSpec( user1, 'abcd' )

	end )

	rxTest:expectError( function()

		return WFCatSpec( user1, '/v2/libraries/aaa' )

	end )

--[[
	-- TODO [scouten 2015-07-20]: Write new tests for :get and :put.

	local spec = WFCatSpec( user1, kCatalogId )

	rxTest:expectError( function()

		return spec:get( 'app://fake-url/fake' )
			-- FIXME, once implemented we should add a nightly test that
			-- does an unauthorized hit on /v2/ or something (?)

	end )

	rxTest:expectError( function()

		return spec:put( 'app://fake-url/fake' )
			-- FIXME, once implemented we should add a nightly test that
			-- does an unauthorized hit on /v2/ or something (?)

	end )
]]--

end

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

return WFRxTestCase.wrapSuite( WFCatSpecTest )
