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

WFCatCollaboratorTest.lua

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

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

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

local WFRxTestCase = require 'WFRxTestCase'

local KSIdGenerator = require 'KSIdGenerator'
local WFCatCollaborator = require 'WFCatCollaborator'
local WFCatMockCatalog = require 'WFCatMockCatalog'
local WFRxRunUntilDone = require 'WFRxRunUntilDone'

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

local WFCatCollaboratorTest = {}

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

local function createFeedbackUser( i )
	return {
		_id = KSIdGenerator.uuidInLowercaseHex(),
		type = 'feedbackuser',
		
		_serverProvidedMetadata = {
			full_name = string.format( 'Full Name %s', tostring( i ) ),
			email = string.format( 'person_%s@gmail.com', tostring( i ) ),
		},
	}
end

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

function WFCatCollaboratorTest.rxTestBasic( rxTest )

	rxTest:setTimeLimit( 3 )
	
	local catalog = WFCatMockCatalog.createFakeWFCatalog( rxTest )
	local docStore = catalog:docStore()
	
	local allCollaborators =  rxTest:observe( WFCatCollaborator.getAllCollaborators( catalog ) )
	
	allCollaborators:expectDataWithinTime( 3, {} )

	local feedbackUsers = {
		createFeedbackUser( 1 ),
		createFeedbackUser( 2 ),
	}
	
	feedbackUsers[ 1 ]._spaceId = 'dummy_space'
	
	docStore:bulkSetDocValue( feedbackUsers ):call( WFRxRunUntilDone )
	
	allCollaborators:expectDataWithinTime( 3, {
		[ feedbackUsers[ 1 ]._id ] = {
			email = feedbackUsers[ 1 ]._serverProvidedMetadata.email,
			fullName = feedbackUsers[ 1 ]._serverProvidedMetadata.full_name,
			spaceId = 'dummy_space'
		},
		[ feedbackUsers[ 2 ]._id ] = {
			email = feedbackUsers[ 2 ]._serverProvidedMetadata.email,
			fullName = feedbackUsers[ 2 ]._serverProvidedMetadata.full_name,
		},
	} )
	
end

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

return WFRxTestCase.wrapSuite( 'WFCatCollaboratorTest', WFCatCollaboratorTest )
