updated booking to create for current user

updated test to pass
This commit is contained in:
jack
2018-05-19 16:11:19 +08:00
parent 2783e874bf
commit 8f3a6d82e5
2 changed files with 34 additions and 28 deletions
+4 -3
View File
@@ -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();
+30 -25
View File
@@ -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);
// }
}
}