Created
August 27, 2019 12:54
-
-
Save sdavara/7acc883b843baaf981f3e9be78084895 to your computer and use it in GitHub Desktop.
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 | |
namespace Tests\Feature\tests\Api; | |
use Tests\TestCase; | |
use Illuminate\Foundation\Testing\WithoutMiddleware; | |
use Illuminate\Foundation\Testing\DatabaseMigrations; | |
use Illuminate\Foundation\Testing\DatabaseTransactions; | |
use App\Models\Ticket; | |
use App\Models\TicketHistory; | |
use App\Models\User; | |
use Illuminate\Http\UploadedFile; | |
use Artisan; | |
class CustomerTicketTest extends TestCase | |
{ | |
public function setUp() | |
{ | |
parent::setUp(); | |
Artisan::call('migrate'); | |
Artisan::call('db:seed', ['--class' => 'DataSeeder']); | |
} | |
/** | |
* A basic functional test example. | |
* | |
* @return void | |
*/ | |
public function testTogetTickets() | |
{ | |
$input = [ | |
'email' => '[email protected]', | |
'password' => '123456' | |
]; | |
$results = $this->call('POST','api/v1/login', $input); | |
$result_array = json_decode( $results->getContent(), true ); | |
$token = $result_array['token']; | |
$headers = [ | |
'Authorization' => 'Bearer '.$token, | |
]; | |
$server = $this->transformHeadersToServerVars($headers); | |
$results = $this->call('GET','api/v1/customers/tickets', [], [], [], $server); | |
$result_array = json_decode( $results->getContent(), true ); | |
$this->assertEquals(5, $result_array['tickets']['total']); | |
} | |
public function testToStoreTickets() { | |
$input = [ | |
'email' => '[email protected]', | |
'password' => '123456' | |
]; | |
$results = $this->call('POST','api/v1/login', $input); | |
$result_array = json_decode( $results->getContent(), true ); | |
$token = $result_array['token']; | |
$headers = [ | |
'Authorization' => 'Bearer '.$token, | |
]; | |
$server = $this->transformHeadersToServerVars($headers); | |
$originalFile = UploadedFile::fake()->image('test.jpg', 200, 200)->size(100); | |
//store ticket | |
$input = [ | |
"device" => 2, | |
"products" => [2], /* product_ids of device */ | |
"description" => 'sdsdf', | |
"serial" => 123412341111111, | |
"access_code" => 123123, | |
"polis_number" => '', | |
]; | |
$results = $this->call('POST','api/v1/customers/tickets', $input, [], [], $server); | |
$result_array = json_decode( $results->getContent(), true); | |
$this->assertEquals('Ticket created successfully.', $result_array['message']); | |
//update ticket | |
$ticket = Ticket::where('friendly_id', '=', 'YNT-400')->first(); | |
$input = [ | |
"device" => 2, | |
"products" => [2], /* product_ids of device */ | |
"serial" => 123412341111111, | |
"access_code" => 1231234 | |
]; | |
$results = $this->call('PUT','api/v1/customers/tickets/'.$ticket['friendly_id'], $input, [], [], $server); | |
$result_array = json_decode( $results->getContent(), true ); | |
$this->assertEquals('Ticket updated successfully.', $result_array['message']); | |
//get single ticket | |
$results = $this->call('GET','api/v1/customers/tickets/'.$ticket['friendly_id'], [], [], [], $server); | |
$result_array = json_decode( $results->getContent(), true ); | |
$this->assertEquals('Ticket detail.', $result_array['message']); | |
} | |
public function testToshowTicketHistory() | |
{ | |
$input = [ | |
'email' => '[email protected]', | |
'password' => '123456' | |
]; | |
$results = $this->call('POST','api/v1/login', $input); | |
$result_array = json_decode( $results->getContent(), true ); | |
$token = $result_array['token']; | |
$headers = [ | |
'Authorization' => 'Bearer '.$token, | |
]; | |
$server = $this->transformHeadersToServerVars($headers); | |
$results = $this->call('GET','api/v1/customers/tickets/YNT-400/history', [], [], [], $server); | |
$result_array = json_decode( $results->getContent(), true ); | |
$allTicketHistoryCount = TicketHistory::where('ticket_id', '=', 2)->count(); | |
$this->assertEquals($allTicketHistoryCount, $result_array['ticket_history']['total']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment