Skip to content

Instantly share code, notes, and snippets.

@sdavara
Created August 27, 2019 12:53
Show Gist options
  • Save sdavara/e81c01eca44dcdc55581b95e7ef438c0 to your computer and use it in GitHub Desktop.
Save sdavara/e81c01eca44dcdc55581b95e7ef438c0 to your computer and use it in GitHub Desktop.
<?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\Appointments;
use App\Models\User;
use Artisan;
use DateTime;
class AppointmentTest 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 testTogetAppointments()
{
$input = [
'email' => 'admin@repairrabbit.co',
'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/admin/appointments', [], [], [], $server);
$result_array = json_decode( $results->getContent(), true );
$allTicketCount = Appointments::count();
$this->assertEquals($allTicketCount, $result_array['appointments']['total']);
}
public function testToStoreAppointments() {
$input = [
'email' => 'admin@repairrabbit.co',
'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);
$datetime = new DateTime('tomorrow');
//store appointment
$input = [
"store" => 1,
"device" => 1,
"products" => [1], /* product_ids of device */
"userId" => 4,
"date" => $datetime->format('Y-m-d'),
"timeSlot" => "08:30 - 09:00",
"imei" => 123412341111111,
"checkTime" => '1',
"no_show" => 0,
"confirmed" => 1,
"retarget" => 1,
"warranty" => 0
];
$results = $this->call('POST','api/v1/admin/appointments', $input, [], [], $server);
$result_array = json_decode( $results->getContent(), true);
$this->assertEquals('Appointment created successfully.', $result_array['message']);
//update appointment
$appointment = Appointments::orderBy('id', 'desc')->first();
$input = [
'store' => 1,
"device" => 1,
"products" => [1], /* product_ids of device */
"userId" => 4,
"date" => $datetime->format('Y-m-d'),
"timeSlot" => "08:40 - 09:10"
];
$results = $this->call('PUT','api/v1/admin/appointments/'.$appointment['id'], $input, [], [], $server);
$result_array = json_decode( $results->getContent(), true );
$this->assertEquals('Appointment updated successfully.', $result_array['message']);
//get single appointment
$results = $this->call('GET','api/v1/admin/appointments/'.$appointment['id'], [], [], [], $server);
$result_array = json_decode( $results->getContent(), true );
$this->assertEquals('Appointment detail.', $result_array['message']);
//delete appointment
$results = $this->call('DELETE','api/v1/admin/appointments/'.$appointment['id'], [], [], [], $server);
$result_array = json_decode( $results->getContent(), true );
$this->assertEquals('Appointment deleted successfully.', $result_array['message']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment