mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 05:24:35 -04: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());
|
||||
|
||||
//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
|
||||
*/
|
||||
CreateCompanyToken::dispatchNow($company, $account);
|
||||
$company_token = CreateCompanyToken::dispatchNow($company, $user);
|
||||
|
||||
/*
|
||||
* Set current company
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Jobs\Company;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@ -35,15 +36,17 @@ class CreateCompanyToken implements ShouldQueue
|
||||
*
|
||||
* @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;
|
||||
|
||||
protected $guarded = [
|
||||
'id',
|
||||
];
|
||||
|
||||
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) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
$table->increments('id');
|
||||
|
@ -15,8 +15,8 @@
|
||||
<h1 style="text-align: center;">@lang('texts.login_create_an_account')</h1>
|
||||
<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-prepend">
|
||||
<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>
|
||||
</div>
|
||||
|
||||
{{ html()->form()->close() }}
|
||||
|
||||
</form>
|
||||
<div class="card-footer p-4">
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
|
@ -8,6 +8,7 @@ use App\Models\Client;
|
||||
use App\Models\User;
|
||||
use App\Utils\Traits\UserSessionAttributes;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
@ -18,33 +19,35 @@ use Tests\TestCase;
|
||||
class ClientTest extends TestCase
|
||||
{
|
||||
|
||||
use DatabaseTransactions;
|
||||
//use DatabaseTransactions;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Session::start();
|
||||
|
||||
$faker = \Faker\Factory::create();
|
||||
|
||||
$this->data = [
|
||||
'first_name' => $faker->firstName,
|
||||
'last_name' => $faker->lastName,
|
||||
'email' => $faker->unique()->safeEmail,
|
||||
'password' => 'ALongAndBrilliantPassword123',
|
||||
'_token' => csrf_token()
|
||||
];
|
||||
|
||||
// $this->user = CreateAccount::dispatchNow($data);
|
||||
$this->faker = \Faker\Factory::create();
|
||||
Model::reguard();
|
||||
}
|
||||
|
||||
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->assertSuccessful();
|
||||
//$response->assertStatus(200);
|
||||
$response = $this->post('/signup', $data);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson([
|
||||
'first_name' => $data['first_name'],
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user