fix tests

This commit is contained in:
Pig Fang 2019-02-17 20:12:42 +08:00
parent 9e05b7c843
commit 0d4f34770e
2 changed files with 10 additions and 6 deletions

View File

@ -271,8 +271,9 @@ class User extends Authenticatable
if (option('sign_after_zero')) { if (option('sign_after_zero')) {
return Carbon::now()->diffInSeconds( return Carbon::now()->diffInSeconds(
(($lastSignTime <= Carbon::today()) ? $lastSignTime : Carbon::tomorrow()) $lastSignTime <= Carbon::today() ? $lastSignTime : Carbon::tomorrow(),
, false); false
);
} }
return Carbon::now()->diffInSeconds($lastSignTime->addHours(option('sign_gap_time')), false); return Carbon::now()->diffInSeconds($lastSignTime->addHours(option('sign_gap_time')), false);

View File

@ -4,6 +4,7 @@ namespace Tests;
use Parsedown; use Parsedown;
use App\Events; use App\Events;
use Carbon\Carbon;
use App\Models\User; use App\Models\User;
use App\Mail\EmailVerification; use App\Mail\EmailVerification;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
@ -83,9 +84,9 @@ class UserControllerTest extends TestCase
]); ]);
// Remaining time is greater than 0 // Remaining time is greater than 0
$user->last_sign_at = get_datetime_string(); $user = factory(User::class)->create(['last_sign_at' => get_datetime_string()]);
$user->save(); $this->actAs($user)
$this->postJson('/user/sign') ->postJson('/user/sign')
->assertJson([ ->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans( 'msg' => trans(
@ -99,6 +100,7 @@ class UserControllerTest extends TestCase
// Can sign after 0 o'clock // Can sign after 0 o'clock
option(['sign_after_zero' => true]); option(['sign_after_zero' => true]);
$user = factory(User::class)->create(['last_sign_at' => get_datetime_string()]);
$diff = \Carbon\Carbon::now()->diffInSeconds(\Carbon\Carbon::tomorrow()); $diff = \Carbon\Carbon::now()->diffInSeconds(\Carbon\Carbon::tomorrow());
if ($diff / 3600 >= 1) { if ($diff / 3600 >= 1) {
$diff = round($diff / 3600); $diff = round($diff / 3600);
@ -107,7 +109,8 @@ class UserControllerTest extends TestCase
$diff = round($diff / 60); $diff = round($diff / 60);
$unit = 'min'; $unit = 'min';
} }
$this->postJson('/user/sign') $this->actAs($user)
->postJson('/user/sign')
->assertJson([ ->assertJson([
'errno' => 1, 'errno' => 1,
'msg' => trans( 'msg' => trans(