Skip to content

Commit

Permalink
create a unit test for getting ical
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelfolaron committed Sep 21, 2024
1 parent 673296f commit 3136c33
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 5 deletions.
9 changes: 5 additions & 4 deletions app/Domain/Calendar/Services/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 0 additions & 1 deletion blocklist.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand Down
84 changes: 84 additions & 0 deletions tests/Unit/app/Domain/Calendar/Services/CalendarServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Unit\app\Domain\Menu\Repositories;

use Codeception\Test\Unit;
use Leantime\Config\Config;
use Leantime\Core\Configuration\Environment;
use Leantime\Core\Events\EventDispatcher;
use Leantime\Core\Language;
use Leantime\Domain\Calendar\Repositories\Calendar as CalendarRepo;
use Leantime\Domain\Calendar\Services\Calendar;
use Leantime\Domain\Menu\Repositories\Menu;
use Leantime\Domain\Setting\Repositories\Setting;
use Leantime\Domain\Tickets\Services\Tickets;

class CalendarServiceTest extends Unit
{

use \Codeception\Test\Feature\Stub;

protected $calendarRepo;

protected $language;

protected $settingsRepo;

protected $config;

protected $calendar;

/**
* The test object
*
* @var Menu
*/
protected $menu;

protected function _before()
{

$this->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');

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Leantime\Domain\Setting\Repositories\Setting;
use Leantime\Domain\Tickets\Services\Tickets;



class MenuRepositoryTest extends Unit
{

Expand Down Expand Up @@ -45,6 +47,7 @@ protected function _before()
ticketsService:$ticketService
);


}

protected function _after()
Expand Down

0 comments on commit 3136c33

Please sign in to comment.