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

WFOzUserTestSessionTest.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.account
local WFOzUserTestSession = require 'WFOzUserTestSession'


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

local WFOzUserTestSessionTest = {}

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

function WFOzUserTestSessionTest.rxTestUserInfo_testNightly( rxTest )

	rxTest:setTimeLimit( 10 )

	local userTestSession = WFOzUserTestSession( rxTest, { v1 = true } )

	local userEmail

	rxTest:expectSingleValue(
		userTestSession:userInfo()
			:map( function( _userEmail, password, otherInfo )

				userEmail = _userEmail

				return _userEmail, password, otherInfo,
					   _userEmail:match( '@' )

			end),

		':ignore:', ':ignore:', ':ignore:', '@' )

	-- Should return the same user ID if we ask again.

	rxTest:expectSingleValue( userTestSession:userInfo(),
							  userEmail,
							  ':ignore:',
							  ':ignore:' )

end

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

function WFOzUserTestSessionTest.rxTestUserInfo_v2_testNightly( rxTest )

	rxTest:setTimeLimit( 10 )

	local userTestSession = WFOzUserTestSession( rxTest, { v2 = true } )

	local userEmail

	rxTest:expectSingleValue(
		userTestSession:userInfo()
			:map( function( _userEmail, password, otherInfo )

				userEmail = _userEmail

				return _userEmail, password, otherInfo,
					   _userEmail:match( '@' )

			end),

		':ignore:', ':ignore:', ':ignore:', '@' )

	-- Should return the same user ID if we ask again.

	rxTest:expectSingleValue( userTestSession:userInfo(),
							  userEmail,
							  ':ignore:',
							  ':ignore:' )

end

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

function WFOzUserTestSessionTest.rxTestRelease_testNightly( rxTest )

	rxTest:setTimeLimit( 10 )

	local userTestSession = WFOzUserTestSession( 'rxTestRelease' )

	local userEmail

	rxTest:expectSingleValue(
		userTestSession:userInfo()
			:map( function( _userEmail, password, otherInfo )

				userEmail = _userEmail

				return _userEmail, password, otherInfo,
					   _userEmail:match( '@' )

			end),

		':ignore:', ':ignore:', ':ignore:', '@' )

	-- Now release this user. Normally in rxTest-based tests, this is
	-- done automatically, but in this case we didn't provide an rxTest
	-- object, so we have to do it manually.

	rxTest:expectOnlyCompleted( userTestSession:releaseUser() )

end

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

function WFOzUserTestSessionTest.rxTestGetCleanOzAccount_testNightly( rxTest )

	rxTest:setTimeLimit( 60 )

	local userTestSession = WFOzUserTestSession( rxTest )

	local ozUserId

	rxTest:expectSingleValue(

		userTestSession:getCleanOzAccount()
			:tap( function( _ozUserId )
				ozUserId = _ozUserId
			end ),

		':ignore:' )

	rxTest:expectEqual( 'string', type( ozUserId ) )
	rxTest:expectEqual( 32, #ozUserId )

end

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

return WFRxTestCase.wrapSuite( WFOzUserTestSessionTest )
