Merge branch 'too/cancelbooking' into 'master'

New Route for booking cancel. Fix bookingTest hardcoded link. Add Cancel…

See merge request CIEFWorldwideSdnBhd/exchange!16
This commit is contained in:
Jack Goh
2018-06-16 09:40:31 +00:00
7 changed files with 147 additions and 48 deletions
+17 -6
View File
@@ -17,7 +17,7 @@ class BookingController extends Controller
public function store(Request $request)
{
$rates = Rate::all()->last();
$rates = Rate::orderby('updated_at','desc')->first();
$term = $request->input('term');
$rate = 1; // default
switch ($term) {
@@ -129,7 +129,7 @@ class BookingController extends Controller
public function uploadbankslip(Request $request, $id)
{
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
/* Validation*/
if (!$booking)
{
@@ -175,7 +175,7 @@ class BookingController extends Controller
public function uploadPurchaseOrder(Request $request, $id)
{
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
$booking = Booking::where('user_id',Auth::user()->id)->where('id',$id)->first();
/* Validation */
if (!$booking)
@@ -198,13 +198,12 @@ class BookingController extends Controller
}
/* End Validation */
$filename = $user_input_file->getClientOriginalName();
$ext = $user_input_file->getClientOriginalExtension();
$input['image_url'] = $filename;
$unique_name = 'purchase_order_' . md5($filename. time());
$unique_image_url = $unique_name. '.' .$ext;
$unique_image_url = $unique_name. '.' .$ext;
Storage::putFileAs(
'image_url',/*folder name*/ $user_input_file, $unique_image_url
);
@@ -217,6 +216,7 @@ class BookingController extends Controller
return response()->json(['message'=>'Success'],200);
}
public function delete(Booking $book_id)
{
$booking = Booking::where('user_id', Auth::user())->where('id', $book_id)->firstOrFail();
@@ -224,5 +224,16 @@ class BookingController extends Controller
return response()->json($book_id, 204);
}
// TODO : cancel booking feature
public function cancel(Request $request, $book_id)
{
if (!$booking = Booking::where('user_id',Auth::user()->id)->where('id',$book_id)->first())
{
return response()->json(['message'=>'Access denied'], 200);
}
$booking->is_cancel = true;
$booking->save();
return response()->json(['message'=>'Success'],200);
}
}
+40
View File
@@ -0,0 +1,40 @@
<?php
use Faker\Generator as Faker;
$factory->define(App\Booking::class, function (Faker $faker) {
$rate_id = App\Rate::pluck('id')->toArray();
$user_id = App\User::pluck('id')->toArray();
return [
'account_name' => $faker->name,
'account_num' => $faker->unique()->randomDigit,
'bank_name' => $faker->name,
'bank_branch' => $faker->unique()->address,
'company_name' => $faker->name,
'company_address' => $faker->unique()->address,
'bank_address' => $faker->unique()->address,
'swift_code' => $faker->unique()->randomDigit,
'cnap' => $faker->randomDigit,
'term' => str_random(10),
'amount'=> $faker->randomDigit,
'rate_id' => $faker->randomElement($rate_id),
'user_id' => $faker->randomElement($user_id),
'rmb_book_amount' => $faker->randomDigit,
'rmb_book_pay_method' => str_random(10),
'rmb_book_account_name' => $faker->name,
'rmb_book_acc_no' => $faker->randomDigit,
'rmb_book_bank_branch' => $faker->unique()->address,
'usd_book_amount' => $faker->randomDigit,
'usd_book_pay_method'=> str_random(10),
'usd_book_company_name'=> $faker->name,
'usd_book_company_address' => $faker->unique()->address,
'usd_book_swift_code'=> $faker->unique()->randomDigit,
'usd_book_cnap' => $faker->randomDigit,
'usd_book_bank_branch' => $faker->unique()->address,
];
});
@@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddCancelBookingTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('bookings', function (Blueprint $table) {
$table->boolean('is_cancel')->default('0');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
if (Schema::hasColumn('bookings', 'is_cancel')) {
Schema::table('bookings', function (Blueprint $table) {
// $table->dropColumn('is_cancel');
});
}
}
}
+1
View File
@@ -81,5 +81,6 @@ Route::delete('setting-supplier/{supplier}', 'SettingSupplierController@delete')
Route::post('upload-china-bankslip', 'ChinaBankSlipController@store');
Route::post('booking/{book_id}/cancel', 'BookingController@cancel');
Route::post('booking/{id}/upload-user-bankslip', 'BookingController@uploadbankslip');
Route::post('booking/{id}/upload-po', 'BookingController@uploadPurchaseOrder');
+53 -40
View File
@@ -18,77 +18,90 @@ use App\Booking;
class BookingTest extends TestCase
{
protected $user;
protected $booking;
public function setUp()
{
parent::setUp();
Artisan::call('db:seed');
$this->user = factory(User::class)->create();
$this->booking = factory(Booking::class)->create([
'user_id' => $this->user->id
]);
}
public function testPost()
{
$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' => 'x2_cash',
'amount' => '14000',
'rmb_book_amount' => '2131',
'rmb_book_pay_method' => '2131rea',
'rmb_book_account_name' => '2131rew',
'rmb_book_acc_no' => '2131',
'rmb_book_bank_branch' => '2131rew',
'usd_book_amount' => '2131',
'usd_book_pay_method' => '2131rew',
'usd_book_company_name' => '2131rew',
'usd_book_company_address' => '2131rew',
'usd_book_swift_code' => '2131rew',
'usd_book_cnap' => '2131rew',
'usd_book_bank_branch' => '2131rew',
'verification_status' => '1'
]);
$response->assertStatus(201);
->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' => 'x2_cash',
'amount' => '14000',
'rmb_book_amount' => '2131',
'rmb_book_pay_method' => '2131rea',
'rmb_book_account_name' => '2131rew',
'rmb_book_acc_no' => '2131',
'rmb_book_bank_branch' => '2131rew',
'usd_book_amount' => '2131',
'usd_book_pay_method' => '2131rew',
'usd_book_company_name' => '2131rew',
'usd_book_company_address' => '2131rew',
'usd_book_swift_code' => '2131rew',
'usd_book_cnap' => '2131rew',
'usd_book_bank_branch' => '2131rew',
'verification_status' => '1'
])
->assertStatus(201);
}
public function testuploadbankslip()
{
$this->actingAs($this->user);
Storage::fake('bankslip_url');
$bankslip_url = UploadedFile::fake()->image('comp.jpg');
if(!file_exists($bankslip_url)){
$response->assertStatus(400);
}
$response = $this->json('POST', '/api/booking/1/upload-user-bankslip', [
'bankslip_url' => $bankslip_url,
'transfer_amount' => '9000'
]);
$response->assertStatus(200);
$this->actingAs($this->user)
->json('POST', '/api/booking/' . $this->booking->id . '/upload-user-bankslip', [
'bankslip_url' => $bankslip_url,
'transfer_amount' => '9000'
])
->assertSuccessful();
}
public function testuploadPO()
{
$this->actingAs($this->user);
Storage::fake('image_url');
$image_url = UploadedFile::fake()->image('comp.jpg');
if(!file_exists($image_url)){
$response->assertStatus(400);
}
$response = $this->json('POST', '/api/booking/1/upload-po', [
'image_url' => UploadedFile::fake()->image('comp.jpg'),
'amount' => '12345'
]);
$response->assertStatus(200);
$this->actingAs($this->user)
->json('POST', '/api/booking/' . $this->booking->id . '/upload-po', [
'image_url' => UploadedFile::fake()->image('comp.jpg'),
'amount' => '12345'
])
->assertSuccessful();
}
public function testCancel()
{
$this->actingAs($this->user)
->json('POST','/api/booking/' . $this->booking->id . '/cancel', [])
->assertSuccessful();
}
}
+1 -1
View File
@@ -4131,7 +4131,7 @@ return array(
'Tests\\Feature\\RegisterTest' => $baseDir . '/tests/Feature/RegisterTest.php',
'Tests\\Feature\\SettingsTest' => $baseDir . '/tests/Feature/SettingsTest.php',
'Tests\\TestCase' => $baseDir . '/tests/TestCase.php',
'Tests\\Unit\\BookingTest\\BookingTest' => $baseDir . '/tests/Feature/BookingTest2.php',
'Tests\\Unit\\BookingTest\\BookingTest' => $baseDir . '/tests/Feature/BookingTest.php',
'Text_Template' => $vendorDir . '/phpunit/php-text-template/src/Template.php',
'TheSeer\\Tokenizer\\Exception' => $vendorDir . '/theseer/tokenizer/src/Exception.php',
'TheSeer\\Tokenizer\\NamespaceUri' => $vendorDir . '/theseer/tokenizer/src/NamespaceUri.php',
+1 -1
View File
@@ -4559,7 +4559,7 @@ class ComposerStaticInit6dcfe61ea7999ade723f072fea748b5a
'Tests\\Feature\\RegisterTest' => __DIR__ . '/../..' . '/tests/Feature/RegisterTest.php',
'Tests\\Feature\\SettingsTest' => __DIR__ . '/../..' . '/tests/Feature/SettingsTest.php',
'Tests\\TestCase' => __DIR__ . '/../..' . '/tests/TestCase.php',
'Tests\\Unit\\BookingTest\\BookingTest' => __DIR__ . '/../..' . '/tests/Feature/BookingTest2.php',
'Tests\\Unit\\BookingTest\\BookingTest' => __DIR__ . '/../..' . '/tests/Feature/BookingTest.php',
'Text_Template' => __DIR__ . '/..' . '/phpunit/php-text-template/src/Template.php',
'TheSeer\\Tokenizer\\Exception' => __DIR__ . '/..' . '/theseer/tokenizer/src/Exception.php',
'TheSeer\\Tokenizer\\NamespaceUri' => __DIR__ . '/..' . '/theseer/tokenizer/src/NamespaceUri.php',