Skip to content

Commit

Permalink
Merge pull request #1176 from HDInnovations/development
Browse files Browse the repository at this point in the history
(Tests) Staff Controllers
  • Loading branch information
HDVinnie authored Feb 25, 2020
2 parents 8fa0839 + 238482d commit c63487b
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 186 deletions.
48 changes: 48 additions & 0 deletions tests/Feature/Http/Controllers/Staff/CheaterControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Tests\Feature\Http\Controllers\Staff;

use App\Models\Group;
use App\Models\User;
use GroupsTableSeeder;
use Tests\TestCase;

/**
* @see \App\Http\Controllers\Staff\CheaterController
*/
class CheaterControllerTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
}

protected function createStaffUser()
{
return factory(User::class)->create([
'group_id' => function () {
return factory(Group::class)->create([
'is_owner' => true,
'is_admin' => true,
'is_modo' => true,
])->id;
},
]);
}

/**
* @test
*/
public function index_returns_an_ok_response()
{
$this->seed(GroupsTableSeeder::class);

$user = $this->createStaffUser();

$response = $this->actingAs($user)->get(route('staff.cheaters.index'));

$response->assertOk();
$response->assertViewIs('Staff.cheater.index');
$response->assertViewHas('cheaters');
}
}
67 changes: 67 additions & 0 deletions tests/Feature/Http/Controllers/Staff/GiftControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Tests\Feature\Http\Controllers\Staff;

use App\Models\Group;
use App\Models\User;
use GroupsTableSeeder;
use Tests\TestCase;

/**
* @see \App\Http\Controllers\Staff\GiftController
*/
class GiftControllerTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
}

protected function createStaffUser()
{
return factory(User::class)->create([
'group_id' => function () {
return factory(Group::class)->create([
'is_owner' => true,
'is_admin' => true,
'is_modo' => true,
])->id;
},
]);
}

/**
* @test
*/
public function index_returns_an_ok_response()
{
$this->seed(GroupsTableSeeder::class);

$user = $this->createStaffUser();

$response = $this->actingAs($user)->get(route('staff.gifts.index'));

$response->assertOk();
$response->assertViewIs('Staff.gift.index');
}

/**
* @test
*/
public function store_returns_an_ok_response()
{
$this->seed(GroupsTableSeeder::class);

$staff = $this->createStaffUser();
$user = factory(User::class)->create();

$response = $this->actingAs($staff)->post(route('staff.gifts.store'), [
'username' => $user->username,
'seedbonus' => '100',
'invites' => '100',
'fl_tokens' => '100',
]);

$response->assertRedirect(route('staff.gifts.index'));
}
}
146 changes: 146 additions & 0 deletions tests/Feature/Http/Controllers/Staff/GroupControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php

namespace Tests\Feature\Http\Controllers\Staff;

use App\Models\Group;
use App\Models\User;
use GroupsTableSeeder;
use Tests\TestCase;

/**
* @see \App\Http\Controllers\Staff\GroupController
*/
class GroupControllerTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
}

protected function createStaffUser()
{
return factory(User::class)->create([
'group_id' => function () {
return factory(Group::class)->create([
'is_owner' => true,
'is_admin' => true,
'is_modo' => true,
])->id;
},
]);
}

/**
* @test
*/
public function create_returns_an_ok_response()
{
$this->seed(GroupsTableSeeder::class);

$user = $this->createStaffUser();

$response = $this->actingAs($user)->get(route('staff.groups.create'));

$response->assertOk();
$response->assertViewIs('Staff.group.create');
}

/**
* @test
*/
public function edit_returns_an_ok_response()
{
$this->seed(GroupsTableSeeder::class);

$user = $this->createStaffUser();
$group = factory(Group::class)->create();

$response = $this->actingAs($user)->get(route('staff.groups.edit', ['id' => $group->id]));

$response->assertOk();
$response->assertViewIs('Staff.group.edit');
$response->assertViewHas('group');
}

/**
* @test
*/
public function index_returns_an_ok_response()
{
$this->seed(GroupsTableSeeder::class);

$user = $this->createStaffUser();

$response = $this->actingAs($user)->get(route('staff.groups.index'));

$response->assertOk();
$response->assertViewIs('Staff.group.index');
$response->assertViewHas('groups');
}

/**
* @test
*/
public function store_returns_an_ok_response()
{
$this->seed(GroupsTableSeeder::class);

$user = $this->createStaffUser();
$group = factory(Group::class)->make();

$response = $this->actingAs($user)->post(route('staff.groups.store'), [
'name' => $group->name,
'slug' => $group->slug,
'position' => $group->position,
'level' => $group->level,
'color' => $group->color,
'icon' => $group->icon,
'effect' => $group->effect,
'is_internal' => $group->is_internal,
'is_owner' => $group->is_owner,
'is_admin' => $group->is_admin,
'is_modo' => $group->is_modo,
'is_trusted' => $group->is_trusted,
'is_immune' => $group->is_immune,
'is_freeleech' => $group->is_freeleech,
'can_upload' => $group->can_upload,
'is_incognito' => $group->is_incognito,
'autogroup' => $group->autogroup,
]);

$response->assertRedirect(route('staff.groups.index'));
}

/**
* @test
*/
public function update_returns_an_ok_response()
{
$this->seed(GroupsTableSeeder::class);

$user = $this->createStaffUser();
$group = factory(Group::class)->create();

$response = $this->actingAs($user)->post(route('staff.groups.update', ['id' => $group->id]), [
'name' => $group->name,
'slug' => $group->slug,
'position' => $group->position,
'level' => $group->level,
'color' => $group->color,
'icon' => $group->icon,
'effect' => $group->effect,
'is_internal' => $group->is_internal,
'is_owner' => $group->is_owner,
'is_admin' => $group->is_admin,
'is_modo' => $group->is_modo,
'is_trusted' => $group->is_trusted,
'is_immune' => $group->is_immune,
'is_freeleech' => $group->is_freeleech,
'can_upload' => $group->can_upload,
'is_incognito' => $group->is_incognito,
'autogroup' => $group->autogroup,
]);

$response->assertRedirect(route('staff.groups.index'));
}
}

This file was deleted.

48 changes: 0 additions & 48 deletions tests/Todo/Feature/Http/Controllers/Staff/GiftControllerTest.php

This file was deleted.

Loading

0 comments on commit c63487b

Please sign in to comment.