pull/3/head
Hasin Hayder 3 years ago
parent 1a4acd2210
commit 4b3c39cac4

@ -6,7 +6,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Testing\Fluent\AssertableJson; use Illuminate\Testing\Fluent\AssertableJson;
use App\Models\User;
class NewUserTest extends TestCase { class NewUserTest extends TestCase {
/** /**
@ -57,13 +57,14 @@ class NewUserTest extends TestCase {
$data = json_decode($response->getContent()); $data = json_decode($response->getContent());
$this->token = $data->token; $this->token = $data->token;
echo $this->token; $this->user_id = $data->id;
$response $response
->assertJson( ->assertJson(
fn (AssertableJson $json) => fn (AssertableJson $json) =>
$json->where('error', 0) $json->where('error', 0)
->has('token') ->has('token')
->has('id')
); );
} }
@ -81,17 +82,51 @@ class NewUserTest extends TestCase {
); );
} }
public function test_new_user_data_update() { public function test_new_user_name_update() {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'test@test.com', 'email' => 'test@test.com',
'password' => 'testX' 'password' => 'test'
]);
$data = json_decode($response->getContent());
$this->token = $data->token;
$this->user_id = $data->id;
$response = $this->withHeader('Authorization', 'Bearer ' . $this->token)
->put("/api/users/{$this->user_id}", [
'name' => 'Mini Me',
]); ]);
$response $response
->assertJson( ->assertJson(
fn (AssertableJson $json) => fn (AssertableJson $json) =>
$json->where('error', 1) $json->where('name', "Mini Me")
->has('message') ->etc()
);
}
public function test_new_user_destroy_as_admin() {
$response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project',
'password' => 'hydra'
]);
$data = json_decode($response->getContent());
$this->token = $data->token;
$this->user_id = $data->id;
$target = User::where('email','test@test.com')->first();
$response = $this->withHeader('Authorization', 'Bearer ' . $this->token)
->delete("/api/users/{$target}");
$response
->assertJson(
fn (AssertableJson $json) =>
$json->where('error',0)
->where('message','user deleted')
); );
} }
} }

Loading…
Cancel
Save