diff --git a/database/migrations/2018_05_15_090646_change_user_id_in_bookings_table.php b/database/migrations/2018_05_15_090646_change_user_id_in_bookings_table.php index 8175c68a..d629bc96 100644 --- a/database/migrations/2018_05_15_090646_change_user_id_in_bookings_table.php +++ b/database/migrations/2018_05_15_090646_change_user_id_in_bookings_table.php @@ -14,7 +14,7 @@ class ChangeUserIdInBookingsTable extends Migration public function up() { Schema::table('bookings', function (Blueprint $table) { - $table->unsignedInteger('user_id'); + $table->unsignedInteger('user_id')->default('0'); $table->foreign('user_id') ->references('id')->on('users') ->onDelete('cascade'); diff --git a/database/migrations/2018_05_18_063200_add_bia_in_bookings_table.php b/database/migrations/2018_05_18_063200_add_bia_in_bookings_table.php index 5c58ba83..3df8fcd8 100644 --- a/database/migrations/2018_05_18_063200_add_bia_in_bookings_table.php +++ b/database/migrations/2018_05_18_063200_add_bia_in_bookings_table.php @@ -14,7 +14,8 @@ class AddBiaInBookingsTable extends Migration public function up() { Schema::table('bookings', function (Blueprint $table) { - $table->double('bia'); + $table->double('bia')->default('0'); +; }); } diff --git a/database/migrations/2018_05_22_032509_add_bookings_table.php b/database/migrations/2018_05_22_032509_add_bookings_table.php index acc4de7f..02a64841 100644 --- a/database/migrations/2018_05_22_032509_add_bookings_table.php +++ b/database/migrations/2018_05_22_032509_add_bookings_table.php @@ -14,21 +14,21 @@ class AddBookingsTable extends Migration public function up() { Schema::table('bookings', function (Blueprint $table) { - $table->double('rmb_book_amount')->nullable(); - $table->string('rmb_book_pay_method')->nullable(); - $table->string('rmb_book_account_name')->nullable(); - $table->string('rmb_book_bank_name')->nullable(); - $table->string('rmb_book_acc_no')->nullable(); - $table->string('rmb_book_bank_branch')->nullable(); + $table->double('rmb_book_amount')->default('0'); + $table->string('rmb_book_pay_method')->default('0'); + $table->string('rmb_book_account_name')->default('0'); + $table->string('rmb_book_bank_name')->default('0'); + $table->string('rmb_book_acc_no')->default('0'); + $table->string('rmb_book_bank_branch')->default('0'); - $table->double('usd_book_amount')->nullable(); - $table->string('usd_book_pay_method')->nullable(); - $table->string('usd_book_company_name')->nullable(); - $table->string('usd_book_company_address')->nullable(); - $table->string('usd_book_swift_code')->nullable(); - $table->string('usd_book_cnap')->nullable(); - $table->string('usd_book_bank_branch')->nullable(); - $table->boolean('verification_status', true); // Results in a default value of 1. + $table->double('usd_book_amount')->default('0'); + $table->string('usd_book_pay_method')->default('0'); + $table->string('usd_book_company_name')->default('0'); + $table->string('usd_book_company_address')->default('0'); + $table->string('usd_book_swift_code')->default('0'); + $table->string('usd_book_cnap')->default('0'); + $table->string('usd_book_bank_branch')->default('0'); + $table->boolean('verification_status')->default('1'); // Results in a default value of 1. // $table->foreign('status_id') // ->references('id')->on('status') diff --git a/tests/Feature/OAuthTest.php b/tests/Feature/OAuthTest.php deleted file mode 100644 index 405aac0c..00000000 --- a/tests/Feature/OAuthTest.php +++ /dev/null @@ -1,129 +0,0 @@ -getContent(), $text), "Expected text [{$text}] not found."); - - return $this; - }); - - TestResponse::macro('assertTextMissing', function ($text) { - PHPUnit::assertFalse(str_contains($this->getContent(), $text), "Expected missing text [{$text}] found."); - - return $this; - }); - } - - /** @test */ - public function redirect_to_provider() - { - $this->mockSocialite('github'); - - $this->postJson('/api/oauth/github') - ->assertSuccessful() - ->assertJson(['url' => 'https://url-to-provider']); - } - - /** @test */ - public function create_user_and_return_token() - { - $this->mockSocialite('github', [ - 'id' => '123', - 'name' => 'Test User', - 'email' => 'test@example.com', - 'token' => 'access-token', - 'refreshToken' => 'refresh-token', - ]); - - $this->withoutExceptionHandling(); - - $this->get('/api/oauth/github/callback') - ->assertText('token') - ->assertSuccessful(); - - $this->assertDatabaseHas('users', [ - 'name' => 'Test User', - 'email' => 'test@example.com', - ]); - - $this->assertDatabaseHas('oauth_providers', [ - 'user_id' => User::first()->id, - 'provider' => 'github', - 'provider_user_id' => '123', - 'access_token' => 'access-token', - 'refresh_token' => 'refresh-token', - ]); - } - - /** @test */ - public function update_user_and_return_token() - { - $user = factory(User::class)->create(['email' => 'test@example.com']); - $user->oauthProviders()->create([ - 'provider' => 'github', - 'provider_user_id' => '123', - ]); - - $this->mockSocialite('github', [ - 'id' => '123', - 'email' => 'test@example.com', - 'token' => 'updated-access-token', - 'refreshToken' => 'updated-refresh-token', - ]); - - $this->get('/api/oauth/github/callback') - ->assertText('token') - ->assertSuccessful(); - - $this->assertDatabaseHas('oauth_providers', [ - 'user_id' => $user->id, - 'access_token' => 'updated-access-token', - 'refresh_token' => 'updated-refresh-token', - ]); - } - - /** @test */ - public function can_not_create_user_if_email_is_taken() - { - factory(User::class)->create(['email' => 'test@example.com']); - - $this->mockSocialite('github', ['email' => 'test@example.com']); - - $this->get('/api/oauth/github/callback') - ->assertText('Email already taken.') - ->assertTextMissing('token') - ->assertStatus(400); - } - - protected function mockSocialite($provider, $user = null) - { - $mock = Socialite::shouldReceive('stateless') - ->andReturn(m::self()) - ->shouldReceive('driver') - ->with($provider) - ->andReturn(m::self()); - - if ($user) { - $mock->shouldReceive('user') - ->andReturn((new SocialiteUser)->setRaw($user)->map($user)); - } else { - $mock->shouldReceive('redirect') - ->andReturn(redirect('https://url-to-provider')); - } - } -}