MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 8.0.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/.trash/tests.1/Unit/Translator/UserBankAccountTest.php
<?php

namespace Tests\Unit\Translator;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;


use App\Models\SoftwareTool;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Str;
use App\Models\Software;

use App\Models\PaymentMethodType;
use App\Models\UserIdentification;
use App\Models\UserBankAccount;

class UserBankAccountTest extends TestCase
{
    protected $users , $clientData, $address_proof_type, $photo_proof_type;
    protected $user_id, $payment_method_type, $bank_proof_type_id, $bank_proof_file, $bank_account_number;
    protected function setUp(): void 
    {
        parent::setUp();

        $this->payment_method_type = PaymentMethodType::where('payment_method_type','Bank')->first();

        // $this->address_proof_type = \App\Models\AddressProofType::inRandomOrder()->first();
        // $this->photo_proof_type = \App\Models\PhotoProofType::inRandomOrder()->first();

        $this->bank_proof_type_id=1;

        $this->bank_account_number =rand();

        $this->bank_proof_file = 'a.png';
    }

    public function test_to_get_user_bank_account()
    {
        $this->withoutMiddleware();
        $this->withoutExceptionHandling();
        $response = $this->json('GET','/getUserBankAccounts');
        $response->assertOk();
    }

    public function test_to_create_user_bank_account()
    { 
        $bank_name = Str::random(10);
        $user = factory(\App\User::class)->create();
        $profile = factory(\App\Models\Profile::class)->create(['user_id'=>$user->id]);

        $address_proof_type = factory(\App\Models\AddressProofType::class)->create();
        $photo_proof_type = factory(\App\Models\PhotoProofType::class)->create();
        $this->withoutMiddleware();
        $this->withoutExceptionHandling();


        $UserIdentification = factory(UserIdentification::class)->create([
            'user_id' => $user->id,
            'photo_proof_type_id' => $photo_proof_type->id,
            'photo_proof_file' => '123456.png',
            'photo_proof_status_id' => 1,
            'address_proof_type_id' => $address_proof_type->id,
            'address_proof_file' => '123456.png',
            'address_proof_status_id' => 1
        ]);

        $this->actingAs($user)->json('GET','/getUserBankAccounts');
        if($this->payment_method_type->id==2){
            $data = [
            "payment_method_type_id" => $this->payment_method_type->id,
            'paypal_id' => null,
            
        ];
        }
        else{
            $data = [
            "payment_method_type_id" => $this->payment_method_type->id,
            'is_primary' => 1,
            'bank_name'              => $bank_name,
            'beneficiary_name'       => $bank_name,
            'account_no'             => $this->bank_account_number,
            'ifsc_code'              => $this->bank_account_number,
            'branch_address'         => 'df ddfgfdgf gfdg f',
            // 'bank_proof_type_id'     => 1,
            // 'bank_proof_file'        => 'a.png',
        ];
        }
        /*$data = [
            "payment_method_type_id" => $this->payment_method_type->id,
            'is_primary' => 1,
            'bank_name'              => $bank_name,
            'beneficiary_name'       => $bank_name,
            'account_no'             => $this->bank_account_number,
            'ifsc_code'              => $this->bank_account_number,
            'branch_address'         => 'df ddfgfdgf gfdg f',
            // 'bank_proof_type_id'     => 1,
            // 'bank_proof_file'        => 'a.png',
        ];*/
        
        $response = $this->json('POST', 'api/insertUserBankAccount', $data, 
            [
                'Accept' => 'application/json', 
                'HTTP_Authorization' => 'Bearer' . $user->remember_token
            ])
            ->assertStatus(200);
        $response->assertOk();

        UserBankAccount::where('user_id',$user->id)->delete();
        UserIdentification::where('id', $UserIdentification->id)->delete();
        \App\Models\AddressProofType::where('id', $address_proof_type->id)->delete();
        \App\Models\PhotoProofType::where('id', $photo_proof_type->id)->delete();
        \App\Models\Profile::where('id', $profile->id)->delete();
        \App\User::where('id', $user->id)->delete();

        /* $response1 = $this->post('/api/insertUserBankAccount', $data);
        dd($response1->getContent()); // add this temporarily
        $response1->assertResponseStatus(200);*/

    }

