1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Feature\MmexClient; |
4
|
|
|
|
5
|
|
|
use App\Models\Category; |
6
|
|
|
use Tests\Feature\Api\AbstractMmexTestCase; |
7
|
|
|
use Tests\TestCase; |
8
|
|
|
|
9
|
|
|
class CategoryTest extends AbstractMmexTestCase |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
View Code Duplication |
public function testDeleteAllCategories() |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
// Arrange |
15
|
|
|
$categorie = factory(Category::class)->create(); |
16
|
|
|
|
17
|
|
|
$url = $this->buildUrl('', ['delete_category' => 'true']); |
18
|
|
|
|
19
|
|
|
// Act |
20
|
|
|
$response = $this->get($url); |
21
|
|
|
|
22
|
|
|
// Assert |
23
|
|
|
$this->seeSuccess($response); |
24
|
|
|
$this->assertDatabaseMissing('categories', ['name' => $categorie->name]); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testImportCategories() |
28
|
|
|
{ |
29
|
|
|
// Arrange |
30
|
|
|
$data = ['MMEX_Post' => '{ "Categories" : [ { "CategoryName" : "Bills", "SubCategoryName" : "Telecom" }, { "CategoryName" : "Bills", "SubCategoryName" : "Water" }, { "CategoryName" : "Automobile", "SubCategoryName" : "Maintenance" }, { "CategoryName" : "Automobile", "SubCategoryName" : "Parking" } ] }']; |
31
|
|
|
$url = $this->buildUrl('', ['import_category' => 'true']); |
32
|
|
|
|
33
|
|
|
// Act |
34
|
|
|
$response = $this->postJson($url, $data); |
35
|
|
|
|
36
|
|
|
// Assert |
37
|
|
|
$this->seeSuccess($response); |
38
|
|
|
$this->assertDatabaseHas('categories', ['name' => 'Bills']); |
39
|
|
|
$this->assertDatabaseHas('categories', ['name' => 'Telecom']); |
40
|
|
|
$this->assertDatabaseHas('categories', ['name' => 'Water']); |
41
|
|
|
$this->assertDatabaseHas('categories', ['name' => 'Automobile']); |
42
|
|
|
$this->assertDatabaseHas('categories', ['name' => 'Maintenance']); |
43
|
|
|
$this->assertDatabaseHas('categories', ['name' => 'Parking']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testImportSubCategories() |
47
|
|
|
{ |
48
|
|
|
// Arrange |
49
|
|
|
$data = ['MMEX_Post' => '{ "Categories" : [ { "CategoryName" : "Bills", "SubCategoryName" : "Telecom" }, { "CategoryName" : "Bills", "SubCategoryName" : "Water" }, { "CategoryName" : "Automobile", "SubCategoryName" : "Maintenance" }, { "CategoryName" : "Automobile", "SubCategoryName" : "Parking" } ] }']; |
50
|
|
|
$url = $this->buildUrl('', ['import_category' => 'true']); |
51
|
|
|
|
52
|
|
|
$bills = factory(Category::class)->create(['name' => 'Bills']); |
53
|
|
|
$automobile = factory(Category::class)->create(['name' => 'Automobile']); |
54
|
|
|
|
55
|
|
|
// Act |
56
|
|
|
$response = $this->postJson($url, $data); |
57
|
|
|
|
58
|
|
|
// Assert |
59
|
|
|
$this->seeSuccess($response); |
60
|
|
|
$this->assertDatabaseHas('categories', ['name' => 'Bills', 'id' => $bills->id]); |
61
|
|
|
$this->assertDatabaseHas('categories', ['name' => 'Telecom', 'parent_id' => $bills->id]); |
62
|
|
|
$this->assertDatabaseHas('categories', ['name' => 'Water', 'parent_id' => $bills->id]); |
63
|
|
|
$this->assertDatabaseHas('categories', ['name' => 'Automobile', 'id' => $automobile->id]); |
64
|
|
|
$this->assertDatabaseHas('categories', ['name' => 'Maintenance', 'parent_id' => $automobile->id]); |
65
|
|
|
$this->assertDatabaseHas('categories', ['name' => 'Parking', 'parent_id' => $automobile->id]); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.