File: /home/imensosw/.trash/tests.1/Unit/Translator/IdentificationInformationTest.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 Illuminate\Support\Str;
use App\Models\UserIdentification;
use App\Models\PhotoProofType;
use App\Models\AddressProofType;
use App\User;
use Illuminate\Http\UploadedFile;
class IdentificationInformationTest extends TestCase
{
protected $users, $clientData, $photo_proof_type, $address_proof_type, $image;
protected function setUp(): void
{
parent::setUp();
// $this->photo_proof_type = PhotoProofType::inRandomOrder()->first();
// $this->address_proof_type = AddressProofType::inRandomOrder()->first();
$this->image = 'balloons.jpg';
}
public function test_to_get_user_identification()
{
$this->withoutMiddleware();
$this->withoutExceptionHandling();
$response = $this->json('GET','/getUserIdentification');
$response->assertOk();
}
/* Photo Identity Upload Test */
public function test_to_update_user_identification_to_upload_photo_id()
{
$user = factory(User::class)->create();
$profile = factory(\App\Models\Profile::class)->create(['user_id'=>$user->id]);
$photo_proof_type = factory(\App\Models\PhotoProofType::class)->create();
$address_proof_type = factory(\App\Models\AddressProofType::class)->create();
$this->withoutMiddleware();
$this->withoutExceptionHandling();
$this->actingAs($user)->json('GET','/getUserIdentification');
$file=UploadedFile::fake()->image($this->image);
$data = [
"photo_proof_type_id" => $photo_proof_type->id,
'address_proof_type_id' =>$address_proof_type->id,
"photo_proof_file" => $file,
'user_id' => $user->id,
];
$response = $this->json('POST', 'api/uploadPhotoId', $data,
[
'Accept' => 'application/json',
'HTTP_Authorization' => 'Bearer' . $user->remember_token
])
->assertStatus(200);
$response->assertOk();
// $this->test_to_update_user_identification_to_delete_photo_id($user->id);
UserIdentification::where('user_id', $user->id)->delete();
\App\Models\PhotoProofType::where('id', $photo_proof_type->id)->delete();
\App\Models\AddressProofType::where('id', $address_proof_type->id)->delete();
\App\Models\Profile::where('user_id', $user->id)->delete();
\App\User::where('id', $user->id)->delete();
/* $response1 = $this->post('/api/uploadPhotoId', $data);
dd($response1->getContent()); // add this temporarily
$response1->assertResponseStatus(200);*/
}
public function test_to_update_user_identification_to_delete_photo_id()
{
// $user = factory(User::class)->create();
// $profile = factory(\App\Models\Profile::class)->create(['user_id'=>$user->id]);
$user = factory(User::class)->create();
$profile = factory(\App\Models\Profile::class)->create(['user_id'=>$user->id]);
$photo_proof_type = factory(\App\Models\PhotoProofType::class)->create();
$address_proof_type = factory(\App\Models\AddressProofType::class)->create();
$file=UploadedFile::fake()->image($this->image);
$user_identification = factory(UserIdentification::class)->create([
"photo_proof_type_id" => $photo_proof_type->id,
"photo_proof_file" => $file,
'address_proof_type_id' =>$address_proof_type->id,
'user_id' => $user->id,
]);
$this->withoutMiddleware();
$this->withoutExceptionHandling();
$this->actingAs($user)->json('GET','/getUserIdentification');
$data = [
'id' => $user->id,
];
$response = $this->json('POST', 'api/deletePhotoId', $data,
[
'Accept' => 'application/json',
'HTTP_Authorization' => 'Bearer' . $user->remember_token
])
->assertStatus(200);
$response->assertOk();
UserIdentification::where('id', $user_identification->id)->delete();
\App\Models\PhotoProofType::where('id', $photo_proof_type->id)->delete();
\App\Models\AddressProofType::where('id', $address_proof_type->id)->delete();
\App\Models\Profile::where('user_id', $user->id)->delete();
\App\User::where('id', $user->id)->delete();
// $response1 = $this->post('/api/deletePhotoId', $data);
// dd($response1->getContent()); // add this temporarily
// $response1->assertResponseStatus(200);
}
/* Address Proof Upload Test */
public function test_to_update_user_identification_to_upload_address_proof_id()
{
$user = factory(User::class)->create();
$profile = factory(\App\Models\Profile::class)->create(['user_id'=>$user->id]);
$address_proof_type = factory(\App\Models\AddressProofType::class)->create();
$photo_proof_type = factory(\App\Models\PhotoProofType::class)->create();
$this->withoutMiddleware();
$this->withoutExceptionHandling();
$this->actingAs($user)->json('GET','/getUserIdentification');
$file=UploadedFile::fake()->image($this->image);
$data = [
"address_proof_type_id" => $address_proof_type->id,
"photo_proof_type_id" => $photo_proof_type->id,
"address_proof_file" => $file,
'user_id' => $user->id,
];
$response = $this->json('POST', 'api/uploadAddressProof', $data,
[
'Accept' => 'application/json',
'HTTP_Authorization' => 'Bearer' . $user->remember_token
])
->assertStatus(200);
$response->assertOk();
UserIdentification::where('user_id', $user->id)->delete();
\App\Models\PhotoProofType::where('id', $photo_proof_type->id)->delete();
\App\Models\AddressProofType::where('id', $address_proof_type->id)->delete();
\App\Models\Profile::where('user_id', $user->id)->delete();
\App\User::where('id', $user->id)->delete();
}
public function test_to_update_user_identification_to_delete_address_proof_id()
{
$user = factory(User::class)->create();
$profile = factory(\App\Models\Profile::class)->create(['user_id'=>$user->id]);
$address_proof_type = factory(\App\Models\AddressProofType::class)->create();
$file=UploadedFile::fake()->image($this->image);
$photo_proof_type = factory(\App\Models\PhotoProofType::class)->create();
$user_identification = factory(UserIdentification::class)->create([
"address_proof_type_id" => $address_proof_type->id,
"photo_proof_type_id" => $photo_proof_type->id,
"address_proof_file" => $file,
'user_id' => $user->id,
]);
$this->withoutMiddleware();
$this->withoutExceptionHandling();
$this->actingAs($user)->json('GET','/getUserIdentification');
$data = [
'id' => $user->id,
];
$response = $this->json('POST', 'api/deleteAddressProof', $data,
[
'Accept' => 'application/json',
'HTTP_Authorization' => 'Bearer' . $user->remember_token
])
->assertStatus(200);
$response->assertOk();
UserIdentification::where('id', $user_identification->id)->delete();
\App\Models\PhotoProofType::where('id', $photo_proof_type->id)->delete();
\App\Models\AddressProofType::where('id', $address_proof_type->id)->delete();
\App\Models\Profile::where('user_id', $user->id)->delete();
\App\User::where('id', $user->id)->delete();
}
public function tearDown(): void
{
$maxId = \DB::table('user_identifications')->max('id');
\DB::statement('ALTER TABLE user_identifications AUTO_INCREMENT=' . intval($maxId + 1) . ';');
$maxId = \DB::table('address_proof_types')->max('id');
\DB::statement('ALTER TABLE address_proof_types AUTO_INCREMENT=' . intval($maxId + 1) . ';');
$maxId = \DB::table('photo_proof_types')->max('id');
\DB::statement('ALTER TABLE photo_proof_types 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();
}
}