akaunting/tests/Feature/Settings/CurrenciesTest.php

96 lines
2.4 KiB
PHP
Raw Normal View History

2018-10-04 16:53:16 +03:00
<?php
namespace Tests\Feature\Settings;
2019-11-17 15:06:00 +03:00
use App\Jobs\Setting\CreateCurrency;
2020-01-13 02:56:14 +03:00
use App\Models\Setting\Currency;
2018-10-04 16:53:16 +03:00
use Tests\Feature\FeatureTestCase;
class CurrenciesTest extends FeatureTestCase
{
public function testItShouldSeeCurrencyListPage()
{
$this->loginAs()
->get(route('currencies.index'))
->assertStatus(200)
->assertSeeText(trans_choice('general.currencies', 2));
}
public function testItShouldSeeCurrencyCreatePage()
{
$this->loginAs()
->get(route('currencies.create'))
->assertStatus(200)
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.currencies', 1)]));
}
public function testItShouldCreateCurrency()
{
2020-07-25 17:22:50 +03:00
$request = $this->getRequest();
2018-10-04 16:53:16 +03:00
$this->loginAs()
2020-07-25 17:22:50 +03:00
->post(route('currencies.store'), $request)
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-04 16:53:16 +03:00
$this->assertFlashLevel('success');
2020-07-25 17:22:50 +03:00
2020-07-26 10:04:52 +03:00
$this->assertDatabaseHas('currencies', [
'code' => $request['code'],
]);
2018-10-04 16:53:16 +03:00
}
2020-01-13 10:55:19 +03:00
public function testItShouldSeeCurrencyUpdatePage()
{
2020-07-25 17:22:50 +03:00
$request = $this->getRequest();
$currency = $this->dispatch(new CreateCurrency($request));
2020-01-13 10:55:19 +03:00
$this->loginAs()
->get(route('currencies.edit', $currency->id))
->assertStatus(200)
->assertSee($currency->code);
}
2018-10-04 16:53:16 +03:00
public function testItShouldUpdateCurrency()
{
2020-01-13 02:56:14 +03:00
$request = $this->getRequest();
2018-10-04 16:53:16 +03:00
2019-11-17 15:06:00 +03:00
$currency = $this->dispatch(new CreateCurrency($request));
2018-10-04 16:53:16 +03:00
$request['name'] = $this->faker->text(15);
$this->loginAs()
->patch(route('currencies.update', $currency->id), $request)
2020-01-13 17:20:28 +03:00
->assertStatus(200)
->assertSee($request['name']);
2018-10-04 16:53:16 +03:00
$this->assertFlashLevel('success');
2020-07-25 17:22:50 +03:00
2020-07-26 10:04:52 +03:00
$this->assertDatabaseHas('currencies', [
'code' => $request['code'],
]);
2018-10-04 16:53:16 +03:00
}
public function testItShouldDeleteCurrency()
{
2020-07-25 17:22:50 +03:00
$request = $this->getRequest();
$currency = $this->dispatch(new CreateCurrency($request));
2018-10-04 16:53:16 +03:00
$this->loginAs()
->delete(route('currencies.destroy', $currency->id))
2019-11-16 10:21:14 +03:00
->assertStatus(200);
2018-10-04 16:53:16 +03:00
$this->assertFlashLevel('success');
2020-07-25 17:22:50 +03:00
2020-07-26 10:04:52 +03:00
$this->assertSoftDeleted('currencies', [
'code' => $request['code'],
]);
2018-10-04 16:53:16 +03:00
}
2020-01-13 02:56:14 +03:00
public function getRequest()
2018-10-04 16:53:16 +03:00
{
2020-10-14 17:07:59 +03:00
return Currency::factory()->enabled()->raw();
2018-10-04 16:53:16 +03:00
}
2019-04-02 18:51:06 +03:00
}