From efc8c009f1a9217fecde574595ffaaeacc75c85f Mon Sep 17 00:00:00 2001 From: Hasin Hayder Date: Sat, 21 May 2022 21:16:37 +0600 Subject: [PATCH] Tests --- tests/Feature/NewUserTest.php | 97 +++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 tests/Feature/NewUserTest.php diff --git a/tests/Feature/NewUserTest.php b/tests/Feature/NewUserTest.php new file mode 100644 index 0000000..1668baf --- /dev/null +++ b/tests/Feature/NewUserTest.php @@ -0,0 +1,97 @@ +postJson('/api/users', [ + 'name' => 'Test User', + 'email' => 'test@test.com', + 'password' => 'test' + ]); + + $response + ->assertJson( + fn (AssertableJson $json) => + $json->where('email', 'test@test.com') + ->where('name', 'Test User') + ->etc() + ); + } + + public function test_existing_email_registration_fail() { + $response = $this->postJson('/api/users', [ + 'name' => 'Test User', + 'email' => 'test@test.com', + 'password' => 'test' + ]); + + $response + ->assertJson( + fn (AssertableJson $json) => + $json->where('error', 1) + ->where('message', 'user already exists') + ); + } + + public function test_new_user_login() { + $response = $this->postJson('/api/login', [ + 'email' => 'test@test.com', + 'password' => 'test' + ]); + + $data = json_decode($response->getContent()); + $this->token = $data->token; + echo $this->token; + + $response + ->assertJson( + fn (AssertableJson $json) => + $json->where('error', 0) + ->has('token') + ); + } + + public function test_new_user_failed_login() { + $response = $this->postJson('/api/login', [ + 'email' => 'test@test.com', + 'password' => 'testX' + ]); + + $response + ->assertJson( + fn (AssertableJson $json) => + $json->where('error', 1) + ->has('message') + ); + } + + public function test_new_user_data_update() { + $response = $this->postJson('/api/login', [ + 'email' => 'test@test.com', + 'password' => 'testX' + ]); + + $response + ->assertJson( + fn (AssertableJson $json) => + $json->where('error', 1) + ->has('message') + ); + } +}