File: /home/imensosw/.trash/tests.1/Unit/Translator/UserSkillTest.php
<?php
// Skill -> Language
namespace Tests\Unit\Translator;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use App\Models\UserSkill;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Str;
use App\Models\Proficiency;
use App\Models\Language;
use App\Models\TranslatorStatus;
class UserSkillTest extends TestCase
{
protected $users , $clientData, $proficiency, $language, $translator_status;
protected function setUp(): void
{
parent::setUp();
$this->proficiency = Proficiency::inRandomOrder()->first();
// $this->language = Language::inRandomOrder()->first();
$this->translator_status = TranslatorStatus::where('id',2)->first();
}
public function test_to_create_user_skill()
{
$user = factory(\App\User::class)->create();
$profile = factory(\App\Models\Profile::class)->create(['user_id'=>$user->id]);
$language = factory(\App\Models\Language::class)->create();
$this->withoutMiddleware();
$this->withoutExceptionHandling();
$this->actingAs($user)->json('GET','/getUserSkills');
$data = [
"user_id" => $user->id,
"language_id" => $language->id,
"proficiency_id" => $this->proficiency->id,
];
$response = $this->json('POST', 'api/insertUserSkill', $data,
[
'Accept' => 'application/json',
'HTTP_Authorization' => 'Bearer' . $user->remember_token
])
->assertStatus(200);
$response->assertOk();
UserSkill::where('user_id', $user->id)->delete();
Language::where('id', $language->id)->delete();
\App\Models\Profile::where('id', $profile->id)->delete();
\App\User::where('id', $user->id)->delete();
/* $response1 = $this->post('/api/insertUserSkill', $data);
dd($response1->getContent()); // add this temporarily
$response1->assertResponseStatus(200);*/
}
public function test_to_update_user_skill()
{
$getUser = factory(\App\User::class)->create();
$profile = factory(\App\Models\Profile::class)->create(['user_id'=>$getUser->id]);
$language = factory(\App\Models\Language::class)->create();
$userSkill = factory(\App\Models\UserSkill::class)->create([
"user_id" => $getUser->id,
"language_id" => $language->id,
"proficiency_id" => $this->proficiency->id,
]);
// $getUser = \App\User::orderBy('id','DESC')->first();
$this->withoutMiddleware();
$this->withoutExceptionHandling();
$this->actingAs($getUser)->json('GET','/getUserSkills');
$data = [
"user_id" => $getUser->id,
// "language_id" => $this->language->id,
"proficiency_id" => $this->proficiency->id,
];
$response = $this->json('POST', 'api/updateUserSkill', $data,
[
'Accept' => 'application/json',
'HTTP_Authorization' => 'Bearer' . $getUser->remember_token
])
->assertStatus(200);
$response->assertOk();
UserSkill::where('id', $userSkill->id)->delete();
Language::where('id', $language->id)->delete();
\App\Models\Profile::where('user_id', $getUser->id)->delete();
\App\User::where('id', $getUser->id)->delete();
/* $response1 = $this->post('/api/updateUserSkill', $data);
dd($response1->getContent()); // add this temporarily
$response1->assertResponseStatus(200);*/
}
public function tearDown(): void
{
$maxId = \DB::table('user_skills')->max('id');
\DB::statement('ALTER TABLE user_skills AUTO_INCREMENT=' . intval($maxId + 1) . ';');
$maxId = \DB::table('languages')->max('id');
\DB::statement('ALTER TABLE languages AUTO_INCREMENT=' . intval($maxId + 1) . ';');
$maxId = \DB::table('profiles')->max('id');
\DB::statement('ALTER TABLE profiles AUTO_INCREMENT=' . intval($maxId + 1) . ';');
$maxId = \DB::table('users')->max('id');
\DB::statement('ALTER TABLE users AUTO_INCREMENT=' . intval($maxId + 1) . ';');
parent::tearDown();
}
}