mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 05:47:28 -08:00
WIP: allow EU style purchase cost via api
This commit is contained in:
parent
783a24eb68
commit
12418ae91b
|
@ -45,8 +45,14 @@ class StoreAssetRequest extends ImageUploadRequest
|
||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
|
$modelRules = (new Asset)->getRules();
|
||||||
|
|
||||||
|
$modelRules['purchase_cost'] = array_filter(explode('|', $modelRules['purchase_cost']), function ($rule) {
|
||||||
|
return $rule !== 'numeric' && $rule !== 'gte:0';
|
||||||
|
});
|
||||||
|
|
||||||
$rules = array_merge(
|
$rules = array_merge(
|
||||||
(new Asset)->getRules(),
|
$modelRules,
|
||||||
parent::rules(),
|
parent::rules(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Api\Assets;
|
namespace Tests\Feature\Api\Assets;
|
||||||
|
|
||||||
|
use App\Helpers\Helper;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\AssetModel;
|
use App\Models\AssetModel;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
@ -12,6 +13,7 @@ use App\Models\Supplier;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\Crypt;
|
use Illuminate\Support\Facades\Crypt;
|
||||||
use Illuminate\Testing\Fluent\AssertableJson;
|
use Illuminate\Testing\Fluent\AssertableJson;
|
||||||
|
use Illuminate\Testing\TestResponse;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class AssetStoreTest extends TestCase
|
class AssetStoreTest extends TestCase
|
||||||
|
@ -278,6 +280,47 @@ class AssetStoreTest extends TestCase
|
||||||
->assertStatusMessageIs('error');
|
->assertStatusMessageIs('error');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function purchaseCosts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'with decimal' => [
|
||||||
|
[
|
||||||
|
'separator' => '1.234.56',
|
||||||
|
'input' => 12.34,
|
||||||
|
'expectation' => 12.34
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'EU style' => [
|
||||||
|
[
|
||||||
|
'separator' => '1.234,56',
|
||||||
|
'input' => "12,34",
|
||||||
|
'expectation' => 12.34
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider purchaseCosts
|
||||||
|
*/
|
||||||
|
public function testPurchaseCost($costs)
|
||||||
|
{
|
||||||
|
$this->settings->set(['digit_separator' => $costs['separator']]);
|
||||||
|
|
||||||
|
$response = $this->actingAsForApi(User::factory()->superuser()->create())
|
||||||
|
->postJson(route('api.assets.store'), [
|
||||||
|
'asset_tag' => 'random-string',
|
||||||
|
'model_id' => AssetModel::factory()->create()->id,
|
||||||
|
'status_id' => Statuslabel::factory()->create()->id,
|
||||||
|
'purchase_cost' => $costs['input'],
|
||||||
|
])
|
||||||
|
->assertStatusMessageIs('success');
|
||||||
|
|
||||||
|
$asset = Asset::find($response['payload']['id']);
|
||||||
|
|
||||||
|
$this->assertEquals($costs['expectation'], $asset->purchase_cost);
|
||||||
|
}
|
||||||
|
|
||||||
public function testUniqueSerialNumbersIsEnforcedWhenEnabled()
|
public function testUniqueSerialNumbersIsEnforcedWhenEnabled()
|
||||||
{
|
{
|
||||||
$model = AssetModel::factory()->create();
|
$model = AssetModel::factory()->create();
|
||||||
|
|
Loading…
Reference in a new issue