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

ADOBE CONFIDENTIAL
------------------
Copyright 2016 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 KSPathUtils = require 'KSPathUtils'

	-- WF.sqlite.doc_store
local WFRxDocStoreImp = require 'WFRxDocStoreImp'

local WFOldWFDocStoreMigratorImp = require 'WFOldWFDocStoreMigratorImp'

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

-- @mark WFOldWFDocStoreMigratorTest namespace

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

local WFOldWFDocStoreMigratorTest = {}

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

function WFOldWFDocStoreMigratorTest.rxTestMigrateUserCache( rxTest )

	local testDataPath = KSPathUtils.getStandardFilePath( "testdata" )
	testDataPath = KSPathUtils.child( testDataPath, 'old-oz-docstore-migrator' )
	
	local wfDocStorePath = KSPathUtils.child( testDataPath, 'wfdocstore-oz-user-6716b07345dcfb25b6279bb73ad9c29f' )
	
	local rxDocStoreImp = WFRxDocStoreImp( ':memory:' )
	
	local migrator = WFOldWFDocStoreMigratorImp( rxDocStoreImp, wfDocStorePath )
	
	rxTest:expectEqual( migrator:sourceDocumentCount(), 7 )
	
	rxTest:expectEqual( migrator:runMigration(), 2 )
	
	rxTest:expectSingleValue( 
		
		rxDocStoreImp:docValue( '6716b07345dcfb25b6279bb73ad9c29f' )
			:map( function( docValue )
			
				return docValue.email, docValue._localOnly.managedCatalogId
				
			end ),
			
		'pkamin+test109@adobetest.com', '9ce24edf95c84deb9a35b79eabd3290e' )
		
	rxTest:finally( function()
	
		migrator:close()
		
	end )

end

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

-- FIXME [jandrew 3/27/2018]: This test suite fails on Android.
local WFPlatformInfo = require 'WFPlatformInfo'

if WFPlatformInfo.isAndroid then
	return {}
else
	return WFRxTestCase.wrapSuite( WFOldWFDocStoreMigratorTest )
end
