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

ADOBE CONFIDENTIAL
------------------
Copyright 2015 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.

----------------------------------------------------------------------------]]--

	-- WF.core.self_test
local WFRxTestCase = require 'WFRxTestCase'

	-- WF.core.utils
local KSIdGenerator = require 'KSIdGenerator'

	-- WF.oz_client.managed_catalog
local WFCatMockCatalog = require 'WFCatMockCatalog'

	-- Lrmobile_models
local LrmAlbumUtils = require 'LrmAlbumUtils'

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

local LrmAlbumUtilsTest = {}

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

local TEST_TIMEOUT = 10

local catalogOptions = {
	indexDefinitions = 'LrmCatalogIndexDefinitions.lua'
}

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

function LrmAlbumUtilsTest.rxTestIsAlbumShared( rxTest )

	rxTest:setTimeLimit( TEST_TIMEOUT )

	local wfCatalog = WFCatMockCatalog.createFakeWFCatalog( rxTest, nil, nil, catalogOptions )

	local kSpaceId = KSIdGenerator.uuidInLowercaseHex()
	local kSpaceAlbumId = KSIdGenerator.uuidInLowercaseHex()
	local kAlbumId = KSIdGenerator.uuidInLowercaseHex()

	rxTest:expectSingleValue( wfCatalog:docStore():applyOverlay {
			type = 'space',
			_id = kSpaceId,
			subtype = 'shared',
			private = false,
			download = false,
			updated = '2012-08-15T15:22:29',
			created = '2012-08-15T15:22:29',
		},
		':ignore:' )

	rxTest:expectSingleValue( wfCatalog:docStore():applyOverlay {
			type = 'space_album',
			_id = kSpaceAlbumId,
			album = {
				id = kAlbumId,
			},
			space = {
				id = kSpaceId,
			},
			updated = '2012-08-15T15:22:29',
		},
		':ignore:' )

	local isAlbumSharedObs = rxTest:observe( LrmAlbumUtils.isAlbumShared( wfCatalog:indexStore(), kAlbumId ) )
	rxTest:finally( function()
		isAlbumSharedObs:dispose()
	end )

	isAlbumSharedObs:expectData( true )

	rxTest:expectSingleValue( wfCatalog:docStore():applyOverlay{
			type = 'space',
			_id = kSpaceId,
			private = true,
			download = false,
			updated = '2012-08-15T15:22:29',
			created = '2012-08-15T15:22:29',
		},
		':ignore:' )

	isAlbumSharedObs:expectData( false )

end

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

function LrmAlbumUtilsTest.rxTestHasSharedAlbums( rxTest )

	rxTest:setTimeLimit( TEST_TIMEOUT )

	local wfCatalog = WFCatMockCatalog.createFakeWFCatalog( rxTest, nil, nil, catalogOptions )

	local kSpaceId = KSIdGenerator.uuidInLowercaseHex()
	local kSpaceAlbumId = KSIdGenerator.uuidInLowercaseHex()
	local kAlbumId = KSIdGenerator.uuidInLowercaseHex()


	rxTest:expectSingleValue( wfCatalog:docStore():applyOverlay{
			type = 'space',
			_id = kSpaceId,
			subtype = 'shared',
			private = false,
			download = false,
			updated = '2012-08-15T15:22:29',
			created = '2012-08-15T15:22:29',
		},
		':ignore:' )

	rxTest:expectSingleValue( wfCatalog:docStore():applyOverlay {
			type = 'space_album',
			_id = kSpaceAlbumId,
			album = {
				id = kAlbumId,
			},
			space = {
				id = kSpaceId,
			},
			updated = '2012-08-15T15:22:29',
		},
		':ignore:' )


	local hasAnySharedAlbumsObs = rxTest:observe( LrmAlbumUtils.hasAnySharedAlbums( wfCatalog:indexStore() ) )
	rxTest:finally( function()
		hasAnySharedAlbumsObs:dispose()
	end )

	hasAnySharedAlbumsObs:expectData( true )

	rxTest:expectSingleValue( wfCatalog:docStore():applyOverlay {
			_id = kSpaceId,
			private = true,
			download = false,
			updated = '2012-08-15T15:22:29',
			created = '2012-08-15T15:22:29',
		},
		':ignore:' )

	hasAnySharedAlbumsObs:expectData( false )

end

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

return WFRxTestCase.wrapSuite( 'LrmAlbumUtilsTest', LrmAlbumUtilsTest )

