-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08e13bc
commit 2a0f603
Showing
1 changed file
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
use App\User; | ||
use App\Services\SystemLogService; | ||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Foundation\Testing\WithoutMiddleware; | ||
|
||
class SystemLogContorllerTest extends TestCase | ||
{ | ||
use WithoutMiddleware; | ||
|
||
public function testGetLog() | ||
{ | ||
$response = $this->json('GET', '/api/system-log'); | ||
|
||
$response->assertStatus(200); | ||
} | ||
|
||
public function testSearchLogWithType() | ||
{ | ||
$user = User::find(1); | ||
$this->actingAs($user); | ||
$content = 'test' . time(); | ||
(new SystemLogService)->write($content, 3); | ||
|
||
$response = $this->json('GET', '/api/system-log', [ | ||
'type_id' => '3', | ||
]); | ||
|
||
$response->assertStatus(200) | ||
->assertJson([ | ||
'data' => [ | ||
'data' => [ | ||
[ | ||
'type_id' => '3', | ||
] | ||
] | ||
] | ||
]); | ||
} | ||
|
||
public function testSearchLogWithName() | ||
{ | ||
$user = User::find(1); | ||
$this->actingAs($user); | ||
$content = 'test' . time(); | ||
(new SystemLogService)->write($content, 2); | ||
|
||
$search = json_encode([ | ||
'username' => 'admin', | ||
]); | ||
|
||
$response = $this->json('GET', '/api/system-log', [ | ||
'search' => $search, | ||
]); | ||
|
||
$response->assertStatus(200) | ||
->assertJson([ | ||
'data' => [ | ||
'data' => [ | ||
[ | ||
'user_name' => 'admin', | ||
] | ||
] | ||
] | ||
]); | ||
} | ||
|
||
public function testSearchLogWithContent() | ||
{ | ||
$user = User::find(1); | ||
$this->actingAs($user); | ||
$content = 'test' . time(); | ||
(new SystemLogService)->write($content, 1); | ||
|
||
$search = json_encode([ | ||
'content' => $content | ||
]); | ||
|
||
$response = $this->json('GET', '/api/system-log', [ | ||
'search' => $search, | ||
]); | ||
|
||
$response->assertStatus(200) | ||
->assertJson([ | ||
'data' => [ | ||
'data' => [ | ||
[ | ||
'content' => $content | ||
] | ||
] | ||
] | ||
]); | ||
} | ||
|
||
public function testSearchLogWithTypeAndName() | ||
{ | ||
$user = User::find(1); | ||
$this->actingAs($user); | ||
$content = 'test' . time(); | ||
(new SystemLogService)->write($content, 1); | ||
|
||
$search = json_encode([ | ||
'username' => 'admin', | ||
]); | ||
|
||
$response = $this->json('GET', '/api/system-log', [ | ||
'type_id' => '1', | ||
'search' => $search, | ||
]); | ||
|
||
$response->assertStatus(200) | ||
->assertJson([ | ||
'data' => [ | ||
'data' => [ | ||
[ | ||
'type_id' => '1', | ||
'user_name' => 'admin', | ||
] | ||
] | ||
] | ||
]); | ||
} | ||
|
||
public function testSearchLogWithTypeAndContent() | ||
{ | ||
$user = User::find(1); | ||
$this->actingAs($user); | ||
$content = 'test' . time(); | ||
(new SystemLogService)->write($content, 1); | ||
|
||
$search = json_encode([ | ||
'content' => $content | ||
]); | ||
|
||
$response = $this->json('GET', '/api/system-log', [ | ||
'type_id' => '1', | ||
'search' => $search, | ||
]); | ||
|
||
$response->assertStatus(200) | ||
->assertJson([ | ||
'data' => [ | ||
'data' => [ | ||
[ | ||
'type_id' => '1', | ||
'content' => $content | ||
] | ||
] | ||
] | ||
]); | ||
} | ||
|
||
public function testSearchLogWithNameAndContent() | ||
{ | ||
$user = User::find(1); | ||
$this->actingAs($user); | ||
$content = 'test' . time(); | ||
(new SystemLogService)->write($content, 1); | ||
|
||
$search = json_encode([ | ||
'username' => 'admin', | ||
'content' => $content | ||
]); | ||
|
||
$response = $this->json('GET', '/api/system-log', [ | ||
'search' => $search, | ||
]); | ||
|
||
$response->assertStatus(200) | ||
->assertJson([ | ||
'data' => [ | ||
'data' => [ | ||
[ | ||
'content' => $content, | ||
'user_name' => 'admin' | ||
] | ||
] | ||
] | ||
]); | ||
} | ||
|
||
public function testSearchLogAllCondition() | ||
{ | ||
$user = User::find(1); | ||
$this->actingAs($user); | ||
$content = 'test' . time(); | ||
(new SystemLogService)->write($content, 1); | ||
|
||
$search = json_encode([ | ||
'username' => 'admin', | ||
'content' => $content | ||
]); | ||
|
||
$response = $this->json('GET', '/api/system-log', [ | ||
'type_id' => '1', | ||
'search' => $search, | ||
]); | ||
|
||
$response->assertStatus(200) | ||
->assertJson([ | ||
'data' => [ | ||
'data' => [ | ||
[ | ||
'type_id' => '1', | ||
'content' => $content, | ||
'user_name' => 'admin', | ||
] | ||
] | ||
] | ||
]); | ||
} | ||
} |