1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MmexControllerTest.php, laravel-money-manager-ex |
4
|
|
|
* |
5
|
|
|
* This File belongs to to Project laravel-money-manager-ex |
6
|
|
|
* @author Oliver Kaufmann <[email protected]> |
7
|
|
|
* @version 1.0 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace App\Tests\Api; |
11
|
|
|
|
12
|
|
|
use App\Models\Account; |
13
|
|
|
use App\Models\Category; |
14
|
|
|
use App\Models\Payee; |
15
|
|
|
use App\Models\Transaction; |
16
|
|
|
|
17
|
|
|
class MmexControllerTest extends AbstractApiTestCase |
18
|
|
|
{ |
19
|
|
View Code Duplication |
public function testDeleteAllPayees() |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
// Arrange |
22
|
|
|
$payee = factory(Payee::class)->create(); |
23
|
|
|
$url = $this->buildUrl('', ['delete_payee' => 'true']); |
24
|
|
|
|
25
|
|
|
//Assert |
26
|
|
|
$this->get($url) |
27
|
|
|
->seeSuccess() |
28
|
|
|
->dontSeeInDatabase('payees', ['name' => $payee->name]); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testImportPayees() |
32
|
|
|
{ |
33
|
|
|
// Arrange |
34
|
|
|
$food = factory(Category::class)->create(['name' => 'Food']); |
35
|
|
|
$foodPurchases = factory(Category::class)->create(['name' => 'Purchases', 'parent_id' => $food->id]); |
36
|
|
|
$bills = factory(Category::class)->create(['name' => 'Bills']); |
37
|
|
|
$billsServices = factory(Category::class)->create(['name' => 'Services', 'parent_id' => $bills->id]); |
38
|
|
|
|
39
|
|
|
$data = ['MMEX_Post' => '{ "Payees" : [ { "PayeeName" : "Mc Donalds", "DefCateg" : "'.$food->name.'", "DefSubCateg" : "'.$foodPurchases->name.'" },'. |
40
|
|
|
'{ "PayeeName" : "Spotify", "DefCateg" : "'.$bills->name.'", "DefSubCateg" : "'.$billsServices->name.'" } ] }']; |
41
|
|
|
|
42
|
|
|
$url = $this->buildUrl("", ["import_payee" => "true"]); |
43
|
|
|
|
44
|
|
|
// Assert |
45
|
|
|
$this->postJson($url, $data) |
46
|
|
|
->seeSuccess() |
47
|
|
|
->seeInDatabase('payees', ["name" => "Mc Donalds", "last_category_id" => $foodPurchases->id]) |
48
|
|
|
->seeInDatabase('payees', ["name" => "Spotify", "last_category_id" => $billsServices->id]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
View Code Duplication |
public function testDeleteAllAccounts() |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
// Arrange |
54
|
|
|
$account = factory(Account::class)->create(); |
55
|
|
|
|
56
|
|
|
$url = $this->buildUrl("", ["delete_bankaccount" => "true"]); |
57
|
|
|
|
58
|
|
|
//Assert |
59
|
|
|
$this->get($url) |
60
|
|
|
->seeSuccess() |
61
|
|
|
->dontSeeInDatabase('accounts', ["name" => $account->name]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testImportAccounts() |
65
|
|
|
{ |
66
|
|
|
// Arrange |
67
|
|
|
$data = ['MMEX_Post' => '{ "Accounts" : [ { "AccountName" : "Creditcard" }, { "AccountName" : "Private Account" } ] }']; |
68
|
|
|
$url = $this->buildUrl('', ['import_bankaccount' => 'true']); |
69
|
|
|
|
70
|
|
|
// Assert |
71
|
|
|
$this->postJson($url, $data) |
72
|
|
|
->seeSuccess() |
73
|
|
|
->seeInDatabase('accounts', ['name' => 'Creditcard']) |
74
|
|
|
->seeInDatabase('accounts', ['name' => 'Private Account']); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
View Code Duplication |
public function testDeleteAllCategories() |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
// Arrange |
80
|
|
|
$categorie = factory(Category::class)->create(); |
81
|
|
|
|
82
|
|
|
$url = $this->buildUrl('', ['delete_category' => 'true']); |
83
|
|
|
|
84
|
|
|
//Assert |
85
|
|
|
$this->get($url) |
86
|
|
|
->seeSuccess() |
87
|
|
|
->dontSeeInDatabase('categories', ['name' => $categorie->name]); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testImportCategories() |
91
|
|
|
{ |
92
|
|
|
// Arrange |
93
|
|
|
$data = ['MMEX_Post' => '{ "Categories" : [ { "CategoryName" : "Bills", "SubCategoryName" : "Telecom" }, { "CategoryName" : "Bills", "SubCategoryName" : "Water" }, { "CategoryName" : "Automobile", "SubCategoryName" : "Maintenance" }, { "CategoryName" : "Automobile", "SubCategoryName" : "Parking" } ] }']; |
94
|
|
|
$url = $this->buildUrl('', ['import_category' => 'true']); |
95
|
|
|
|
96
|
|
|
// Assert |
97
|
|
|
$this->postJson($url, $data) |
98
|
|
|
->seeSuccess() |
99
|
|
|
->seeInDatabase('categories', ['name' => 'Bills']) |
100
|
|
|
->seeInDatabase('categories', ['name' => 'Telecom']) |
101
|
|
|
->seeInDatabase('categories', ['name' => 'Water']) |
102
|
|
|
->seeInDatabase('categories', ['name' => 'Automobile']) |
103
|
|
|
->seeInDatabase('categories', ['name' => 'Maintenance']) |
104
|
|
|
->seeInDatabase('categories', ['name' => 'Parking']); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testImportSubCategories() |
108
|
|
|
{ |
109
|
|
|
// Arrange |
110
|
|
|
$data = ['MMEX_Post' => '{ "Categories" : [ { "CategoryName" : "Bills", "SubCategoryName" : "Telecom" }, { "CategoryName" : "Bills", "SubCategoryName" : "Water" }, { "CategoryName" : "Automobile", "SubCategoryName" : "Maintenance" }, { "CategoryName" : "Automobile", "SubCategoryName" : "Parking" } ] }']; |
111
|
|
|
$url = $this->buildUrl('', ['import_category' => 'true']); |
112
|
|
|
|
113
|
|
|
$bills = factory(Category::class)->create(['name' => 'Bills']); |
114
|
|
|
$automobile = factory(Category::class)->create(['name' => 'Automobile']); |
115
|
|
|
|
116
|
|
|
// Assert |
117
|
|
|
$this->postJson($url, $data) |
118
|
|
|
->seeSuccess() |
119
|
|
|
->seeInDatabase('categories', ['name' => 'Bills', 'id' => $bills->id]) |
120
|
|
|
->seeInDatabase('categories', ['name' => 'Telecom', 'parent_id' => $bills->id]) |
121
|
|
|
->seeInDatabase('categories', ['name' => 'Water', 'parent_id' => $bills->id]) |
122
|
|
|
->seeInDatabase('categories', ['name' => 'Automobile', 'id' => $automobile->id]) |
123
|
|
|
->seeInDatabase('categories', ['name' => 'Maintenance', 'parent_id' => $automobile->id]) |
124
|
|
|
->seeInDatabase('categories', ['name' => 'Parking', 'parent_id' => $automobile->id]); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function testDeleteTransactions() |
128
|
|
|
{ |
129
|
|
|
$transaction = factory(Transaction::class)->create(); |
130
|
|
|
|
131
|
|
|
$url = $this->buildUrl('', ['delete_group' => $transaction->id]); |
132
|
|
|
|
133
|
|
|
//Assert |
134
|
|
|
$this->get($url) |
135
|
|
|
->seeSuccess() |
136
|
|
|
->seeIsSoftDeletedInDatabase('transactions', ['payee_name' => $transaction->payee_name]); // must not be deleted! just soft deleted. |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function testDownloadTransactions() |
140
|
|
|
{ |
141
|
|
|
$transaction = factory(Transaction::class)->create(); |
142
|
|
|
|
143
|
|
|
$transaction->addMediaFromUrl('https://images.unsplash.com/photo-1459666644539-a9755287d6b0?dpr=1&auto=compress,format&fit=crop&w=376&h=227&q=80&cs=tinysrgb&crop=') |
144
|
|
|
->toCollection('attachments'); |
145
|
|
|
|
146
|
|
|
$url = $this->buildUrl('', ['download_transaction' => 'true']); |
147
|
|
|
|
148
|
|
|
$this->get($url) |
149
|
|
|
->seeStatusCode(200) |
150
|
|
|
->seeJson( |
151
|
|
|
[ |
152
|
|
|
"ID" => $transaction->id, |
153
|
|
|
"Date" => $transaction->date, |
154
|
|
|
"Account" => $transaction->account_name, |
155
|
|
|
"ToAccount" => $transaction->to_account_name, |
156
|
|
|
"Status" => $transaction->status->slug, |
157
|
|
|
"Type" => $transaction->type->name, |
158
|
|
|
"Payee" => $transaction->payee_name, |
159
|
|
|
"Category" => $transaction->category_name, |
160
|
|
|
"SubCategory" => $transaction->sub_category_name, |
161
|
|
|
"Amount" => $transaction->amount, |
162
|
|
|
"Notes" => $transaction->notes, |
163
|
|
|
"Attachments" => "Transaction_1_Attach1.png;Transaction_1_Attach2.jpg" |
164
|
|
|
] |
165
|
|
|
); |
166
|
|
|
|
167
|
|
|
// Stop here and mark this test as incomplete. |
168
|
|
|
$this->markTestIncomplete( |
169
|
|
|
'Test not implemented yet.' |
170
|
|
|
); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function testDownloadAttachment() |
174
|
|
|
{ |
175
|
|
|
// attachment file name will be provided as comma seperated list in the transaction download |
176
|
|
|
|
177
|
|
|
$fileName = 'Transaction_1_Attach2.jpg'; |
178
|
|
|
$url = $this->buildUrl('', ['download_attachment' => $fileName]); |
|
|
|
|
179
|
|
|
|
180
|
|
|
$this->markTestIncomplete( |
181
|
|
|
'Test not implemented yet.' |
182
|
|
|
); |
183
|
|
|
} |
184
|
|
|
} |
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.