--[[----------------------------------------------------------------------------
ADOBE CONFIDENTIAL
------------------
Copyright 2017 Adobe Systems Incorporated
All Rights Reserved.
NOTICE: All information contained herein is, and remain 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 may be covered by U.S. and Foreign
Patents, patents in process, and are protected by trade secret or copyright
law.  Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.
----------------------------------------------------------------------------]]--

local Rx = require 'Rx'
local WFRxTestCase = require 'WFRxTestCase'
local LrmCatalogTestHelper = require 'LrmCatalogTestHelper'
local LrmLibrarySocialModelImp = require 'LrmLibrarySocialModelImp'
local KSIdGenerator = require 'KSIdGenerator'
local WFPlatformInfo = require 'WFPlatformInfo'
local WFCatCollaborationActivityTestUtils = require 'WFCatCollaborationActivityTestUtils'

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

local LrmLibararySocialModelImpTest = {}

local wfCatalog

local TEST_TIMEOUT = 10

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

function LrmLibararySocialModelImpTest.setUp()

	wfCatalog = LrmCatalogTestHelper.makeWFCatalog()

end

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

function LrmLibararySocialModelImpTest.tearDown()

	if wfCatalog then

		wfCatalog:close()
		wfCatalog = nil

	end

end

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

function LrmLibararySocialModelImpTest.rxTestAddComment( rxTest )

	-- testing the happy path

	local result = LrmLibrarySocialModelImp:addComment( 'FAKE', 'FAKE', 'FAKE', {
				TEST_mock = function(_catalog, _albumId, _assetId, _comment)
					return Rx.Observable.just( true )
				end
			} )

	rxTest:expectSingleValue( result.value, { state = true } )

	-- testing the sad path

	local fakeError = "FAILED TO ADD COMMENT"

	result = LrmLibrarySocialModelImp:addComment( 'FAKE', 'FAKE', 'FAKE', {
				TEST_mock = function(_catalog, _albumId, _assetId, _comment)
					return Rx.Observable.throw( fakeError )
				end
			} )

	rxTest:expectSingleValue(result.value, { state = false, error = fakeError })

end

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

function LrmLibararySocialModelImpTest.rxTestDeleteComment( rxTest )

	-- testing the happy path

	local result = LrmLibrarySocialModelImp:deleteComment( 'FAKE', {
				TEST_mock = function( )
					return Rx.Observable.just( true )
				end
			} )

	rxTest:expectSingleValue( result.value, { state = true } )

	-- testing the sad path

	local fakeError = "FAILED TO DELETE COMMENT"

	result = LrmLibrarySocialModelImp:deleteComment( 'FAKE', {
				TEST_mock = function( )
					return Rx.Observable.throw( fakeError )
				end
			} )

	rxTest:expectSingleValue(result.value, { state = false, error = fakeError })

end

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

function LrmLibararySocialModelImpTest.rxTestDeleteSpaceFavorite( rxTest )

	-- testing the happy path

	local result = LrmLibrarySocialModelImp:deleteSpaceFavorite( 'FAKE', {
				TEST_mock = function( )
					return Rx.Observable.just( true )
				end
			} )

	rxTest:expectSingleValue( result.value, { state = true } )

	-- testing the sad path

	local fakeError = "FAILED TO DELETE SPACE FAVORITE"

	result = LrmLibrarySocialModelImp:deleteSpaceFavorite( 'FAKE', {
				TEST_mock = function( )
					return Rx.Observable.throw( fakeError )
				end
			} )

	rxTest:expectSingleValue(result.value, { state = false, error = fakeError })

end

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

function LrmLibararySocialModelImpTest.rxTestToggleMyFavorite( rxTest )

	-- testing the happy path

	local result = LrmLibrarySocialModelImp:toggleMyFavorite( 'FAKE', 'FAKE', {
				TEST_mock = function(_catalog, _assetId, _albumId)
					return Rx.Observable.just( true )
				end
			} )

	rxTest:expectSingleValue( result.value, { state = true } )

	-- testing the sad path

	local fakeError = "FAILED TO TOGGLE MY FAVORITE"

	result = LrmLibrarySocialModelImp:toggleMyFavorite( 'FAKE', 'FAKE', {
				TEST_mock = function(_catalog, _assetId, _albumId)
					return Rx.Observable.throw( fakeError )
				end
			} )

	rxTest:expectSingleValue(result.value, { state = false, error = fakeError })

end

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

function LrmLibararySocialModelImpTest.rxTestShareAlbum( rxTest )

	-- testing the happy path

	local result = LrmLibrarySocialModelImp:shareAlbum( 'FAKE', true, {
				TEST_mock = function( )
					return Rx.Observable.just( true )
				end
			} )

	rxTest:expectSingleValue( result.value, { state = true } )

	-- testing the sad path

	local fakeError = "FAILED TO SHARE ALBUM"

	result = LrmLibrarySocialModelImp:shareAlbum( 'FAKE', true, {
				TEST_mock = function( )
					return Rx.Observable.throw( fakeError )
				end
			} )

	rxTest:expectSingleValue(result.value, { state = false, error = fakeError })

end

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

function LrmLibararySocialModelImpTest.rxTestResolveAlbumFromSpace( rxTest )

	-- testing the happy path

	local result = LrmLibrarySocialModelImp:resolveAlbumFromSpace( 'FAKE', {
				TEST_mock = function( _wfCatalog, _spaceId )
					return Rx.Observable.just( true )
				end
			} )

	rxTest:expectSingleValue( result.value, { state = true } )

	-- testing the sad path

	local fakeError = "FAILED TO RESOLVE ALBUM FROM SPACE"

	result = LrmLibrarySocialModelImp:resolveAlbumFromSpace( 'FAKE', {
				TEST_mock = function( _wfCatalog, _spaceId )
					return Rx.Observable.throw( fakeError )
				end
			} )

	rxTest:expectSingleValue(result.value, { state = false, error = fakeError })

end

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

function LrmLibararySocialModelImpTest.rxTestGetSharedAlbumUrl( rxTest )

	-- testing the happy path
	local url = 'www.ilikerabbits.com'
	local result = LrmLibrarySocialModelImp:getSharedAlbumUrl( 'FAKE', {
				TEST_mock = function( )
					return Rx.Observable.just( url )
				end
			} )

	rxTest:expectSingleValue( result.value, { state = true, sharedAlbumUrl = url } )

	-- testing the sad path

	local fakeError = "FAILED TO GET SHARED ALBUM URL"

	result = LrmLibrarySocialModelImp:getSharedAlbumUrl( 'FAKE', {
				TEST_mock = function( )
					return Rx.Observable.throw( fakeError )
				end
			} )

	rxTest:expectSingleValue(result.value, { state = false, error = fakeError })

end

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

if WFPlatformInfo.isDesktop then
	return {}
else
	return WFRxTestCase.wrapSuite( LrmLibararySocialModelImpTest )
end