mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 00:07:35 -05:00 
			
		
		
		
	Fixes for CRUD actions on bank transaction rules
This commit is contained in:
		
							parent
							
								
									069568da6e
								
							
						
					
					
						commit
						3562c3376c
					
				@ -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="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="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="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="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"),
 | 
					 *       @OA\Property(property="category_id", type="string", example="AS3df3A", description="The category hashed id"),
 | 
				
			||||||
 | 
				
			|||||||
@ -37,7 +37,7 @@ class StoreBankTransactionRuleRequest extends Request
 | 
				
			|||||||
            'rules' => 'bail|array',
 | 
					            'rules' => 'bail|array',
 | 
				
			||||||
            'auto_convert' => 'bail|sometimes|bool',
 | 
					            'auto_convert' => 'bail|sometimes|bool',
 | 
				
			||||||
            'matches_on_all' => 'bail|sometimes|bool',
 | 
					            'matches_on_all' => 'bail|sometimes|bool',
 | 
				
			||||||
            'applies_to' => 'bail|sometimes|bool',
 | 
					            'applies_to' => 'bail|sometimes|string',
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(isset($this->category_id)) 
 | 
					        if(isset($this->category_id)) 
 | 
				
			||||||
 | 
				
			|||||||
@ -36,7 +36,7 @@ class UpdateBankTransactionRuleRequest extends Request
 | 
				
			|||||||
            'rules' => 'bail|array',
 | 
					            'rules' => 'bail|array',
 | 
				
			||||||
            'auto_convert' => 'bail|sometimes|bool',
 | 
					            'auto_convert' => 'bail|sometimes|bool',
 | 
				
			||||||
            'matches_on_all' => 'bail|sometimes|bool',
 | 
					            'matches_on_all' => 'bail|sometimes|bool',
 | 
				
			||||||
            'applies_to' => 'bail|sometimes|bool',
 | 
					            'applies_to' => 'bail|sometimes|string',
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(isset($this->category_id)) 
 | 
					        if(isset($this->category_id)) 
 | 
				
			||||||
 | 
				
			|||||||
@ -32,6 +32,13 @@ class BankTransactionRule extends BaseModel
 | 
				
			|||||||
        'category_id',
 | 
					        'category_id',
 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected $casts = [
 | 
				
			||||||
 | 
					        'rules' => 'array',
 | 
				
			||||||
 | 
					        'updated_at' => 'timestamp',
 | 
				
			||||||
 | 
					        'created_at' => 'timestamp',
 | 
				
			||||||
 | 
					        'deleted_at' => 'timestamp',
 | 
				
			||||||
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected $dates = [
 | 
					    protected $dates = [
 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
				
			|||||||
@ -42,6 +42,91 @@ class BankTransactionRuleApiTest extends TestCase
 | 
				
			|||||||
        Model::reguard();
 | 
					        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()
 | 
					    public function testBankTransactionRuleGet()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $response = $this->withHeaders([
 | 
					        $response = $this->withHeaders([
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user