mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Added/updated tests
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
a9d6a5f618
commit
3de5f5882c
|
@ -27,6 +27,7 @@ class CreateCategoriesTest extends TestCase
|
||||||
'name' => 'Test Category',
|
'name' => 'Test Category',
|
||||||
'eula_text' => 'Test EULA',
|
'eula_text' => 'Test EULA',
|
||||||
'category_type' => 'accessory',
|
'category_type' => 'accessory',
|
||||||
|
'notes' => 'Test Note',
|
||||||
])
|
])
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertStatusMessageIs('success')
|
->assertStatusMessageIs('success')
|
||||||
|
@ -38,6 +39,7 @@ class CreateCategoriesTest extends TestCase
|
||||||
$category = Category::find($response['payload']['id']);
|
$category = Category::find($response['payload']['id']);
|
||||||
$this->assertEquals('Test Category', $category->name);
|
$this->assertEquals('Test Category', $category->name);
|
||||||
$this->assertEquals('Test EULA', $category->eula_text);
|
$this->assertEquals('Test EULA', $category->eula_text);
|
||||||
|
$this->assertEquals('Test Note', $category->notes);
|
||||||
$this->assertEquals('accessory', $category->category_type);
|
$this->assertEquals('accessory', $category->category_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ class UpdateCategoriesTest extends TestCase
|
||||||
->patchJson(route('api.categories.update', $category), [
|
->patchJson(route('api.categories.update', $category), [
|
||||||
'name' => 'Test Category',
|
'name' => 'Test Category',
|
||||||
'eula_text' => 'Test EULA',
|
'eula_text' => 'Test EULA',
|
||||||
|
'notes' => 'Test Note',
|
||||||
])
|
])
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertStatusMessageIs('success')
|
->assertStatusMessageIs('success')
|
||||||
|
@ -27,6 +28,7 @@ class UpdateCategoriesTest extends TestCase
|
||||||
$category->refresh();
|
$category->refresh();
|
||||||
$this->assertEquals('Test Category', $category->name, 'Name was not updated');
|
$this->assertEquals('Test Category', $category->name, 'Name was not updated');
|
||||||
$this->assertEquals('Test EULA', $category->eula_text, 'EULA was not updated');
|
$this->assertEquals('Test EULA', $category->eula_text, 'EULA was not updated');
|
||||||
|
$this->assertEquals('Test Note', $category->notes, 'Note was not updated');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +41,7 @@ class UpdateCategoriesTest extends TestCase
|
||||||
'name' => 'Test Category',
|
'name' => 'Test Category',
|
||||||
'eula_text' => 'Test EULA',
|
'eula_text' => 'Test EULA',
|
||||||
'category_type' => 'accessory',
|
'category_type' => 'accessory',
|
||||||
|
'note' => 'Test Note',
|
||||||
])
|
])
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertStatusMessageIs('error')
|
->assertStatusMessageIs('error')
|
||||||
|
@ -48,6 +51,7 @@ class UpdateCategoriesTest extends TestCase
|
||||||
$category->refresh();
|
$category->refresh();
|
||||||
$this->assertNotEquals('Test Category', $category->name, 'Name was not updated');
|
$this->assertNotEquals('Test Category', $category->name, 'Name was not updated');
|
||||||
$this->assertNotEquals('Test EULA', $category->eula_text, 'EULA was not updated');
|
$this->assertNotEquals('Test EULA', $category->eula_text, 'EULA was not updated');
|
||||||
|
$this->assertNotEquals('Test Note', $category->notes, 'Note was not updated');
|
||||||
$this->assertNotEquals('accessory', $category->category_type, 'EULA was not updated');
|
$this->assertNotEquals('accessory', $category->category_type, 'EULA was not updated');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,11 +33,12 @@ class CreateCategoriesTest extends TestCase
|
||||||
$this->actingAs(User::factory()->superuser()->create())
|
$this->actingAs(User::factory()->superuser()->create())
|
||||||
->post(route('categories.store'), [
|
->post(route('categories.store'), [
|
||||||
'name' => 'Test Category',
|
'name' => 'Test Category',
|
||||||
'category_type' => 'asset'
|
'category_type' => 'asset',
|
||||||
|
'notes' => 'Test Note',
|
||||||
])
|
])
|
||||||
->assertRedirect(route('categories.index'));
|
->assertRedirect(route('categories.index'));
|
||||||
|
|
||||||
$this->assertTrue(Category::where('name', 'Test Category')->exists());
|
$this->assertTrue(Category::where('name', 'Test Category')->where('notes', 'Test Note')->exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUserCannotCreateCategoriesWithInvalidType()
|
public function testUserCannotCreateCategoriesWithInvalidType()
|
||||||
|
@ -48,7 +49,7 @@ class CreateCategoriesTest extends TestCase
|
||||||
->from(route('categories.create'))
|
->from(route('categories.create'))
|
||||||
->post(route('categories.store'), [
|
->post(route('categories.store'), [
|
||||||
'name' => 'Test Category',
|
'name' => 'Test Category',
|
||||||
'category_type' => 'invalid'
|
'category_type' => 'invalid',
|
||||||
])
|
])
|
||||||
->assertRedirect(route('categories.create'));
|
->assertRedirect(route('categories.create'));
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ class UpdateCategoriesTest extends TestCase
|
||||||
$this->actingAs(User::factory()->superuser()->create())
|
$this->actingAs(User::factory()->superuser()->create())
|
||||||
->post(route('categories.store'), [
|
->post(route('categories.store'), [
|
||||||
'name' => 'Test Category',
|
'name' => 'Test Category',
|
||||||
'category_type' => 'asset'
|
'category_type' => 'asset',
|
||||||
])
|
])
|
||||||
->assertStatus(302)
|
->assertStatus(302)
|
||||||
->assertSessionHasNoErrors()
|
->assertSessionHasNoErrors()
|
||||||
|
@ -49,13 +49,14 @@ class UpdateCategoriesTest extends TestCase
|
||||||
$response = $this->actingAs(User::factory()->superuser()->create())
|
$response = $this->actingAs(User::factory()->superuser()->create())
|
||||||
->put(route('categories.update', ['category' => $category]), [
|
->put(route('categories.update', ['category' => $category]), [
|
||||||
'name' => 'Test Category Edited',
|
'name' => 'Test Category Edited',
|
||||||
|
'notes' => 'Test Note Edited',
|
||||||
])
|
])
|
||||||
->assertStatus(302)
|
->assertStatus(302)
|
||||||
->assertSessionHasNoErrors()
|
->assertSessionHasNoErrors()
|
||||||
->assertRedirect(route('categories.index'));
|
->assertRedirect(route('categories.index'));
|
||||||
|
|
||||||
$this->followRedirects($response)->assertSee('Success');
|
$this->followRedirects($response)->assertSee('Success');
|
||||||
$this->assertTrue(Category::where('name', 'Test Category Edited')->exists());
|
$this->assertTrue(Category::where('name', 'Test Category Edited')->where('notes', 'Test Note Edited')->exists());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,13 +70,14 @@ class UpdateCategoriesTest extends TestCase
|
||||||
->put(route('categories.update', ['category' => $category]), [
|
->put(route('categories.update', ['category' => $category]), [
|
||||||
'name' => 'Test Category Edited',
|
'name' => 'Test Category Edited',
|
||||||
'category_type' => 'accessory',
|
'category_type' => 'accessory',
|
||||||
|
'notes' => 'Test Note Edited',
|
||||||
])
|
])
|
||||||
->assertSessionHasNoErrors()
|
->assertSessionHasNoErrors()
|
||||||
->assertStatus(302)
|
->assertStatus(302)
|
||||||
->assertRedirect(route('categories.index'));
|
->assertRedirect(route('categories.index'));
|
||||||
|
|
||||||
$this->followRedirects($response)->assertSee('Success');
|
$this->followRedirects($response)->assertSee('Success');
|
||||||
$this->assertTrue(Category::where('name', 'Test Category Edited')->exists());
|
$this->assertTrue(Category::where('name', 'Test Category Edited')->where('notes', 'Test Note Edited')->exists());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +91,7 @@ class UpdateCategoriesTest extends TestCase
|
||||||
->put(route('categories.update', ['category' => $category]), [
|
->put(route('categories.update', ['category' => $category]), [
|
||||||
'name' => 'Test Category Edited',
|
'name' => 'Test Category Edited',
|
||||||
'category_type' => 'accessory',
|
'category_type' => 'accessory',
|
||||||
|
'notes' => 'Test Note Edited',
|
||||||
])
|
])
|
||||||
->assertSessionHasErrors(['category_type'])
|
->assertSessionHasErrors(['category_type'])
|
||||||
->assertInvalid(['category_type'])
|
->assertInvalid(['category_type'])
|
||||||
|
@ -96,7 +99,7 @@ class UpdateCategoriesTest extends TestCase
|
||||||
->assertRedirect(route('categories.edit', ['category' => $category->id]));
|
->assertRedirect(route('categories.edit', ['category' => $category->id]));
|
||||||
|
|
||||||
$this->followRedirects($response)->assertSee(trans('general.error'));
|
$this->followRedirects($response)->assertSee(trans('general.error'));
|
||||||
$this->assertFalse(Category::where('name', 'Test Category Edited')->exists());
|
$this->assertFalse(Category::where('name', 'Test Category Edited')->where('notes', 'Test Note Edited')->exists());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,4 +20,23 @@ class CreateDepartmentsTest extends TestCase
|
||||||
->assertForbidden();
|
->assertForbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCanCreateDepartment()
|
||||||
|
{
|
||||||
|
$response = $this->actingAsForApi(User::factory()->superuser()->create())
|
||||||
|
->postJson(route('api.departments.store'), [
|
||||||
|
'name' => 'Test Department',
|
||||||
|
'notes' => 'Test Note',
|
||||||
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertStatusMessageIs('success')
|
||||||
|
->assertStatus(200)
|
||||||
|
->json();
|
||||||
|
|
||||||
|
$this->assertTrue(Department::where('name', 'Test Department')->exists());
|
||||||
|
|
||||||
|
$department = Department::find($response['payload']['id']);
|
||||||
|
$this->assertEquals('Test Department', $department->name);
|
||||||
|
$this->assertEquals('Test Note', $department->notes);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ class UpdateDepartmentsTest extends TestCase
|
||||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||||
->patchJson(route('api.departments.update', $department), [
|
->patchJson(route('api.departments.update', $department), [
|
||||||
'name' => 'Test Department',
|
'name' => 'Test Department',
|
||||||
|
'notes' => 'Test Note',
|
||||||
])
|
])
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertStatusMessageIs('success')
|
->assertStatusMessageIs('success')
|
||||||
|
@ -33,6 +34,7 @@ class UpdateDepartmentsTest extends TestCase
|
||||||
|
|
||||||
$department->refresh();
|
$department->refresh();
|
||||||
$this->assertEquals('Test Department', $department->name, 'Name was not updated');
|
$this->assertEquals('Test Department', $department->name, 'Name was not updated');
|
||||||
|
$this->assertEquals('Test Note', $department->notes, 'Note was not updated');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,12 @@ class CreateDepartmentsTest extends TestCase
|
||||||
$this->actingAs(User::factory()->superuser()->create())
|
$this->actingAs(User::factory()->superuser()->create())
|
||||||
->post(route('departments.store'), [
|
->post(route('departments.store'), [
|
||||||
'name' => 'Test Department',
|
'name' => 'Test Department',
|
||||||
'company_id' => Company::factory()->create()->id
|
'company_id' => Company::factory()->create()->id,
|
||||||
|
'notes' => 'Test Note',
|
||||||
])
|
])
|
||||||
->assertRedirect(route('departments.index'));
|
->assertRedirect(route('departments.index'));
|
||||||
|
|
||||||
$this->assertTrue(Department::where('name', 'Test Department')->exists());
|
$this->assertTrue(Department::where('name', 'Test Department')->where('notes', 'Test Note')->exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,13 +34,14 @@ class UpdateDepartmentsTest extends TestCase
|
||||||
$response = $this->actingAs(User::factory()->superuser()->create())
|
$response = $this->actingAs(User::factory()->superuser()->create())
|
||||||
->put(route('departments.update', ['department' => $department]), [
|
->put(route('departments.update', ['department' => $department]), [
|
||||||
'name' => 'Test Department Edited',
|
'name' => 'Test Department Edited',
|
||||||
|
'notes' => 'Test Note Edited',
|
||||||
])
|
])
|
||||||
->assertStatus(302)
|
->assertStatus(302)
|
||||||
->assertSessionHasNoErrors()
|
->assertSessionHasNoErrors()
|
||||||
->assertRedirect(route('departments.index'));
|
->assertRedirect(route('departments.index'));
|
||||||
|
|
||||||
$this->followRedirects($response)->assertSee('Success');
|
$this->followRedirects($response)->assertSee('Success');
|
||||||
$this->assertTrue(Department::where('name', 'Test Department Edited')->exists());
|
$this->assertTrue(Department::where('name', 'Test Department Edited')->where('notes', 'Test Note Edited')->exists());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ class StoreGroupTest extends TestCase
|
||||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||||
->postJson(route('api.groups.store'), [
|
->postJson(route('api.groups.store'), [
|
||||||
'name' => 'My Awesome Group',
|
'name' => 'My Awesome Group',
|
||||||
|
'notes' => 'My Awesome Note',
|
||||||
'permissions' => [
|
'permissions' => [
|
||||||
'admin' => '1',
|
'admin' => '1',
|
||||||
'import' => '1',
|
'import' => '1',
|
||||||
|
@ -29,7 +30,7 @@ class StoreGroupTest extends TestCase
|
||||||
])
|
])
|
||||||
->assertOk();
|
->assertOk();
|
||||||
|
|
||||||
$group = Group::where('name', 'My Awesome Group')->first();
|
$group = Group::where('name', 'My Awesome Group')->where('notes', 'My Awesome Note')->first();
|
||||||
|
|
||||||
$this->assertNotNull($group);
|
$this->assertNotNull($group);
|
||||||
$this->assertEquals('1', $group->decodePermissions()['admin']);
|
$this->assertEquals('1', $group->decodePermissions()['admin']);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Groups\Ui;
|
namespace Tests\Feature\Groups\Ui;
|
||||||
|
|
||||||
|
use App\Models\Group;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
@ -13,4 +14,18 @@ class CreateGroupTest extends TestCase
|
||||||
->get(route('groups.create'))
|
->get(route('groups.create'))
|
||||||
->assertOk();
|
->assertOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUserCanCreateGroup()
|
||||||
|
{
|
||||||
|
$this->assertFalse(Group::where('name', 'Test Group')->exists());
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->superuser()->create())
|
||||||
|
->post(route('groups.store'), [
|
||||||
|
'name' => 'Test Group',
|
||||||
|
'notes' => 'Test Note',
|
||||||
|
])
|
||||||
|
->assertRedirect(route('groups.index'));
|
||||||
|
|
||||||
|
$this->assertTrue(Group::where('name', 'Test Group')->where('notes', 'Test Note')->exists());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,4 +14,22 @@ class UpdateGroupTest extends TestCase
|
||||||
->get(route('groups.edit', Group::factory()->create()->id))
|
->get(route('groups.edit', Group::factory()->create()->id))
|
||||||
->assertOk();
|
->assertOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUserCanEditGroups()
|
||||||
|
{
|
||||||
|
$group = Group::factory()->create(['name' => 'Test Group']);
|
||||||
|
$this->assertTrue(Group::where('name', 'Test Group')->exists());
|
||||||
|
|
||||||
|
$response = $this->actingAs(User::factory()->superuser()->create())
|
||||||
|
->put(route('groups.update', ['group' => $group]), [
|
||||||
|
'name' => 'Test Group Edited',
|
||||||
|
'notes' => 'Test Note Edited',
|
||||||
|
])
|
||||||
|
->assertStatus(302)
|
||||||
|
->assertSessionHasNoErrors()
|
||||||
|
->assertRedirect(route('groups.index'));
|
||||||
|
|
||||||
|
$this->followRedirects($response)->assertSee('Success');
|
||||||
|
$this->assertTrue(Group::where('name', 'Test Group Edited')->where('notes', 'Test Note Edited')->exists());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,26 @@ class CreateLocationsTest extends TestCase
|
||||||
->assertForbidden();
|
->assertForbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testCanCreateLocation()
|
||||||
|
{
|
||||||
|
$response = $this->actingAsForApi(User::factory()->superuser()->create())
|
||||||
|
->postJson(route('api.locations.store'), [
|
||||||
|
'name' => 'Test Location',
|
||||||
|
'notes' => 'Test Note',
|
||||||
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertStatusMessageIs('success')
|
||||||
|
->assertStatus(200)
|
||||||
|
->json();
|
||||||
|
|
||||||
|
$this->assertTrue(Location::where('name', 'Test Location')->exists());
|
||||||
|
|
||||||
|
$department = Location::find($response['payload']['id']);
|
||||||
|
$this->assertEquals('Test Location', $department->name);
|
||||||
|
$this->assertEquals('Test Note', $department->notes);
|
||||||
|
}
|
||||||
|
|
||||||
public function testCannotCreateNewLocationsWithTheSameName()
|
public function testCannotCreateNewLocationsWithTheSameName()
|
||||||
{
|
{
|
||||||
$location = Location::factory()->create();
|
$location = Location::factory()->create();
|
||||||
|
|
|
@ -22,7 +22,8 @@ class UpdateLocationsTest extends TestCase
|
||||||
|
|
||||||
$this->actingAsForApi(User::factory()->superuser()->create())
|
$this->actingAsForApi(User::factory()->superuser()->create())
|
||||||
->patchJson(route('api.locations.update', $location), [
|
->patchJson(route('api.locations.update', $location), [
|
||||||
'name' => 'Test Location',
|
'name' => 'Test Updated Location',
|
||||||
|
'notes' => 'Test Updated Note',
|
||||||
])
|
])
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertStatusMessageIs('success')
|
->assertStatusMessageIs('success')
|
||||||
|
@ -30,7 +31,8 @@ class UpdateLocationsTest extends TestCase
|
||||||
->json();
|
->json();
|
||||||
|
|
||||||
$location->refresh();
|
$location->refresh();
|
||||||
$this->assertEquals('Test Location', $location->name, 'Name was not updated');
|
$this->assertEquals('Test Updated Location', $location->name, 'Name was not updated');
|
||||||
|
$this->assertEquals('Test Updated Note', $location->notes, 'Note was not updated');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,11 @@ class CreateLocationsTest extends TestCase
|
||||||
$this->actingAs(User::factory()->superuser()->create())
|
$this->actingAs(User::factory()->superuser()->create())
|
||||||
->post(route('locations.store'), [
|
->post(route('locations.store'), [
|
||||||
'name' => 'Test Location',
|
'name' => 'Test Location',
|
||||||
'company_id' => Company::factory()->create()->id
|
'notes' => 'Test Note',
|
||||||
])
|
])
|
||||||
->assertRedirect(route('locations.index'));
|
->assertRedirect(route('locations.index'));
|
||||||
|
|
||||||
$this->assertTrue(Location::where('name', 'Test Location')->exists());
|
$this->assertTrue(Location::where('name', 'Test Location')->where('notes', 'Test Note')->exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUserCannotCreateLocationsWithInvalidParent()
|
public function testUserCannotCreateLocationsWithInvalidParent()
|
||||||
|
|
|
@ -33,13 +33,14 @@ class UpdateLocationsTest extends TestCase
|
||||||
$response = $this->actingAs(User::factory()->superuser()->create())
|
$response = $this->actingAs(User::factory()->superuser()->create())
|
||||||
->put(route('locations.update', ['location' => $location]), [
|
->put(route('locations.update', ['location' => $location]), [
|
||||||
'name' => 'Test Location Edited',
|
'name' => 'Test Location Edited',
|
||||||
|
'notes' => 'Test Note Edited',
|
||||||
])
|
])
|
||||||
->assertStatus(302)
|
->assertStatus(302)
|
||||||
->assertSessionHasNoErrors()
|
->assertSessionHasNoErrors()
|
||||||
->assertRedirect(route('locations.index'));
|
->assertRedirect(route('locations.index'));
|
||||||
|
|
||||||
$this->followRedirects($response)->assertSee('Success');
|
$this->followRedirects($response)->assertSee('Success');
|
||||||
$this->assertTrue(Location::where('name', 'Test Location Edited')->exists());
|
$this->assertTrue(Location::where('name', 'Test Location Edited')->where('notes', 'Test Note Edited')->exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUserCannotEditLocationsToMakeThemTheirOwnParent()
|
public function testUserCannotEditLocationsToMakeThemTheirOwnParent()
|
||||||
|
|
39
tests/Feature/Manufacturers/Api/CreateManufacturersTest.php
Normal file
39
tests/Feature/Manufacturers/Api/CreateManufacturersTest.php
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Manufacturers\Api;
|
||||||
|
|
||||||
|
use App\Models\Manufacturer;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class CreateManufacturersTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public function testRequiresPermissionToCreateDepartment()
|
||||||
|
{
|
||||||
|
$this->actingAsForApi(User::factory()->create())
|
||||||
|
->postJson(route('api.departments.store'))
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanCreateManufacturer()
|
||||||
|
{
|
||||||
|
$response = $this->actingAsForApi(User::factory()->superuser()->create())
|
||||||
|
->postJson(route('api.manufacturers.store'), [
|
||||||
|
'name' => 'Test Manufacturer',
|
||||||
|
'notes' => 'Test Note',
|
||||||
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertStatusMessageIs('success')
|
||||||
|
->assertStatus(200)
|
||||||
|
->json();
|
||||||
|
|
||||||
|
$this->assertTrue(Manufacturer::where('name', 'Test Manufacturer')->where('notes', 'Test Note')->exists());
|
||||||
|
|
||||||
|
$manufacturer = Manufacturer::find($response['payload']['id']);
|
||||||
|
$this->assertEquals('Test Manufacturer', $manufacturer->name);
|
||||||
|
$this->assertEquals('Test Note', $manufacturer->notes);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
50
tests/Feature/Manufacturers/Api/UpdateManufacturersTest.php
Normal file
50
tests/Feature/Manufacturers/Api/UpdateManufacturersTest.php
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Manufacturers\Ui;
|
||||||
|
|
||||||
|
use App\Models\Manufacturer;
|
||||||
|
use App\Models\Category;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class UpdateManufacturersTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testPermissionRequiredToStoreManufacturer()
|
||||||
|
{
|
||||||
|
$this->actingAs(User::factory()->create())
|
||||||
|
->post(route('manufacturers.store'), [
|
||||||
|
'name' => 'Test Manufacturer',
|
||||||
|
])
|
||||||
|
->assertStatus(403)
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPageRenders()
|
||||||
|
{
|
||||||
|
$this->actingAs(User::factory()->superuser()->create())
|
||||||
|
->get(route('manufacturers.edit', Manufacturer::factory()->create()->id))
|
||||||
|
->assertOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUserCanEditManufacturers()
|
||||||
|
{
|
||||||
|
$department = Manufacturer::factory()->create(['name' => 'Test Manufacturer']);
|
||||||
|
$this->assertTrue(Manufacturer::where('name', 'Test Manufacturer')->exists());
|
||||||
|
|
||||||
|
$response = $this->actingAs(User::factory()->superuser()->create())
|
||||||
|
->put(route('manufacturers.update', ['manufacturer' => $department]), [
|
||||||
|
'name' => 'Test Manufacturer Edited',
|
||||||
|
'notes' => 'Test Note Edited',
|
||||||
|
])
|
||||||
|
->assertStatus(302)
|
||||||
|
->assertSessionHasNoErrors()
|
||||||
|
->assertRedirect(route('manufacturers.index'));
|
||||||
|
|
||||||
|
$this->followRedirects($response)->assertSee('Success');
|
||||||
|
$this->assertTrue(Manufacturer::where('name', 'Test Manufacturer Edited')->where('notes', 'Test Note Edited')->exists());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Tests\Feature\Manufacturers\Ui;
|
namespace Tests\Feature\Manufacturers\Ui;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Models\Manufacturer;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class CreateManufacturerTest extends TestCase
|
class CreateManufacturerTest extends TestCase
|
||||||
|
@ -13,4 +14,19 @@ class CreateManufacturerTest extends TestCase
|
||||||
->get(route('manufacturers.create'))
|
->get(route('manufacturers.create'))
|
||||||
->assertOk();
|
->assertOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUserCanCreateManufacturer()
|
||||||
|
{
|
||||||
|
$this->assertFalse(Manufacturer::where('name', 'Test Manufacturer')->exists());
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->superuser()->create())
|
||||||
|
->post(route('manufacturers.store'), [
|
||||||
|
'name' => 'Test Manufacturer',
|
||||||
|
'notes' => 'Test Note',
|
||||||
|
])
|
||||||
|
->assertRedirect(route('manufacturers.index'));
|
||||||
|
|
||||||
|
$this->assertTrue(Manufacturer::where('name', 'Test Manufacturer')->where('notes', 'Test Note')->exists());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,4 +14,23 @@ class UpdateManufacturerTest extends TestCase
|
||||||
->get(route('manufacturers.edit', Manufacturer::factory()->create()->id))
|
->get(route('manufacturers.edit', Manufacturer::factory()->create()->id))
|
||||||
->assertOk();
|
->assertOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUserCanEditManufacturers()
|
||||||
|
{
|
||||||
|
$manufacturer = Manufacturer::factory()->create(['name' => 'Test Manufacturer']);
|
||||||
|
$this->assertTrue(Manufacturer::where('name', 'Test Manufacturer')->exists());
|
||||||
|
|
||||||
|
$response = $this->actingAs(User::factory()->superuser()->create())
|
||||||
|
->put(route('manufacturers.update', ['manufacturer' => $manufacturer]), [
|
||||||
|
'name' => 'Test Manufacturer Edited',
|
||||||
|
'notes' => 'Test Note Edited',
|
||||||
|
])
|
||||||
|
->assertStatus(302)
|
||||||
|
->assertSessionHasNoErrors()
|
||||||
|
->assertRedirect(route('manufacturers.index'));
|
||||||
|
|
||||||
|
$this->followRedirects($response)->assertSee('Success');
|
||||||
|
$this->assertTrue(Manufacturer::where('name', 'Test Manufacturer Edited')->where('notes', 'Test Note Edited')->exists());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue