mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 23:07:32 -05:00 
			
		
		
		
	testing api
This commit is contained in:
		
							parent
							
								
									7defe077bc
								
							
						
					
					
						commit
						e8da725aa1
					
				@ -49,8 +49,8 @@ class AccountController extends Controller
 | 
				
			|||||||
        $user = CreateAccount::dispatchNow($request->all());
 | 
					        $user = CreateAccount::dispatchNow($request->all());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //todo redirect to localization setup workflow
 | 
					        //todo redirect to localization setup workflow
 | 
				
			||||||
        return redirect()->route('dashboard.index');
 | 
					        //return redirect()->route('dashboard.index');
 | 
				
			||||||
 | 
					        return response()->json($user);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -63,7 +63,7 @@ class CreateAccount
 | 
				
			|||||||
        /*
 | 
					        /*
 | 
				
			||||||
         * Create token
 | 
					         * Create token
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        CreateCompanyToken::dispatchNow($company, $account);
 | 
					        $company_token = CreateCompanyToken::dispatchNow($company, $user);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /*
 | 
					        /*
 | 
				
			||||||
         * Set current company
 | 
					         * Set current company
 | 
				
			||||||
 | 
				
			|||||||
@ -3,6 +3,7 @@
 | 
				
			|||||||
namespace App\Jobs\Company;
 | 
					namespace App\Jobs\Company;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use App\Models\Company;
 | 
					use App\Models\Company;
 | 
				
			||||||
 | 
					use App\Models\CompanyToken;
 | 
				
			||||||
use App\Models\User;
 | 
					use App\Models\User;
 | 
				
			||||||
use Illuminate\Bus\Queueable;
 | 
					use Illuminate\Bus\Queueable;
 | 
				
			||||||
use Illuminate\Contracts\Queue\ShouldQueue;
 | 
					use Illuminate\Contracts\Queue\ShouldQueue;
 | 
				
			||||||
@ -35,15 +36,17 @@ class CreateCompanyToken implements ShouldQueue
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return void
 | 
					     * @return void
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function handle() : void
 | 
					    public function handle() : ?CompanyToken
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $company_token = [
 | 
					 | 
				
			||||||
            'user_id' => $this->user->id,
 | 
					 | 
				
			||||||
            'account_id' => $company->account->id,
 | 
					 | 
				
			||||||
            'token' => str_random(64),
 | 
					 | 
				
			||||||
            'name' => $user->first_name. ' '. $user->last_name;
 | 
					 | 
				
			||||||
        ];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->company->tokens()->attach($company->id, $company_token);
 | 
					        $ct = CompanyToken::create([
 | 
				
			||||||
 | 
					            'user_id' => $this->user->id,
 | 
				
			||||||
 | 
					            'account_id' => $this->company->account->id,
 | 
				
			||||||
 | 
					            'token' => str_random(64),
 | 
				
			||||||
 | 
					            'name' => $this->user->first_name. ' '. $this->user->last_name,
 | 
				
			||||||
 | 
					            'company_id' => $this->company->id,
 | 
				
			||||||
 | 
					        ]);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        return $ct;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -11,6 +11,9 @@ class CompanyToken extends BaseModel
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public $timestamps = false;
 | 
					    public $timestamps = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected $guarded = [
 | 
				
			||||||
 | 
					        'id',
 | 
				
			||||||
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function account()
 | 
					    public function account()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
				
			|||||||
@ -181,18 +181,7 @@ class CreateUsersTable extends Migration
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Schema::create('company_tokens', function (Blueprint $table) {
 | 
					 | 
				
			||||||
            $table->increments('id');
 | 
					 | 
				
			||||||
            $table->unsignedInteger('company_id');
 | 
					 | 
				
			||||||
            $table->unsignedInteger('account_id');
 | 
					 | 
				
			||||||
            $table->unsignedInteger('user_id')->index();
 | 
					 | 
				
			||||||
            $table->string('token')->nullable();
 | 
					 | 
				
			||||||
            $table->string('name')->nullable();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
 | 
					 | 
				
			||||||
            $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
 | 
					 | 
				
			||||||
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        Schema::create('users', function (Blueprint $table) {
 | 
					        Schema::create('users', function (Blueprint $table) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -227,6 +216,20 @@ class CreateUsersTable extends Migration
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Schema::create('company_tokens', function (Blueprint $table) {
 | 
				
			||||||
 | 
					            $table->increments('id');
 | 
				
			||||||
 | 
					            $table->unsignedInteger('company_id');
 | 
				
			||||||
 | 
					            $table->unsignedInteger('account_id');
 | 
				
			||||||
 | 
					            $table->unsignedInteger('user_id')->index();
 | 
				
			||||||
 | 
					            $table->string('token')->nullable();
 | 
				
			||||||
 | 
					            $table->string('name')->nullable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
 | 
				
			||||||
 | 
					            $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
 | 
				
			||||||
 | 
					            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        Schema::create('clients', function (Blueprint $table) {
 | 
					        Schema::create('clients', function (Blueprint $table) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $table->increments('id');
 | 
					            $table->increments('id');
 | 
				
			||||||
 | 
				
			|||||||
@ -15,8 +15,8 @@
 | 
				
			|||||||
                        <h1 style="text-align: center;">@lang('texts.login_create_an_account')</h1>
 | 
					                        <h1 style="text-align: center;">@lang('texts.login_create_an_account')</h1>
 | 
				
			||||||
                        <p class="text-muted"></p>
 | 
					                        <p class="text-muted"></p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        {{ html()->form('POST', route('signup.submit'))->open() }}
 | 
					                            <form method="POST" action="{{ route('signup.submit')}}">
 | 
				
			||||||
 | 
					                            @csrf
 | 
				
			||||||
                        <div class="input-group mb-3">
 | 
					                        <div class="input-group mb-3">
 | 
				
			||||||
                            <div class="input-group-prepend">
 | 
					                            <div class="input-group-prepend">
 | 
				
			||||||
                                <span class="input-group-text">
 | 
					                                <span class="input-group-text">
 | 
				
			||||||
@ -98,8 +98,7 @@
 | 
				
			|||||||
                        <button class="btn btn-block btn-success" type="submit" :disabled="!isDisabled">@lang('texts.create_account')</button>
 | 
					                        <button class="btn btn-block btn-success" type="submit" :disabled="!isDisabled">@lang('texts.create_account')</button>
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    {{ html()->form()->close() }}
 | 
					                    </form>
 | 
				
			||||||
 | 
					 | 
				
			||||||
                    <div class="card-footer p-4">
 | 
					                    <div class="card-footer p-4">
 | 
				
			||||||
                        <div class="row">
 | 
					                        <div class="row">
 | 
				
			||||||
                            <div class="col-6">
 | 
					                            <div class="col-6">
 | 
				
			||||||
 | 
				
			|||||||
@ -8,6 +8,7 @@ use App\Models\Client;
 | 
				
			|||||||
use App\Models\User;
 | 
					use App\Models\User;
 | 
				
			||||||
use App\Utils\Traits\UserSessionAttributes;
 | 
					use App\Utils\Traits\UserSessionAttributes;
 | 
				
			||||||
use Faker\Factory;
 | 
					use Faker\Factory;
 | 
				
			||||||
 | 
					use Illuminate\Database\Eloquent\Model;
 | 
				
			||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
 | 
					use Illuminate\Foundation\Testing\DatabaseTransactions;
 | 
				
			||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
 | 
					use Illuminate\Foundation\Testing\RefreshDatabase;
 | 
				
			||||||
use Illuminate\Foundation\Testing\WithFaker;
 | 
					use Illuminate\Foundation\Testing\WithFaker;
 | 
				
			||||||
@ -18,33 +19,35 @@ use Tests\TestCase;
 | 
				
			|||||||
class ClientTest extends TestCase
 | 
					class ClientTest extends TestCase
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    use DatabaseTransactions;
 | 
					    //use DatabaseTransactions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function setUp()
 | 
					    public function setUp()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        parent::setUp();
 | 
					        parent::setUp();
 | 
				
			||||||
        Session::start();
 | 
					        Session::start();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $faker = \Faker\Factory::create();
 | 
					        $this->faker = \Faker\Factory::create();
 | 
				
			||||||
 | 
					        Model::reguard();
 | 
				
			||||||
        $this->data = [
 | 
					 | 
				
			||||||
            'first_name' => $faker->firstName,
 | 
					 | 
				
			||||||
            'last_name' => $faker->lastName,
 | 
					 | 
				
			||||||
            'email' => $faker->unique()->safeEmail,
 | 
					 | 
				
			||||||
            'password' => 'ALongAndBrilliantPassword123',
 | 
					 | 
				
			||||||
            '_token' => csrf_token()
 | 
					 | 
				
			||||||
        ];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
       // $this->user = CreateAccount::dispatchNow($data);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function testAccountCreation()
 | 
					    public function testAccountCreation()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $response = $this->post('/signup', $this->data);
 | 
					        $data = [
 | 
				
			||||||
 | 
					            'first_name' => $this->faker->firstName,
 | 
				
			||||||
 | 
					            'last_name' => $this->faker->lastName,
 | 
				
			||||||
 | 
					            'email' => $this->faker->unique()->safeEmail,
 | 
				
			||||||
 | 
					            'password' => 'ALongAndBrilliantPassword123',
 | 
				
			||||||
 | 
					            '_token' => csrf_token(),
 | 
				
			||||||
 | 
					            'privacy_policy' => 1,
 | 
				
			||||||
 | 
					            'terms_of_service' => 1
 | 
				
			||||||
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->assertEquals($response->json(), 'yadda');
 | 
					        $response = $this->post('/signup', $data);
 | 
				
			||||||
        //$response->assertSuccessful();
 | 
					
 | 
				
			||||||
        //$response->assertStatus(200);
 | 
					        $response->assertStatus(200)
 | 
				
			||||||
 | 
					                ->assertJson([
 | 
				
			||||||
 | 
					                'first_name' => $data['first_name'],
 | 
				
			||||||
 | 
					            ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user