|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
+use App\Carrier;
|
|
|
use App\WaybillAuditLog;
|
|
|
use App\Authority;
|
|
|
use App\WaybillPriceModel;
|
|
|
@@ -50,39 +51,102 @@ class WaybillTest extends TestCase
|
|
|
public function testAddWaybill(){
|
|
|
$waybill=new Waybill([
|
|
|
'type'=>'直发车',
|
|
|
- 'state'=>'未审核',
|
|
|
- 'waybill_number'=>'BSZX12345848854',
|
|
|
- 'owner_id'=>2,
|
|
|
- 'wms_bill_number'=>'zx1858545465',
|
|
|
- 'origination'=>'上海松江',
|
|
|
- 'destination'=>'郑州中原',
|
|
|
- 'recipient'=>'elder sister',
|
|
|
- 'recipient_mobile'=>'18458741254',
|
|
|
- 'charge'=>586,
|
|
|
- 'ordering_remark'=>'禁'
|
|
|
+ 'waybill_number'=>'TestBSZF12345848854',
|
|
|
+ 'owner_id'=>1,
|
|
|
+ 'wms_bill_number'=>'test1858545465',
|
|
|
+ 'origination'=>'test',
|
|
|
+ 'destination'=>'test',
|
|
|
+ 'recipient'=>'test sister',
|
|
|
+ 'recipient_mobile'=>'025487456',
|
|
|
+ 'charge'=>586.5,
|
|
|
+ 'collect_fee'=>30,
|
|
|
+ 'ordering_remark'=>'test'
|
|
|
]);
|
|
|
$result=$waybill->save();
|
|
|
$this->assertTrue($result);
|
|
|
- $this->assertNotEmpty($waybill);
|
|
|
+ $this->assertNotEmpty($waybill->charge);
|
|
|
return $waybill;
|
|
|
}
|
|
|
|
|
|
+ public function testAddWaybillZX(){
|
|
|
+ $waybillZX=new Waybill([
|
|
|
+ 'type'=>'专线',
|
|
|
+ 'status'=>'未审核',
|
|
|
+ 'waybill_number'=>'testBSZX123451468',
|
|
|
+ 'owner_id'=>1,
|
|
|
+ 'wms_bill_number'=>'test01547860548',
|
|
|
+ 'origination'=>'上海',
|
|
|
+ 'destination'=>'郑州',
|
|
|
+ 'recipient'=>'elder sister',
|
|
|
+ 'recipient_mobile'=>'12364851478',
|
|
|
+ 'charge'=>586,
|
|
|
+ 'ordering_remark'=>'禁'
|
|
|
+ ]);
|
|
|
+ $waybillZX->save();
|
|
|
+ $this->assertNotEmpty($waybillZX);
|
|
|
+ return $waybillZX;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testAddWaybillPriceModel(){
|
|
|
+ $waybillPriceModel=WaybillPriceModel::create([
|
|
|
+ 'carrier_id'=>1,
|
|
|
+ 'province_id'=>1,
|
|
|
+ 'city_id'=>1,
|
|
|
+ 'unit_id'=>1,
|
|
|
+ 'range_min'=>0,
|
|
|
+ 'range_max'=>2000,
|
|
|
+ 'unit_price'=>5,
|
|
|
+ 'base_fee'=>10,
|
|
|
+ 'initial_weight'=>10
|
|
|
+ ]);
|
|
|
+ $this->assertNotEmpty($waybillPriceModel);
|
|
|
+ return $waybillPriceModel;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testAddWaybillPriceModelTwo(){
|
|
|
+ $waybillPriceModelTwo=WaybillPriceModel::create([
|
|
|
+ 'carrier_id'=>1,
|
|
|
+ 'province_id'=>1,
|
|
|
+ 'unit_id'=>3,
|
|
|
+ 'unit_price'=>5,
|
|
|
+ 'base_fee'=>10,
|
|
|
+ 'initial_weight'=>10
|
|
|
+ ]);
|
|
|
+ $this->assertNotEmpty($waybillPriceModelTwo);
|
|
|
+ return $waybillPriceModelTwo;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testAddCarrier(){
|
|
|
+ $carrier=Carrier::create([
|
|
|
+ 'name'=>'test承运商',
|
|
|
+ 'mobile'=>'000005416',
|
|
|
+ 'remark'=>'test',
|
|
|
+ 'delivery_fee'=>170
|
|
|
+ ]);
|
|
|
+ $this->assertNotEmpty($carrier);
|
|
|
+ return $carrier;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @depends testUser
|
|
|
* @depends testAddWaybill
|
|
|
* @depends testUserMark
|
|
|
*/
|
|
|
public function testIndex(User $user,Waybill $waybill,User $userMark){
|
|
|
- $responseFalse=$this->actingAs($user)->get('waybill',[
|
|
|
- 'waybill_number'=>'BSZX12345848854'
|
|
|
+ $responseFalse=$this->actingAs($user)->get('waybill/index',[
|
|
|
+ 'waybill_number'=>'TestBSZF12345848854'
|
|
|
]);
|
|
|
- $responseFalse->assertOk()->assertSee('BSZX12345848854');
|
|
|
- $responseMark=$this->actingAs($userMark)->get('waybill',[
|
|
|
- 'waybill_number'=>'BSZX12345848854'
|
|
|
+ $responseFalseZX=$this->actingAs($user)->get('waybill/index/ZX');
|
|
|
+ $responseFalseZF=$this->actingAs($user)->get('waybill/index/ZF');
|
|
|
+ $responseFalseZX->assertOk();
|
|
|
+ $responseFalseZF->assertOk();
|
|
|
+ $responseFalse->assertOk()->assertSee('TestBSZF12345848854');
|
|
|
+ $responseMark=$this->actingAs($userMark)->get('waybill/index',[
|
|
|
+ 'waybill_number'=>'TestBSZF12345848854'
|
|
|
]);
|
|
|
$responseMark->assertStatus(302)->assertRedirect('/');
|
|
|
$responseTrue=$this->actingAs($user)->get('waybill');
|
|
|
- $responseTrue->assertOk()->assertSee('BSZX12345848854');
|
|
|
+ $responseTrue->assertOk()->assertSee('TestBSZF12345848854');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -90,9 +154,11 @@ class WaybillTest extends TestCase
|
|
|
* @depends testUserMark
|
|
|
*/
|
|
|
public function testCreate(User $user,User $userMark){
|
|
|
- $response=$this->actingAs($user)->get('waybill/createZX');
|
|
|
+ $response=$this->actingAs($user)->get('waybill/create/ZX');
|
|
|
$response->assertOk()->assertSee('WMS单号');
|
|
|
- $responseMark=$this->actingAs($userMark)->get('waybill/createZX');
|
|
|
+ $responseZF=$this->actingAs($user)->get('waybill/create/ZF');
|
|
|
+ $responseZF->assertOk();
|
|
|
+ $responseMark=$this->actingAs($userMark)->get('waybill/create/ZX');
|
|
|
$responseMark->assertStatus(302)->assertRedirect('/');
|
|
|
}
|
|
|
|
|
|
@@ -105,24 +171,24 @@ class WaybillTest extends TestCase
|
|
|
'type'=>'专线',
|
|
|
'owner_id'=>1,
|
|
|
'wms_bill_number'=>'ad544da6584',
|
|
|
- 'origination'=>'上海',
|
|
|
- 'destination'=>'商丘',
|
|
|
- 'recipient'=>'周某',
|
|
|
+ 'origination'=>'test上海',
|
|
|
+ 'destination'=>'test商丘',
|
|
|
+ 'recipient'=>'test周某',
|
|
|
'recipient_mobile'=>'01547896548',
|
|
|
'charge'=>58.6,
|
|
|
- 'ordering_remark'=>''
|
|
|
+ 'ordering_remark'=>'test'
|
|
|
]);
|
|
|
$response->assertStatus(302)->assertRedirect('waybill')->assertSessionHas('successTip');
|
|
|
$responseMark=$this->actingAs($userMark)->post('waybill',[
|
|
|
'type'=>'专线',
|
|
|
'owner_id'=>1,
|
|
|
'wms_bill_number'=>'ad544da6584',
|
|
|
- 'origination'=>'上海',
|
|
|
- 'destination'=>'商丘',
|
|
|
- 'recipient'=>'周某',
|
|
|
+ 'origination'=>'test上海',
|
|
|
+ 'destination'=>'test商丘',
|
|
|
+ 'recipient'=>'test周某',
|
|
|
'recipient_mobile'=>'01547896548',
|
|
|
'charge'=>58.6,
|
|
|
- 'ordering_remark'=>''
|
|
|
+ 'ordering_remark'=>'test'
|
|
|
]);
|
|
|
$responseMark->assertStatus(302)->assertRedirect('/');
|
|
|
}
|
|
|
@@ -134,17 +200,50 @@ class WaybillTest extends TestCase
|
|
|
*/
|
|
|
public function testEdit(User $user,Waybill $waybill,User $userMark){
|
|
|
$response=$this->actingAs($user)->get('waybill/'.$waybill->id.'/edit');
|
|
|
- $response->assertOk()->assertSee('BSZX12345848854');
|
|
|
+ $response->assertOk()->assertSee('TestBSZF12345848854');
|
|
|
$responseMark=$this->actingAs($userMark)->get('waybill/'.$waybill->id.'/edit');
|
|
|
$responseMark->assertStatus(302)->assertRedirect('/');
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @depends testUser
|
|
|
+ * @depends testAddWaybillPriceModel
|
|
|
+ * @depends testAddWaybillPriceModelTwo
|
|
|
+ */
|
|
|
+ public function testIsWaybillPriceModel(User $user,WaybillPriceModel $waybillPriceModel,WaybillPriceModel $waybillPriceModelTwo){
|
|
|
+ $response=$this->actingAs($user)->post('waybill/is/waybillPriceModel',[
|
|
|
+ 'carrier_id'=>'1',
|
|
|
+ 'destination_city_id'=>'1',
|
|
|
+ 'carrier_weight'=>['50','20'],
|
|
|
+ 'carrier_weight_unit_id'=>['1','1'],
|
|
|
+ ]);
|
|
|
+ $response->assertOk()->assertJson(['success'=>$waybillPriceModel->id]);
|
|
|
+ $response=$this->actingAs($user)->post('waybill/is/waybillPriceModel',[
|
|
|
+ 'carrier_id'=>'2',
|
|
|
+ 'destination_city_id'=>'2',
|
|
|
+ 'carrier_weight'=>['50','20'],
|
|
|
+ 'carrier_weight_unit_id'=>['1','1'],
|
|
|
+ ]);
|
|
|
+ $response->assertOk()->assertJson(['success'=>false]);
|
|
|
+ $response=$this->actingAs($user)->post('waybill/is/waybillPriceModel',[
|
|
|
+ 'carrier_id'=>'1',
|
|
|
+ 'destination_city_id'=>'2',
|
|
|
+ 'carrier_weight'=>['50','20'],
|
|
|
+ 'carrier_weight_unit_id'=>['1','1'],
|
|
|
+ ]);
|
|
|
+ $response->assertOk()->assertJson(['success'=>$waybillPriceModelTwo->id]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* @depends testUser
|
|
|
* @depends testAddWaybill
|
|
|
* @depends testUserMark
|
|
|
+ * @depends testAddWaybillZX
|
|
|
+ * @depends testAddWaybillPriceModel
|
|
|
+ * @depends testAddCarrier
|
|
|
*/
|
|
|
- public function testUpdate(User $user,Waybill $waybill,User $userMark){
|
|
|
+ public function testUpdate(User $user,Waybill $waybill,User $userMark,Waybill $waybillZX,WaybillPriceModel $waybillPriceModel,Carrier $carrier){
|
|
|
//直发车数据校验通过
|
|
|
$responseZFTrue=$this->actingAs($user)->put('waybill/'.$waybill->id,[
|
|
|
'type'=>'直发车',
|
|
|
@@ -171,8 +270,8 @@ class WaybillTest extends TestCase
|
|
|
$waybillPayoffs=WaybillPayoff::where('waybill_id','=',$waybill->id)->first();
|
|
|
$this->assertNotEmpty($waybillPayoffs);
|
|
|
$this->assertEquals(490.00,$waybillPayoffs->total_expense);
|
|
|
- $this->assertEquals(586.00,$waybillPayoffs->total_receivable);
|
|
|
- $this->assertEquals(96.00,$waybillPayoffs->gross_margin);
|
|
|
+ $this->assertEquals(586.50,$waybillPayoffs->total_receivable);
|
|
|
+ $this->assertEquals(96.50,$waybillPayoffs->gross_margin);
|
|
|
//直发车数据校验失败
|
|
|
$responseZFFalse=$this->actingAs($user)->put('waybill/'.$waybill->id,[
|
|
|
'type'=>'直发车',
|
|
|
@@ -183,23 +282,7 @@ class WaybillTest extends TestCase
|
|
|
'dispatch_remark'=>''
|
|
|
]);
|
|
|
$responseZFFalse->assertStatus(302)->assertRedirect('/'); //保留
|
|
|
-//专线
|
|
|
- $waybillZX=new Waybill([
|
|
|
- 'type'=>'专线',
|
|
|
- 'state'=>'未审核',
|
|
|
- 'waybill_number'=>'BSZX12345146854854',
|
|
|
- 'owner_id'=>2,
|
|
|
- 'wms_bill_number'=>'01547860548',
|
|
|
- 'origination'=>'上海',
|
|
|
- 'destination'=>'郑州',
|
|
|
- 'recipient'=>'elder sister',
|
|
|
- 'recipient_mobile'=>'12364851478',
|
|
|
- 'charge'=>586,
|
|
|
- 'ordering_remark'=>'禁'
|
|
|
- ]);
|
|
|
- $waybillZX->save();
|
|
|
- $this->assertNotEmpty($waybillZX);
|
|
|
-//未定义计费模型
|
|
|
+//无模型
|
|
|
$responseZXFalse=$this->actingAs($user)->put('waybill/'.$waybillZX->id,[
|
|
|
'type'=>'专线',
|
|
|
'carrier_id'=>1,
|
|
|
@@ -232,12 +315,29 @@ class WaybillTest extends TestCase
|
|
|
$responseZXMark->assertStatus(302)->assertRedirect('/');
|
|
|
$fee=Waybill::find($waybillZX->id);
|
|
|
$this->assertEquals(null,$fee->fee);
|
|
|
- $waybillPayoffsZX=WaybillPayoff::where('waybill_id','=',$waybillZX->id)->first();
|
|
|
- $this->assertNotEmpty($waybillPayoffsZX);
|
|
|
- $waybillPayoffsZX->delete();
|
|
|
-//清除冗余数据
|
|
|
- $result=$waybillZX->delete();
|
|
|
- $this->assertTrue($result);
|
|
|
+//有模型
|
|
|
+ $responseZX=$this->actingAs($user)->put('waybill/'.$waybillZX->id,[
|
|
|
+ 'type'=>'专线',
|
|
|
+ 'carrier_id'=>$carrier->id,
|
|
|
+ 'carrier_bill'=>'test01547860548',
|
|
|
+ 'origination_city_id'=>1,
|
|
|
+ 'destination_city_id'=>1,
|
|
|
+ 'warehouse_weight'=>25,
|
|
|
+ 'warehouse_weight_unit_id'=>1,
|
|
|
+ 'carrier_weight'=>50,
|
|
|
+ 'carrier_weight_unit_id'=>1,
|
|
|
+ 'carrier_weight_other'=>5,
|
|
|
+ 'carrier_weight_unit_id_other'=>2,
|
|
|
+ 'pick_up_fee'=>20,
|
|
|
+ 'other_fee'=>20,
|
|
|
+ 'waybillPriceModel'=>$waybillPriceModel->id,
|
|
|
+ 'dispatch_remark'=>''
|
|
|
+ ]);
|
|
|
+ $responseZX->assertStatus(302)->assertRedirect('waybill');
|
|
|
+ $waybillPayoff=WaybillPayoff::where('waybill_id',$waybillZX->id)->first();
|
|
|
+ $this->assertNotEmpty($waybillPayoff);
|
|
|
+ $this->assertEquals(460.00,$waybillPayoff->total_expense);
|
|
|
+ $this->assertEquals(126.00,$waybillPayoff->gross_margin);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -278,7 +378,7 @@ class WaybillTest extends TestCase
|
|
|
public function testWaybillAudit(User $user,Waybill $waybill,User $userMark){
|
|
|
//第一次请求成功
|
|
|
$response=$this->actingAs($user)->json('post','waybill/waybillAudit',['id'=>$waybill->id]);
|
|
|
- $response->assertJson(['success'=>true,'state'=>'已审核']);
|
|
|
+ $response->assertJson(['success'=>true,'status'=>'已审核']);
|
|
|
$responseMark=$this->actingAs($userMark)->json('post','waybill/waybillAudit',['id'=>$waybill->id]);
|
|
|
$responseMark->assertStatus(302)->assertRedirect('/');
|
|
|
//第二次请求拦截
|
|
|
@@ -293,7 +393,7 @@ class WaybillTest extends TestCase
|
|
|
*/
|
|
|
public function testWaybillEdit(User $user,Waybill $waybill,User $userMark){
|
|
|
$response=$this->actingAs($user)->get('waybill/waybillEdit/'.$waybill->id);
|
|
|
- $response->assertOk()->assertSee('上海松江');
|
|
|
+ $response->assertOk();
|
|
|
$responseMark=$this->actingAs($userMark)->get('waybill/waybillEdit/'.$waybill->id);
|
|
|
$responseMark->assertStatus(302)->assertRedirect('/');
|
|
|
}
|
|
|
@@ -305,7 +405,7 @@ class WaybillTest extends TestCase
|
|
|
*/
|
|
|
public function testWaybillRetreatAudit(User $user,Waybill $waybill,User $userMark){
|
|
|
$response=$this->actingAs($user)->json('post','waybill/waybillRetreatAudit',['id'=>$waybill->id]);
|
|
|
- $response->assertJson(['success'=>true,'state'=>'待重审']);
|
|
|
+ $response->assertJson(['success'=>true,'status'=>'待重审']);
|
|
|
$responseMark=$this->actingAs($userMark)->json('post','waybill/waybillRetreatAudit',['id'=>$waybill->id]);
|
|
|
$responseMark->assertStatus(302)->assertRedirect('/');
|
|
|
}
|
|
|
@@ -314,13 +414,19 @@ class WaybillTest extends TestCase
|
|
|
* @depends testUser
|
|
|
* @depends testAddWaybill
|
|
|
* @depends testUserMark
|
|
|
+ * @depends testAddWaybillZX
|
|
|
*/
|
|
|
- public function testWaybillEndAudit(User $user,Waybill $waybill,User $userMark){
|
|
|
+ public function testWaybillEndAudit(User $user,Waybill $waybill,User $userMark,Waybill $waybillZX){
|
|
|
//第一次请求成功
|
|
|
$response=$this->actingAs($user)->json('post','waybill/waybillEndAudit',['id'=>$waybill->id]);
|
|
|
- $response->assertJson(['success'=>true,'state'=>'未定义计费模型']);
|
|
|
+ $response->assertJson(['success'=>true]);
|
|
|
$responseMark=$this->actingAs($userMark)->json('post','waybill/waybillEndAudit',['id'=>$waybill->id]);
|
|
|
$responseMark->assertStatus(302)->assertRedirect('/');
|
|
|
+ //异常时
|
|
|
+ $waybillZX->waybill_price_model_id=null;
|
|
|
+ $waybillZX->save();
|
|
|
+ $response=$this->actingAs($user)->json('post','waybill/waybillEndAudit',['id'=>$waybillZX->id]);
|
|
|
+ $response->assertJson(['success'=>true]);
|
|
|
//第二次请求拦截
|
|
|
$responseRe=$this->actingAs($user)->json('post','waybill/waybillEndAudit',['id'=>$waybill->id]);
|
|
|
$responseRe->assertJson(['exception'=>'请勿重复审核!']);
|
|
|
@@ -332,8 +438,13 @@ class WaybillTest extends TestCase
|
|
|
* @depends testUser
|
|
|
* @depends testUserMark
|
|
|
* @depends testRole
|
|
|
+ * @depends testAddWaybillZX
|
|
|
+ * @depends testAddWaybillZX
|
|
|
+ * @depends testAddWaybillPriceModel
|
|
|
+ * @depends testAddCarrier
|
|
|
+ * @depends testAddWaybillPriceModelTwo
|
|
|
*/
|
|
|
- public function testDestroy(Waybill $waybill,User $user,User $userMark,Role $role){
|
|
|
+ public function testDestroy(Waybill $waybill,User $user,User $userMark,Role $role,Waybill $waybillZX,WaybillPriceModel $waybillPriceModel,Carrier $carrier,WaybillPriceModel $waybillPriceModelTwo){
|
|
|
$this->assertNotEmpty($waybill);
|
|
|
$result=$waybill->delete();
|
|
|
$this->assertTrue($result);
|
|
|
@@ -345,9 +456,26 @@ class WaybillTest extends TestCase
|
|
|
$this->assertNotEmpty($waybillStore);
|
|
|
$resultWaybillStore=$waybillStore->delete();
|
|
|
$this->assertTrue($resultWaybillStore);
|
|
|
- $waybillFinancialSnapshots=WaybillFinancialExcepted::where('waybill_id','=',$waybill->id)->first();
|
|
|
+ $waybillPayoffsZX=WaybillPayoff::where('waybill_id','=',$waybillZX->id)->first();
|
|
|
+ $this->assertNotEmpty($waybillPayoffsZX);
|
|
|
+ $waybillPayoffsZX->delete();
|
|
|
+ $result=$waybillZX->delete();
|
|
|
+ $this->assertTrue($result);
|
|
|
+ $this->assertNotEmpty($waybillPriceModel);
|
|
|
+ $resultWaybillPriceModel=$waybillPriceModel->delete();
|
|
|
+ $this->assertTrue($resultWaybillPriceModel);
|
|
|
+ $this->assertNotEmpty($waybillPriceModelTwo);
|
|
|
+ $resultWaybillPriceModelTwo=$waybillPriceModelTwo->delete();
|
|
|
+ $this->assertTrue($resultWaybillPriceModelTwo);
|
|
|
+ $this->assertNotEmpty($carrier);
|
|
|
+ $resultCarrier=$carrier->delete();
|
|
|
+ $this->assertTrue($resultCarrier);
|
|
|
+ $waybillFinancialSnapshots=WaybillFinancialSnapshot::where('waybill_id','=',$waybill->id)->first();
|
|
|
$r=$waybillFinancialSnapshots->delete();
|
|
|
$this->assertTrue($r);
|
|
|
+ $waybillFinancialSnapshotsZX=WaybillFinancialExcepted::where('waybill_id','=',$waybillZX->id)->first();
|
|
|
+ $resultZX=$waybillFinancialSnapshotsZX->delete();
|
|
|
+ $this->assertTrue($resultZX);
|
|
|
$isAudit=WaybillAuditLog::withTrashed()->whereRaw('waybill_id = ? and audit_stage = ?',[$waybill->id,"运单阶段"])->first();
|
|
|
$resultWaybillAuditLogWaybill=$isAudit->forceDelete();
|
|
|
$this->assertTrue($resultWaybillAuditLogWaybill);
|