# Copyright (c) 2018, JINGROW and Contributors
# License: MIT. See LICENSE
import jingrow
from jingrow.tests.utils import JingrowTestCase


class TestViewLog(JingrowTestCase):
	def tearDown(self):
		jingrow.set_user("Administrator")

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

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

		from jingrow.desk.form.load import getpage

		# load the form
		getpage("Event", ev.name)
		a = jingrow.get_value(
			pagetype="View Log",
			filters={"reference_pagetype": "Event", "reference_name": ev.name},
			fieldname=["viewed_by"],
		)

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