diff --git a/app/Http/Controllers/OpenAPI/BankTransactionRule.php b/app/Http/Controllers/OpenAPI/BankTransactionRule.php index f62e0cf19a91..522b1764b265 100644 --- a/app/Http/Controllers/OpenAPI/BankTransactionRule.php +++ b/app/Http/Controllers/OpenAPI/BankTransactionRule.php @@ -17,7 +17,7 @@ * ), * @OA\Property(property="auto_convert", type="boolean", example=true, description="Flags whether the rule converts the transaction automatically"), * @OA\Property(property="matches_on_all", type="boolean", example=true, description="Flags whether all subrules are required for the match"), - * @OA\Property(property="applies_to", type="boolean", example="CREDIT", description="Flags whether the rule applies to a CREDIT or DEBIT"), + * @OA\Property(property="applies_to", type="string", example="CREDIT", description="Flags whether the rule applies to a CREDIT or DEBIT"), * @OA\Property(property="client_id", type="string", example="AS3df3A", description="The client hashed id"), * @OA\Property(property="vendor_id", type="string", example="AS3df3A", description="The vendor hashed id"), * @OA\Property(property="category_id", type="string", example="AS3df3A", description="The category hashed id"), diff --git a/app/Http/Requests/BankTransactionRule/StoreBankTransactionRuleRequest.php b/app/Http/Requests/BankTransactionRule/StoreBankTransactionRuleRequest.php index 5f8e8546d94c..f62b7414c710 100644 --- a/app/Http/Requests/BankTransactionRule/StoreBankTransactionRuleRequest.php +++ b/app/Http/Requests/BankTransactionRule/StoreBankTransactionRuleRequest.php @@ -37,7 +37,7 @@ class StoreBankTransactionRuleRequest extends Request 'rules' => 'bail|array', 'auto_convert' => 'bail|sometimes|bool', 'matches_on_all' => 'bail|sometimes|bool', - 'applies_to' => 'bail|sometimes|bool', + 'applies_to' => 'bail|sometimes|string', ]; if(isset($this->category_id)) diff --git a/app/Http/Requests/BankTransactionRule/UpdateBankTransactionRuleRequest.php b/app/Http/Requests/BankTransactionRule/UpdateBankTransactionRuleRequest.php index 8b45a061e4ae..d198a3892eae 100644 --- a/app/Http/Requests/BankTransactionRule/UpdateBankTransactionRuleRequest.php +++ b/app/Http/Requests/BankTransactionRule/UpdateBankTransactionRuleRequest.php @@ -36,7 +36,7 @@ class UpdateBankTransactionRuleRequest extends Request 'rules' => 'bail|array', 'auto_convert' => 'bail|sometimes|bool', 'matches_on_all' => 'bail|sometimes|bool', - 'applies_to' => 'bail|sometimes|bool', + 'applies_to' => 'bail|sometimes|string', ]; if(isset($this->category_id)) diff --git a/app/Models/BankTransactionRule.php b/app/Models/BankTransactionRule.php index 2096072c4619..f2d1e62d905d 100644 --- a/app/Models/BankTransactionRule.php +++ b/app/Models/BankTransactionRule.php @@ -32,6 +32,13 @@ class BankTransactionRule extends BaseModel 'category_id', ]; + protected $casts = [ + 'rules' => 'array', + 'updated_at' => 'timestamp', + 'created_at' => 'timestamp', + 'deleted_at' => 'timestamp', + ]; + protected $dates = [ ]; diff --git a/tests/Feature/BankTransactionRuleApiTest.php b/tests/Feature/BankTransactionRuleApiTest.php index 30ff202c0644..e581788c659a 100644 --- a/tests/Feature/BankTransactionRuleApiTest.php +++ b/tests/Feature/BankTransactionRuleApiTest.php @@ -42,6 +42,91 @@ class BankTransactionRuleApiTest extends TestCase Model::reguard(); } +/* +$rules = [ + 'name' => 'bail|required|string', + 'rules' => 'bail|array', + 'auto_convert' => 'bail|sometimes|bool', + 'matches_on_all' => 'bail|sometimes|bool', + 'applies_to' => 'bail|sometimes|bool', +]; + +if(isset($this->category_id)) + $rules['category_id'] = 'bail|sometimes|exists:expense_categories,id,'.auth()->user()->company()->id.',is_deleted,0'; + +if(isset($this->vendor_id)) + $rules['vendor_id'] = 'bail|sometimes|exists:vendors,id,company_id,'.auth()->user()->company()->id.',is_deleted,0'; + +if(isset($this->client_id)) + $rules['client_id'] = 'bail|sometimes|exists:clients,id,company_id,'.auth()->user()->company()->id.',is_deleted,0'; +*/ + public function testBankRulePost() + { + + $data = [ + 'name' => 'The First Rule', + 'rules' => [], + 'auto_convert' => false, + 'matches_on_all' => false, + 'applies_to' => 'CREDIT', + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson('/api/v1/bank_transaction_rules/', $data); + + $arr = $response->json(); + + $response->assertStatus(200); + + $this->assertEquals('The First Rule', $arr['data']['name']); + + } + + public function testBankRulePut() + { + + $data = [ + 'name' => 'The First Rule', + 'rules' => [], + 'auto_convert' => false, + 'matches_on_all' => false, + 'applies_to' => 'CREDIT', + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson('/api/v1/bank_transaction_rules/', $data); + + $arr = $response->json(); + + $response->assertStatus(200); + + $this->assertEquals('The First Rule', $arr['data']['name']); + + $data = [ + 'name' => 'A New Name For The First Rule', + 'rules' => [], + 'auto_convert' => false, + 'matches_on_all' => false, + 'applies_to' => 'CREDIT', + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->putJson('/api/v1/bank_transaction_rules/'. $arr['data']['id'], $data); + + $arr = $response->json(); + + $response->assertStatus(200); + + $this->assertEquals('A New Name For The First Rule', $arr['data']['name']); + + } + public function testBankTransactionRuleGet() { $response = $this->withHeaders([