From 3136c33c1317a00f774b3fc8dc38d5737acb89a4 Mon Sep 17 00:00:00 2001 From: Marcel Folaron Date: Fri, 20 Sep 2024 22:17:07 -0400 Subject: [PATCH] create a unit test for getting ical --- app/Domain/Calendar/Services/Calendar.php | 9 +- blocklist.json | 1 - .../Calendar/Services/CalendarServiceTest.php | 84 +++++++++++++++++++ .../Menu/Repositories/MenuRepositoryTest.php | 3 + 4 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 tests/Unit/app/Domain/Calendar/Services/CalendarServiceTest.php diff --git a/app/Domain/Calendar/Services/Calendar.php b/app/Domain/Calendar/Services/Calendar.php index 84295d6fc..936dd0524 100644 --- a/app/Domain/Calendar/Services/Calendar.php +++ b/app/Domain/Calendar/Services/Calendar.php @@ -436,12 +436,13 @@ public function getCalendar(int $userId): array public function getICalUrl() { - if(empty(session("userdata.id"))) { - throw new \Exception("Session id is not set."); + $userId = -1; + if(!empty(session("userdata.id"))) { + $userId = session("userdata.id"); } - $userHash = hash('sha1', session("userdata.id") . $this->config->sessionPassword); - $icalHash = $this->settingsRepo->getSetting("usersettings." . session("userdata.id") . ".icalSecret"); + $userHash = hash('sha1', $userId . $this->config->sessionPassword); + $icalHash = $this->settingsRepo->getSetting("usersettings." . $userId. ".icalSecret"); if(empty($icalHash)) { throw new \Exception("User has no ical hash"); diff --git a/blocklist.json b/blocklist.json index bbfd085d3..62a687d05 100644 --- a/blocklist.json +++ b/blocklist.json @@ -69,7 +69,6 @@ "tw-p-[10px]", "tw-p-m", "tw-p-none", - "tw-px-2", "tw-px-2.5", "tw-px-4", "tw-px-[15px]", diff --git a/tests/Unit/app/Domain/Calendar/Services/CalendarServiceTest.php b/tests/Unit/app/Domain/Calendar/Services/CalendarServiceTest.php new file mode 100644 index 000000000..f56825cb1 --- /dev/null +++ b/tests/Unit/app/Domain/Calendar/Services/CalendarServiceTest.php @@ -0,0 +1,84 @@ +calendarRepo = $this->make(CalendarRepo::class); + $this->language = $this->make(Language::class); + $this->settingsRepo = $this->make(Setting::class, [ + "getSetting" => "secret" + ]); + $this->config = $this->make(Environment::class, [ + "sessionPassword" => "123abc" + ]); + + //Load class to be tested + $this->calendar = new \Leantime\Domain\Calendar\Services\Calendar( + calendarRepo: $this->calendarRepo, + language: $this->language, + settingsRepo: $this->settingsRepo, + config: $this->config + + ); + + } + + protected function _after() + { + $this->calendar = null; + } + + //Write tests below + + /** + * Test GetMenuTypes method + */ + public function testGetICalUrl() { + + + + //Sha is generated from id -1 and sessionpassword 123abc + $sha = "ba62fbd0d08f6607d6b3213dcccc1b50f4d82f19"; + $url = $this->calendar->getICalUrl(1); + + $this->assertEquals(BASE_URL . "/calendar/ical/secret_" . $sha, $url, 'hash is not correct'); + + } + + +} diff --git a/tests/Unit/app/Domain/Menu/Repositories/MenuRepositoryTest.php b/tests/Unit/app/Domain/Menu/Repositories/MenuRepositoryTest.php index a7f00c0cc..bc412db8a 100644 --- a/tests/Unit/app/Domain/Menu/Repositories/MenuRepositoryTest.php +++ b/tests/Unit/app/Domain/Menu/Repositories/MenuRepositoryTest.php @@ -11,6 +11,8 @@ use Leantime\Domain\Setting\Repositories\Setting; use Leantime\Domain\Tickets\Services\Tickets; + + class MenuRepositoryTest extends Unit { @@ -45,6 +47,7 @@ protected function _before() ticketsService:$ticketService ); + } protected function _after()