mirror of
https://github.com/crater-invoice/crater.git
synced 2025-12-16 02:12:54 -05:00
build version 400
This commit is contained in:
@@ -1,138 +1,91 @@
|
||||
<?php
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Crater\User;
|
||||
use Crater\TaxType;
|
||||
use Laravel\Passport\Passport;
|
||||
use SettingsSeeder;
|
||||
use Crater\Models\User;
|
||||
use Crater\Models\TaxType;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Crater\Http\Requests\TaxTypeRequest;
|
||||
use Crater\Http\Controllers\V1\Settings\TaxTypesController;
|
||||
|
||||
class TaxTypeTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
use function Pest\Laravel\{postJson, putJson, getJson, deleteJson};
|
||||
|
||||
protected $user;
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->seed();
|
||||
$this->seed(SettingsSeeder::class);
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->company_id,
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->company_id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get tax types', function () {
|
||||
$response = getJson('api/v1/tax-types');
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('create tax type', function () {
|
||||
$taxType = TaxType::factory()->raw();
|
||||
|
||||
postJson('api/v1/tax-types', $taxType);
|
||||
|
||||
$this->assertDatabaseHas('tax_types', $taxType);
|
||||
});
|
||||
|
||||
test('store validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
TaxTypesController::class,
|
||||
'store',
|
||||
TaxTypeRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('get tax type', function () {
|
||||
$taxType = TaxType::factory()->create();
|
||||
|
||||
$response = getJson('api/v1/tax-types/' . $taxType->id);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'taxType' => $taxType->toArray()
|
||||
]);
|
||||
Passport::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
/** @test */
|
||||
public function testGetTaxTypes()
|
||||
{
|
||||
$response = $this->json('GET', 'api/tax-types');
|
||||
test('update tax type', function () {
|
||||
$taxType = TaxType::factory()->create();
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
$taxType1 = TaxType::factory()->raw();
|
||||
|
||||
/** @test */
|
||||
public function testCreateTaxType()
|
||||
{
|
||||
$taxType = factory(TaxType::class)->raw();
|
||||
$response = putJson('api/v1/tax-types/' . $taxType->id, $taxType1);
|
||||
|
||||
$response = $this->json('POST', 'api/tax-types', $taxType);
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'taxType' => $taxType1
|
||||
]);
|
||||
});
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'taxType' => $taxType
|
||||
]);
|
||||
}
|
||||
test('update validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
TaxTypesController::class,
|
||||
'update',
|
||||
TaxTypeRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
/** @test */
|
||||
public function testCreateTaxTypeRequiresName()
|
||||
{
|
||||
$taxType = factory(TaxType::class)->raw(['name' => '']);
|
||||
test('delete tax type', function () {
|
||||
$taxType = TaxType::factory()->create();
|
||||
|
||||
$response = $this->json('POST', 'api/tax-types', $taxType);
|
||||
$response = deleteJson('api/v1/tax-types/' . $taxType->id);
|
||||
|
||||
$response->assertStatus(422)->assertJsonValidationErrors(['name']);
|
||||
}
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'success' => true
|
||||
]);
|
||||
|
||||
/** @test */
|
||||
public function testCreateTaxTypeRequiresPercent()
|
||||
{
|
||||
$taxType = factory(TaxType::class)->raw(['percent' => '']);
|
||||
|
||||
$response = $this->json('POST', 'api/tax-types', $taxType);
|
||||
|
||||
$response->assertStatus(422)->assertJsonValidationErrors(['percent']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function testGetEditTaxTypeData()
|
||||
{
|
||||
$taxType = factory(TaxType::class)->create();
|
||||
|
||||
$response = $this->json('GET', 'api/tax-types/'.$taxType->id.'/edit');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'taxType' => $taxType->toArray()
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function testUpdateTaxType()
|
||||
{
|
||||
$taxType = factory(TaxType::class)->create();
|
||||
|
||||
$taxType2 = factory(TaxType::class)->raw();
|
||||
|
||||
$response = $this->json('PUT', 'api/tax-types/'.$taxType->id, $taxType2);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'taxType' => $taxType2
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function testUpdateTaxTypeRequiresName()
|
||||
{
|
||||
$taxType = factory(TaxType::class)->create();
|
||||
$taxType2 = factory(TaxType::class)->raw(['name' => '']);
|
||||
|
||||
$response = $this->json('PUT', 'api/tax-types/'.$taxType->id, $taxType2);
|
||||
|
||||
$response->assertStatus(422)->assertJsonValidationErrors(['name']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function testUpdateTaxTypeRequiresPercent()
|
||||
{
|
||||
$taxType = factory(TaxType::class)->create();
|
||||
$taxType2 = factory(TaxType::class)->raw(['percent' => '']);
|
||||
|
||||
$response = $this->json('PUT', 'api/tax-types/'.$taxType->id, $taxType2);
|
||||
|
||||
$response->assertStatus(422)->assertJsonValidationErrors(['percent']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function testDeleteTaxType()
|
||||
{
|
||||
$taxType = factory(TaxType::class)->create();
|
||||
|
||||
$response = $this->json('DELETE', 'api/tax-types/'.$taxType->id);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'success' => true
|
||||
]);
|
||||
|
||||
$this->assertNull(TaxType::find($taxType->id));
|
||||
}
|
||||
}
|
||||
$this->assertDeleted($taxType);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user