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

LrmSyncInfoModelImpTest.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2021 Adobe
All Rights Reserved.

NOTICE: All information contained herein is, and remains
the property of Adobe and its suppliers, if any. The intellectual
and technical concepts contained herein are proprietary to Adobe
and its suppliers and are protected by all applicable intellectual
property laws, including trade secret and copyright laws.
Dissemination of this information or reproduction of this material
is strictly forbidden unless prior written permission is obtained
from Adobe.

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

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

	-- com.adobe.wichitafoundation.core.utils
local KSIdGenerator = require 'KSIdGenerator'
local WFPlatformInfo = require 'WFPlatformInfo'

-- This model test is only valid on the mobile platforms.

if not WFPlatformInfo.isMobile() then
	return {}
end

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

	-- WF.lrmobile
local LrmSyncClientImp = require 'LrmSyncClientImp' 

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

local LrmSyncInfoModelImpTest = {}

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

function LrmSyncInfoModelImpTest.rxTestSyncDiagnostics( rxTest )

	-- This test verifies the model is hooked up correctly, but does not validate
	-- the contents of the response. That's okay though, because the sync diagnostic
	-- APIs are thoroughly covered in the class-based unit tests.

	local kCatalogId = KSIdGenerator.uuidInLowercaseHex()
	local kUserId = KSIdGenerator.uuidInLowercaseHex()
	
	local wfCatalogSpec = WFCatSpecMock( kCatalogId, kUserId, rxTest, {} )

	local indexSpecScript = 'LrmCatalogIndexDefinitions.lua'

	local wfCatalog = WFCatMockCatalog.createWFCatalogForTestWithSpec( rxTest, wfCatalogSpec, nil, indexSpecScript )

	local wfCatSpec = wfCatalog:ozCatalogSpec()

	local options = {
		serverBase = 'foo',
		userId = wfCatalog:ozUserId(),
		userInfoCacheFolder = 'bar',
		catalogId = wfCatalog:ozCatalogId(),
		rootCatalogPath = wfCatalog:fileSpec():rootPath(),
		docStorePath = wfCatalog:fileSpec():docStorePath(),
		indexSpecScript = 'LrmCatalogIndexDefinitions.lua',
		rxTest = rxTest,
		wfCatalog = wfCatalog,
		wfCatSpec = wfCatSpec,
		wfCatUser = wfCatSpec:wfOzUser()
	}
	
	local syncClient = LrmSyncClientImp( options )
			
	local diagnosticsStream = rxTest:observe( syncClient:syncDiagnostics( 0.1 ) )
	
	diagnosticsStream:expectDataWithinTime( 5,
		{
			binaryUploaderSyncDiagnostics = {
				documentsNeedingBinaryUpload = 0,
				inFlightUploads = {},
				isCurrentlySyncing = false,
				numberOfInFlightUploads = 0,
				numberOfScheduledBinaryUploads = 0,
				recentlyUploaded = {},
				summaryStr = "Catalog: Uploaded 0 binaries to Oz.",
				uploadsByType = {},
			},
			metadataSyncDiagnostics = {
				catalogPullerSyncDiagnostics = {
					documentsSyncedByType = {},
					isCurrentlySyncing = false,
					recentlySyncedDocIds = {},
					summaryStr = "Catalog Puller synced down 0 updates, 0 deletions from Oz.",
					totalDocumentsSynced = 0,
				},
				catalogPusherSyncDiagnostics = {
					docsFilteredDueToErrorByType = {},
					documentsSyncedByType = {},
					isCurrentlySyncing = false,
					numberOfDocsRemainingToSync = 0,
					pausedBySynchronizedOperation = 0,
					recentlySyncedDocIds = {},
					summaryStr = "Catalog Pusher synced up 0 new docs, 0 updates, 0 deletions to Oz.",
					totalDocumentsSynced = 0,
				},
				spaceFeedsManagerSyncDiagnostics = {
					feedOfFeedsPullerSyncDiagnostics = {
						documentsSyncedByType = {},
						isCurrentlySyncing = false,
						recentlySyncedDocIds = {},
						summaryStr = "Feed-of-Feeds Puller synced down 0 updates, 0 deletions from Oz.",
						totalDocumentsSynced = 0,
					},
					spacePullersSyncDiagnostics = {},
					spacePusherSyncDiagnostics = {
						docsFilteredDueToErrorByType = {},
						documentsSyncedByType = {},
						isCurrentlySyncing = false,
						numberOfDocsRemainingToSync = 0,
						pausedBySynchronizedOperation = 0,
						recentlySyncedDocIds = {},
						summaryStr = "Space Pusher synced up 0 new docs, 0 updates, 0 deletions to Oz.",
						totalDocumentsSynced = 0,
					}
				}
			}		
		} )
	
	diagnosticsStream:dispose()
	
end

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

return WFRxTestCase.wrapSuite( 'LrmSyncInfoModelImpTest', LrmSyncInfoModelImpTest )
