# Copyright (c) 2018, InfluxFramework LLC
# License: MIT. See LICENSE
import influxframework
from influxframework.tests.utils import InfluxFrameworkTestCase


class TestViewLog(InfluxFrameworkTestCase):
	def tearDown(self):
		influxframework.set_user("Administrator")

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

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

		from influxframework.desk.form.load import getdoc

		# load the form
		getdoc("Event", ev.name)
		a = influxframework.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)
