mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 06:17:28 -08:00
Add test validation test for update method and remove name uniqueness constraint
This commit is contained in:
parent
8873137ed0
commit
c5710b858e
|
@ -15,10 +15,10 @@ class ReportTemplatesController extends Controller
|
||||||
$this->authorize('reports.view');
|
$this->authorize('reports.view');
|
||||||
|
|
||||||
// Ignore "options" rules since data does not come in under that key...
|
// Ignore "options" rules since data does not come in under that key...
|
||||||
$request->validate(Arr::except((new ReportTemplate)->getRules(), 'options'));
|
$validated = $request->validate(Arr::except((new ReportTemplate)->getRules(), 'options'));
|
||||||
|
|
||||||
$report = $request->user()->reportTemplates()->create([
|
$report = $request->user()->reportTemplates()->create([
|
||||||
'name' => $request->get('name'),
|
'name' => $validated['name'],
|
||||||
'options' => $request->except(['_token', 'name']),
|
'options' => $request->except(['_token', 'name']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -55,9 +55,10 @@ class ReportTemplatesController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('reports.view');
|
$this->authorize('reports.view');
|
||||||
|
|
||||||
// @todo: validation
|
// Ignore "options" rules since data does not come in under that key...
|
||||||
|
$validated = $request->validate(Arr::except((new ReportTemplate)->getRules(), 'options'));
|
||||||
|
|
||||||
$reportTemplate->name = $request->input('name');
|
$reportTemplate->name = $validated['name'];
|
||||||
$reportTemplate->options = $request->except(['_token', 'name']);
|
$reportTemplate->options = $request->except(['_token', 'name']);
|
||||||
$reportTemplate->save();
|
$reportTemplate->save();
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,8 @@ class ReportTemplate extends Model
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $rules = [
|
protected $rules = [
|
||||||
// @todo: this should probably be unique for each user so people don't get errors trying to use a name someone else already used...
|
|
||||||
// @todo: but enabling shared reports in the future would mean we would have name collisions then...
|
|
||||||
'name' => [
|
'name' => [
|
||||||
'required',
|
'required',
|
||||||
'unique:report_templates,name',
|
|
||||||
],
|
],
|
||||||
'options' => [
|
'options' => [
|
||||||
'required',
|
'required',
|
||||||
|
|
|
@ -25,6 +25,21 @@ class UpdateReportTemplateTest extends TestCase implements TestsPermissionsRequi
|
||||||
->assertNotFound();
|
->assertNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUpdatingReportTemplateRequiresValidFields()
|
||||||
|
{
|
||||||
|
$user = User::factory()->canViewReports()->create();
|
||||||
|
|
||||||
|
$reportTemplate = ReportTemplate::factory()->for($user, 'creator')->create();
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
|
->post($this->getRoute($reportTemplate), [
|
||||||
|
//
|
||||||
|
])
|
||||||
|
->assertSessionHasErrors([
|
||||||
|
'name' => 'The name field is required.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function testCanUpdateAReportTemplate()
|
public function testCanUpdateAReportTemplate()
|
||||||
{
|
{
|
||||||
$user = User::factory()->canViewReports()->create();
|
$user = User::factory()->canViewReports()->create();
|
||||||
|
|
Loading…
Reference in a new issue