Skip to content

Commit

Permalink
Testes para auth de fila
Browse files Browse the repository at this point in the history
  * Seis deles estão fracassando por prováveis erros de auth;
  * Não cobre ainda os gates de gerente;
  * Não cobre alguns stores() como admin por precisar mexer com BD.
  • Loading branch information
wgnann committed Nov 16, 2020
1 parent 2abad6a commit 695d968
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 22 deletions.
21 changes: 0 additions & 21 deletions tests/Feature/ExampleTest.php

This file was deleted.

214 changes: 214 additions & 0 deletions tests/Unit/FilaAuthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
<?php

namespace Tests\Unit;

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class FilaAuthTest extends TestCase
{
# auxiliares
private function deslogado($method, $url)
{
$response = $this->$method($url);
$response->assertStatus(302);
$this->assertStringContainsString('/login</title>', $response->content());
}

private function noadmin403($method, $url)
{
$user = User::factory()->make();
$this->actingAs($user);
$response = $this->$method($url);
$response->assertStatus(403);
}

private function admin200($method, $url)
{
$user = User::factory()->make(['is_admin' => 1]);
$this->actingAs($user);
session(['is_admin' => 1]);
$response = $this->$method($url);
$response->assertStatus(200);
# o restante das checagens é feita em cada teste
return $response;
}

#
# index
#
public function testFilaIndexDeslogado()
{
$this->deslogado('get', '/filas');
}

public function testFilaIndexNoAdmin()
{
$this->noadmin403('get', '/filas');
}

public function testFilaIndexAdmin()
{
$response = $this->admin200('get', '/filas');
$this->assertStringContainsString('Filas</span>', $response->content());
}

#
# store
#
public function testFilaStoreDeslogado()
{
$this->deslogado('post', '/filas');
}

public function testFilaStoreNoAdmin()
{
$this->noadmin403('post', '/filas');
}

# precisa de bd
# TODO public function testFilaStoreAdmin() {}

#
# create
#
public function testFilaCreateDeslogado()
{
$this->deslogado('get', '/filas/create');
}

public function testFilaCreateNoAdmin()
{
$this->noadmin403('/filas/create', 'get');
}

public function testFilaCreateAdmin()
{
$response = $this->admin200('get', '/filas/create');
$this->assertStringContainsString('Criar nova fila</span>', $response->content());
}

#
# show
#
public function testShowDeslogado()
{
$this->deslogado('get', '/filas/1');
}

public function testShowNoAdmin()
{
$this->noadmin403('get', '/filas/1');
}

public function testShowAdmin()
{
$response = $this->admin200('get', '/filas/1');
$this->assertStringContainsString('Setor:', $response->content());
}

#
# update
#
public function testUpdateDeslogado()
{
$this->deslogado('put', '/filas/1');
}

public function testUpdateNoAdmin()
{
$this->noadmin403('put', '/filas/1');
}

# precisa de bd
# TODO public function testUpdateAdmin() {}

#
# destroy
#
public function testDestroyDeslogado()
{
$this->deslogado('delete', '/filas/1');
}

public function testDestroyNoAdmin()
{
$this->noadmin403('delete', '/filas/1');
}

# precisa de bd
# TODO public function testDestroyAdmin() {}

#
# edit teoricamente está desativado
#

#
# storePessoa
#
public function testStorePessoaDeslogado()
{
$this->deslogado('post', '/filas/1/pessoas');
}

public function testStorePessoaNoAdmin()
{
$this->noadmin403('post', '/filas/1/pessoas');
}

# precisa de bd
# TODO public function testStorePessoaAdmin() {}

#
# destroyPessoa
#
public function testDestroyPessoaDeslogado()
{
$this->deslogado('delete', '/filas/1/pessoas/1');
}

public function testDestroyPessoaNoAdmin()
{
$this->noadmin403('delete', '/filas/1/pessoas/1');
}

# precisa de bd
# TODO public function testDestroyPessoaAdmin() {}

#
# createTemplate
#
public function testCreateTemplateDeslogado()
{
$this->deslogado('get', '/filas/1/template');
}

public function testCreateTemplateNoAdmin()
{
$this->noadmin403('get', '/filas/1/template');
}

public function testCreateTemplateAdmin()
{
$response = $this->admin200('get', '/filas/1/template');
$this->assertStringContainsString('Criar template para a fila:', $response->content());
}

#
# storeTemplate
#
public function testStoreTemplateDeslogado()
{
$this->deslogado('post', '/filas/1/template');
}

public function testStoreTemplateNoAdmin()
{
$this->noadmin403('post', '/filas/1/template');
}

# precisa de bd
# TODO public function testStoreTemplateAdmin()
}
2 changes: 1 addition & 1 deletion tests/Unit/JSONFormsTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests\Feature;
namespace Tests\Unit;

use App\Models\Chamado;
use App\Models\Fila;
Expand Down

0 comments on commit 695d968

Please sign in to comment.