# Copyright (c) 2018, XhiveFramework Technologies and Contributors
# License: MIT. See LICENSE
import xhiveframework
from xhiveframework.tests.utils import XhiveFrameworkTestCase


class TestViewLog(XhiveFrameworkTestCase):
	def tearDown(self):
		xhiveframework.set_user("Administrator")

	def test_if_user_is_added(self):
		ev = xhiveframework.get_doc(
			{
				"doctype": "Event",
				"subject": "test event for view logs",
				"starts_on": "2018-06-04 14:11:00",
				"event_type": "Public",
			}
		).insert()

		xhiveframework.set_user("test@example.com")

		from xhiveframework.desk.form.load import getdoc

		# load the form
		getdoc("Event", ev.name)
		a = xhiveframework.get_value(
			doctype="View Log",
			filters={"reference_doctype": "Event", "reference_name": ev.name},
			fieldname=["viewed_by"],
		)

		self.assertEqual("test@example.com", a)
		self.assertNotEqual("test1@example.com", a)
