Skip to content

Commit

Permalink
feat(registration-link): generate registration link #63
Browse files Browse the repository at this point in the history
  • Loading branch information
DumbergerL committed Feb 11, 2022
1 parent 9fda4ef commit 8324b45
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/Models/PublicGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace CTApi\Models;


use CTApi\CTConfig;
use CTApi\Models\Traits\FillWithData;

class PublicGroup extends Group
Expand Down Expand Up @@ -31,6 +32,21 @@ protected function fillNonArrayType(string $key, $value): void
parent::fillNonArrayType($key, $value);
}

public function generateRegistrationLink(string $groupHash): string
{
$url = CTConfig::getApiUrl();

if ('/' != substr($url, -1)) {
$url .= '/';
}

$url .= 'publicgroup/' . $this->getId();

$url .= '?hash=' . $groupHash;

return $url;
}

/**
* @return string|null
*/
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/Requests/PublicGroupRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ public function testGetPublicGroup()

$foundGroup = null;
foreach ($publicGroup->getGroups() as $group) {
print_r($group);
if ($group->getId() == $this->groupId) {
$foundGroup = $group;
}
}

print_r($foundGroup);

$this->assertNotNull($foundGroup);
$this->assertEquals($this->groupName, $foundGroup->getName());

Expand Down
30 changes: 30 additions & 0 deletions tests/unit/Models/PublicGroupTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php


namespace Tests\Unit\Models;


use CTApi\CTConfig;
use CTApi\Models\PublicGroup;
use PHPUnit\Framework\TestCase;

class PublicGroupTest extends TestCase
{

public function testGenerateRegistrationLink()
{
// WITHOUT SLASH IN THE END OF URL
CTConfig::setApiUrl("https://test.church.tools");

$publicGroup = new PublicGroup();
$publicGroup->setId("21");

$this->assertEquals("https://test.church.tools/publicgroup/21?hash=EXAMPLEHASHCODE", $publicGroup->generateRegistrationLink("EXAMPLEHASHCODE"));

// WITH SLASH IN THE END OF URL
CTConfig::setApiUrl("https://test.church.tools/");

$this->assertEquals("https://test.church.tools/publicgroup/21?hash=EXAMPLEHASHCODE", $publicGroup->generateRegistrationLink("EXAMPLEHASHCODE"));

}
}

0 comments on commit 8324b45

Please sign in to comment.