Created
March 28, 2017 15:33
-
-
Save mkdesignn/4388a048d4829da768336f51c929aedd to your computer and use it in GitHub Desktop.
Register new complaint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use App\Acme\Box; | |
use App\Cases; | |
use App\Complaint; | |
use App\User; | |
use App\UserMeta; | |
use Illuminate\Foundation\Testing\WithoutMiddleware; | |
use Illuminate\Foundation\Testing\DatabaseMigrations; | |
use Illuminate\Foundation\Testing\DatabaseTransactions; | |
class CreateCaseTest extends TestCase | |
{ | |
use DatabaseTransactions; | |
function test_create_case_with_registering_new_defendant(){ | |
// we need to crate a user of type client | |
$citizen = $this->createClient(); | |
// we need to create the complaint | |
$complaint = $this->createComplaint($citizen); | |
// we need to create a user of type defendant | |
$defendant = $this->createDefendant(); | |
// then we need to create a case base on the complaint info | |
$case = $this->createCase($complaint, $defendant, $citizen); | |
$this->assertEquals($complaint->id, $case->complaint_id); | |
} | |
function test_create_case_with_registered_defendant(){ | |
// we need to crate a user of type client | |
$citizen = $this->createClient(); | |
// we should get the defendant id | |
$defendant = $this->getDefendant(); | |
// we need to create the complaint | |
$complaint = $this->createComplaint($citizen); | |
// then we need to create a case base on the complaint info | |
$case = $this->createCase($complaint, $defendant, $citizen); | |
$this->assertEquals($complaint->id, $case->complaint_id); | |
} | |
private function createDefendant(){ | |
$trade_operator = factory(User::class) | |
->create(["role"=>"trade-operator"]); | |
factory(UserMeta::class) | |
->create(["user_id"=>$trade_operator->id]); | |
return $trade_operator; | |
} | |
private function createClient(){ | |
$citizen = factory(User::class)->create(["role"=>"citizen"])->first(); | |
factory(UserMeta::class) | |
->create(["user_id"=>$citizen->id])->first(); | |
return $citizen; | |
} | |
private function createComplaint($citizen){ | |
return factory(Complaint::class) | |
->create(["complainer_id"=>$citizen->id | |
,"trade_unit_phone"=>"2794849405859"])->first(); | |
} | |
private function createCase($complaint, $trade_operator, $citizen){ | |
$case = factory(Cases::class) | |
->create(["code"=>$complaint->tracking_code, "complainer_id"=>$citizen->id, | |
"complaint_id"=>$complaint->id, "defendant_id"=>$trade_operator->id])->first(); | |
return $case; | |
} | |
private function getDefendant(){ | |
return User::where("role", "trade-operator")->first(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment