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

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'

	-- Lrmobile_models
local LrmCatalogTestHelper = require 'LrmCatalogTestHelper'
local LrmAlbumUtils = require 'LrmAlbumUtils'

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

local LrmAlbumUtilsTest = {}

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

local catalog

local TEST_TIMEOUT = 10

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

function LrmAlbumUtilsTest.setUp()

	catalog = LrmCatalogTestHelper.makeCatalogService( )

end

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

function LrmAlbumUtilsTest.tearDown()

	if catalog then

		catalog:close()
		catalog = nil

	end

end

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

function LrmAlbumUtilsTest.rxTestIsAlbumShared( rxTest )

	rxTest:setTimeLimit( TEST_TIMEOUT )

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

	rxTest:expectSingleValue( catalog: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( catalog: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( catalog:indexStore(), kAlbumId ) )
	rxTest:finally( function()
		isAlbumSharedObs:dispose()
	end )

	isAlbumSharedObs:expectData( true )

	rxTest:expectSingleValue( catalog: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 kSpaceId = KSIdGenerator.uuidInLowercaseHex()
	local kSpaceAlbumId = KSIdGenerator.uuidInLowercaseHex()
	local kAlbumId = KSIdGenerator.uuidInLowercaseHex()


	rxTest:expectSingleValue( catalog: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( catalog: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( catalog:indexStore() ) )
	rxTest:finally( function()
		hasAnySharedAlbumsObs:dispose()
	end )

	hasAnySharedAlbumsObs:expectData( true )

	rxTest:expectSingleValue( catalog: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 )

