Skip to content

Commit

Permalink
Add team tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner committed Jun 11, 2019
1 parent da3d772 commit 85631c3
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Listeners/CreatedTeamListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ class CreatedTeamListener
{
public function handle($team)
{
auth()->user()->teams()->save($team);
$team->members()->syncWithoutDetaching([auth()->user()->id]);
}
}
10 changes: 10 additions & 0 deletions src/Traits/Governing.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public function ownedTeams() : HasMany
);
}

public function teams() : BelongsToMany
{
return $this->belongsToMany(
config('genealabs-laravel-governor.models.team'),
"governor_team_user",
"user_id",
"team_id"
);
}

public function getPermissionsAttribute() : Collection
{
$permissionClass = config("genealabs-laravel-governor.models.permission");
Expand Down
1 change: 0 additions & 1 deletion tests/Integration/Notifications/TeamInvitationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public function setUp() : void

public function testTeamInvitationNotification()
{

$invitation = (new TeamInvitation)->create([
"team_id" => $this->team->id,
"email" => "test1@example.com",
Expand Down
56 changes: 56 additions & 0 deletions tests/Integration/TeamTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php namespace GeneaLabs\LaravelGovernor\Tests\Integration\Notifications;

use GeneaLabs\LaravelGovernor\Permission;
use GeneaLabs\LaravelGovernor\Team;
use GeneaLabs\LaravelGovernor\TeamInvitation;
use GeneaLabs\LaravelGovernor\Tests\Fixtures\User;
use GeneaLabs\LaravelGovernor\Tests\UnitTestCase;

class TeamTest extends UnitTestCase
{
public function setUp() : void
{
parent::setUp();

$this->user = factory(User::class)->create();
$this->actingAs($this->user);
$this->team = (new Team)->create([
"name" => "Test Team",
"description" => "bla bla bla",
]);
$this->user->teams()->attach($this->team);
$this->team->load("members");
}

public function testMembersRelationship()
{
$this->assertTrue($this->team->members->contains($this->user));
}

public function testOwnedByRelationship()
{
$this->assertEquals($this->team->ownedBy->toArray(), $this->user->toArray());
}

public function testInvitationsRelationship()
{
$invitation = (new TeamInvitation)->create([
"team_id" => $this->team->id,
"email" => "test1@example.com",
]);

$this->assertTrue($this->team->invitations->contains($invitation));
}

public function testPermissionsRelationship()
{
$permission = (new Permission)->firstOrCreate([
"team_id" => $this->team->id,
"entity_name" => "author",
"action_name" => "create",
"ownership_name" => "any",
]);

$this->assertTrue($this->team->permissions->contains($permission));
}
}
Binary file modified tests/database/database.sqlite
Binary file not shown.

0 comments on commit 85631c3

Please sign in to comment.