Skip to content

Commit

Permalink
chore: 修正一个测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
boxshadow committed Aug 15, 2019
1 parent 4da4008 commit 6b25dc7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 2 additions & 3 deletions app/Http/Controllers/APIs/V2/AuthController.php
Expand Up @@ -65,9 +65,8 @@ public function login(Request $request)
$login = (string) $request->input('login', '');
$code = $request->input('verifiable_code');
$field = username($login);

if ($code !== null && in_array($field, ['phone', 'email'])) {
$verify = VerificationCode::where('account', $login)
$verify = VerificationCode::query()->where('account', $login)
->where('channel', $field == 'phone' ? 'sms' : 'mail')
->where('code', $code)
->byValid(120)
Expand Down Expand Up @@ -114,7 +113,7 @@ public function login(Request $request)
return $this->respondWithToken($token);
}

return $this->response()->json(['message' => '账号或密码不正确'], 422);
return $this->response()->json(['message' => '账号或密码不正确'], 403);
} else {
return $this->response()->json([
'message' => sprintf('%s还没有注册', $field == 'phone'
Expand Down
2 changes: 1 addition & 1 deletion database/factories/UserFactory.php
Expand Up @@ -36,7 +36,7 @@
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'phone' => $faker->unique()->phoneNumber,
'password' => $password ?: $password = bcrypt('secret'),
'password' => $password ?: $password = bcrypt('password'),
'email_verified_at' => now(),
'phone_verified_at' => now(),
'remember_token' => str_random(10),
Expand Down
15 changes: 14 additions & 1 deletion tests/Feature/API2/AuthLoginTest.php
Expand Up @@ -47,12 +47,25 @@ public function testUserLogin()
{
$response = $this->json('POST', 'api/v2/auth/login', [
'login' => $this->user->id,
'password' => 'secret',
'password' => 'password',
]);

$this->assertLoginResponse($response);
}

/**
* 使用错误的密码将返回403状态码
*/
public function test_user_can_not_login_with_wrong_password()
{
$response = $this->json('POST', 'api/v2/auth/login', [
'login' => $this->user->id,
'password' => 'secret',
]);

$response->assertStatus(403);
}

/**
* Assert login response.
*
Expand Down

0 comments on commit 6b25dc7

Please sign in to comment.