File: /home/imensosw/.trash/tests.1/Unit/Translator/UserAvailabilityTest.php
<?php
namespace Tests\Unit\Translator;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use App\Models\UserAvailability;
use App\Models\TimeSlot;
use App\Models\Day;
use App\User;
class UserAvailabilityTest extends TestCase
{
protected $users, $clientData, $day, $time_slot;
protected function setUp(): void
{
parent::setUp();
$this->day = Day::inRandomOrder()->first();
$this->time_slot = TimeSlot::inRandomOrder()->first();
}
public function test_to_get_user_day_time_slots_pivote()
{
$this->withoutMiddleware();
$this->withoutExceptionHandling();
$response = $this->json('GET','/getUserDayTimeSlotsPivote');
$response->assertOk();
}
public function test_to_update_user_availability()
{
$user = factory(User::class)->create();
$this->withoutMiddleware();
$this->withoutExceptionHandling();
$this->actingAs($user)->json('GET','/getUserDayTimeSlotsPivote');
$data = [
// "user_id" => $user->id,
'time_slot_id' => $this->time_slot->id,
'day_id' => $this->day->id,
'operation' => 'insert'
];
$response = $this->json('POST', 'api/updateUserAvailability', $data,
[
'Accept' => 'application/json',
'HTTP_Authorization' => 'Bearer' . $user->remember_token
])
->assertStatus(200);
$response->assertOk();
UserAvailability::where('user_id', $user->id)->delete();
\App\User::where('id', $user->id)->delete();
// $response1 = $this->post('/api/updateUserAvailability', $data);
// dd($response1->getContent()); // add this temporarily
// $response1->assertResponseStatus(200);
}
public function tearDown(): void
{
$maxId = \DB::table('user_availabilitys')->max('id');
\DB::statement('ALTER TABLE user_availabilitys AUTO_INCREMENT=' . intval($maxId + 1) . ';');
$maxId = \DB::table('users')->max('id');
\DB::statement('ALTER TABLE users AUTO_INCREMENT=' . intval($maxId + 1) . ';');
parent::tearDown();
}
}