    public function test_to_update_user_bank_account()
    {
        $bank_name = Str::random(10);
        $user = factory(\App\User::class)->create();
        $profile = factory(\App\Models\Profile::class)->create(['user_id'=>$user->id]);
        // $userAccountDetail = UserBankAccount::where('user_id',$user->id)->orderBy('id','DESC')->first();

        $address_proof_type = factory(\App\Models\AddressProofType::class)->create();
        $photo_proof_type = factory(\App\Models\PhotoProofType::class)->create();

        $UserIdentification = factory(UserIdentification::class)->create([
            'user_id' => $user->id,
            'photo_proof_type_id' => $photo_proof_type->id,
            'photo_proof_file' => '123456.png',
            'photo_proof_status_id' => 1,
            'address_proof_type_id' => $address_proof_type->id,
            'address_proof_file' => '123456.png',
            'address_proof_status_id' => 1
        ]);

        $userAccountDetail =factory(UserBankAccount::class)->create(['user_id'=>$user->id]);

        $this->withoutMiddleware();
        $this->withoutExceptionHandling();
        
        $this->actingAs($user)->json('GET','/getUserBankAccounts');

        if($this->payment_method_type->id==2){
          $data = [
            "payment_method_type_id" => $this->payment_method_type->id,
            'paypal_id' =>null,
            'id' => $userAccountDetail->id
        ];
        }else{
            $data = [
            "payment_method_type_id" => $this->payment_method_type->id,
            'is_primary' => 1,
            'bank_name'              => $bank_name,
            'beneficiary_name'       => $bank_name,
            'account_no'             => $this->bank_account_number,
            'ifsc_code'              => $this->bank_account_number,
            'branch_address'         => 'df ddfgfdgf gfdg f',
            'id' => $userAccountDetail->id
        ];
        }
        /*$data = [
            "payment_method_type_id" => $this->payment_method_type->id,
            'is_primary' => 1,
            'bank_name'              => $bank_name,
            'beneficiary_name'       => $bank_name,
            'account_no'             => $this->bank_account_number,
            'ifsc_code'              => $this->bank_account_number,
            'branch_address'         => 'df ddfgfdgf gfdg f',
            'id' => $userAccountDetail->id
        ];*/
        
        $response = $this->json('POST', 'api/updateUserBankAccount', $data, 
            [
                'Accept' => 'application/json', 
                'HTTP_Authorization' => 'Bearer' . $user->remember_token
            ])
            ->assertStatus(200);
        $response->assertOk();


        UserBankAccount::where('id',$userAccountDetail->id)->delete();
        UserIdentification::where('id', $UserIdentification->id)->delete();
        \App\Models\AddressProofType::where('id', $address_proof_type->id)->delete();
        \App\Models\PhotoProofType::where('id', $photo_proof_type->id)->delete();
        \App\Models\Profile::where('id', $profile->id)->delete();
        \App\User::where('id', $user->id)->delete();

    }


    public function test_to_delete_user_bank_account()
    {
        $bank_name = Str::random(10);
        $user = factory(\App\User::class)->create();
        $profile = factory(\App\Models\Profile::class)->create(['user_id'=>$user->id]);
        // $userAccountDetail = UserBankAccount::where('user_id',$user->id)->orderBy('id','DESC')->first();

        $address_proof_type = factory(\App\Models\AddressProofType::class)->create();
        $photo_proof_type = factory(\App\Models\PhotoProofType::class)->create();

        $UserIdentification = factory(UserIdentification::class)->create([
            'user_id' => $user->id,
            'photo_proof_type_id' => $photo_proof_type->id,
            'photo_proof_file' => '123456.png',
            'photo_proof_status_id' => 1,
            'address_proof_type_id' => $address_proof_type->id,
            'address_proof_file' => '123456.png',
            'address_proof_status_id' => 1
        ]);

        $userAccountDetail =factory(UserBankAccount::class)->create(['user_id'=>$user->id]);
        $this->withoutMiddleware();
        $this->withoutExceptionHandling();
        
        $this->actingAs($user)->json('GET','/getUserBankAccounts');
        $data = [
            'id' => $userAccountDetail->id
        ];
        
        $response = $this->json('POST', 'api/deleteUserBankAccount', $data, 
            [
                'Accept' => 'application/json', 
                'HTTP_Authorization' => 'Bearer' . $user->remember_token
            ])
            ->assertStatus(200);
        $response->assertOk();

        UserBankAccount::where('id',$userAccountDetail->id)->delete();
        UserIdentification::where('id', $UserIdentification->id)->delete();
        \App\Models\AddressProofType::where('id', $address_proof_type->id)->delete();
        \App\Models\PhotoProofType::where('id', $photo_proof_type->id)->delete();
        \App\Models\Profile::where('id', $profile->id)->delete();
        \App\User::where('id', $user->id)->delete();
    }



    public function tearDown(): void
    {
        $maxId = \DB::table('user_bank_accounts')->max('id');
        \DB::statement('ALTER TABLE user_bank_accounts AUTO_INCREMENT=' . intval($maxId + 1) . ';');

        $maxId = \DB::table('user_identifications')->max('id');
        \DB::statement('ALTER TABLE user_identifications AUTO_INCREMENT=' . intval($maxId + 1) . ';');

        $maxId = \DB::table('address_proof_types')->max('id');
        \DB::statement('ALTER TABLE address_proof_types AUTO_INCREMENT=' . intval($maxId + 1) . ';');

        $maxId = \DB::table('photo_proof_types')->max('id');
        \DB::statement('ALTER TABLE photo_proof_types AUTO_INCREMENT=' . intval($maxId + 1) . ';');

        $maxId = \DB::table('profiles')->max('id');
        \DB::statement('ALTER TABLE profiles AUTO_INCREMENT=' . intval($maxId + 1) . ';');

        $maxId = \DB::table('users')->max('id');
        \DB::statement('ALTER TABLE users AUTO_INCREMENT=' . intval($maxId + 1) . ';');
        parent::tearDown();
    }
}