From 8f3a6d82e50bfc9d8c50853bbd8bda57917d0bb1 Mon Sep 17 00:00:00 2001 From: jack Date: Sat, 19 May 2018 16:11:19 +0800 Subject: [PATCH] updated booking to create for current user updated test to pass --- app/Http/Controllers/BookingController.php | 7 +-- tests/Unit/BookingTest.php | 55 ++++++++++++---------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/app/Http/Controllers/BookingController.php b/app/Http/Controllers/BookingController.php index afa6ec6d..5cfd855e 100644 --- a/app/Http/Controllers/BookingController.php +++ b/app/Http/Controllers/BookingController.php @@ -6,6 +6,7 @@ use Illuminate\Http\Request; use App\Booking; use App\Rate; use App\User; +use Auth; class BookingController extends Controller { @@ -72,7 +73,7 @@ class BookingController extends Controller $bia = round(($amount + ($svcharge / $rate) + 0.06), 2); // return $bia; - $user = User::first(); + $user = Auth::user(); $booking = new Booking(); $booking->account_name = $request->input('account_name'); $booking->account_num = $request->input('account_num'); @@ -86,8 +87,8 @@ class BookingController extends Controller $booking->term = $request->input('term'); $booking->amount = $request->input('amount'); $booking->rate_id = $rate; - // $booking->user()->associate($user); - $booking->user_id = $request->input('user_id'); + $booking->user()->associate($user); + //$booking->user_id = $request->input('user_id'); $booking->bia = $bia; $booking->save(); diff --git a/tests/Unit/BookingTest.php b/tests/Unit/BookingTest.php index b8d61f48..fe5b01bd 100644 --- a/tests/Unit/BookingTest.php +++ b/tests/Unit/BookingTest.php @@ -3,13 +3,23 @@ namespace Tests\Unit\BookingTest; use Tests\TestCase; -use Illuminate\Foundation\Testing\WithFaker; -use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithoutMiddleware; - +use Illuminate\Database\Seeder; +use Illuminate\Foundation\Testing\DatabaseMigrations; +use Artisan; +use App\User; class BookingTest extends TestCase { + protected $user; + + public function setUp() + { + parent::setUp(); + Artisan::call('db:seed'); + $this->user = factory(User::class)->create(); + } + /** * A basic test example. * @@ -36,27 +46,22 @@ class BookingTest extends TestCase public function testPost() { - $response = $this->json('POST', '/api/booking/', [ - - 'account_name' => 'johnny', - 'account_num' => '1234567', - 'bank_name' => 'myabnak', - 'bank_branch' => 'banking', - 'company_name' => 'besaras', - 'company_address' => 'californina', - 'bank_address' => 'cyber', - 'swift_code' => '123wert', - 'cnap' => '2131rew', - 'term' => 'x1_cash', - 'amount' => '14000', - 'user_id' => '1', - - ]); - dd($response->getContent()); - $response - ->assertStatus(201); - - //dd($response->getContent()); + $response = + $this->actingAs($this->user) + ->postJson('/api/booking/', [ + 'account_name' => 'johnny', + 'account_num' => '1234567', + 'bank_name' => 'myabnak', + 'bank_branch' => 'banking', + 'company_name' => 'besaras', + 'company_address' => 'californina', + 'bank_address' => 'cyber', + 'swift_code' => '123wert', + 'cnap' => '2131rew', + 'term' => 'x1_cash', + 'amount' => '14000' + ]); + $response->assertStatus(201); } // public function testPut() @@ -85,4 +90,4 @@ class BookingTest extends TestCase // $response->assertStatus(204); // } -} +} \ No newline at end of file