--[[----------------------------------------------------------------------------
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 LrmCatCollaboration = require 'LrmCatCollaboration'
local KSIdGenerator = require 'KSIdGenerator'
local WFCatAlbumTestUtils = require 'WFCatAlbumTestUtils'

local WFCatMockCatalog = require 'WFCatMockCatalog'
local Rx = require 'Rx'
local WFRxTestCase = require 'WFRxTestCase'
local LrmLibrarySocialModelImp = require 'LrmLibrarySocialModelImp'
local WFPlatformInfo = require 'WFPlatformInfo'

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

local LrmLibararySocialModelImpTest = {}

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

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 )

	local wfCatalog = WFCatMockCatalog.createFakeWFCatalog( rxTest )

	local docStore = wfCatalog:docStore()

	local catalogService = {
		_wfCatalog = wfCatalog
	}

	local albumId = KSIdGenerator.uuidInLowercaseHex()

	local albumDoc = WFCatAlbumTestUtils.createAlbumDocument( rxTest, wfCatalog, albumId, {} )[ 1 ]

	rxTest:waitFor( docStore:applyOverlay( albumDoc ) )

	local spaceId = rxTest:getFirstValue( LrmCatCollaboration.shareAlbum( wfCatalog, albumId ) )

	rxTest:expectSingleValue( 
		LrmLibrarySocialModelImp.resolveAlbumFromSpace(catalogService, spaceId).value, 
		albumId )

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( 'LrmLibrarySocialModelImpTest', LrmLibararySocialModelImpTest )
end