mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-08-19 01:46:03 +02:00
initial commit
This commit is contained in:
108
tests/Unit/APITest.php
Normal file
108
tests/Unit/APITest.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class APITest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExample()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* test Account creation via API
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAccountCreation()
|
||||
{
|
||||
$response = $this->json('POST', '/api/account', [
|
||||
'name' => 'Unit Test Account',
|
||||
'email' => str_random(10) . '@demo.com',
|
||||
'password' => '12345',
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)->assertJsonStructure([
|
||||
'success' => ['token', 'name']
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)->assertJson([
|
||||
'status' => true,
|
||||
'message' => 'Category Created'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* test User login via API
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUserLogin()
|
||||
{
|
||||
$response = $this->json('POST', '/api/login', [
|
||||
'email' => 'demo@demo.com',
|
||||
'password' => 'secret'
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)->assertJsonStructure([
|
||||
'success' => ['token']
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* test Account index fetching via API
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAccountFetch()
|
||||
{
|
||||
$user = \App\User::find(1);
|
||||
|
||||
$response = $this->actingAs($user, 'api')
|
||||
->json('GET', '/api/account')
|
||||
->assertStatus(200)->assertJsonStructure([
|
||||
'*' => [
|
||||
'id',
|
||||
'name',
|
||||
'secret',
|
||||
'icon',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at'
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test Account deletion via API
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function testAccountDeletion()
|
||||
{
|
||||
$user = \App\User::find(1);
|
||||
|
||||
$category = \App\Account::create([
|
||||
'name' => 'To be deleted',
|
||||
'secret' => 'To be deleted'
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user, 'api')
|
||||
->json('DELETE', "/api/account/{$category->id}")
|
||||
->assertStatus(200)->assertJson([
|
||||
'status' => true,
|
||||
'message' => 'Account Deleted'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
19
tests/Unit/ExampleTest.php
Normal file
19
tests/Unit/ExampleTest.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class ExampleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBasicTest()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user