mirror of
https://github.com/easychen/pushdeer.git
synced 2025-04-30 08:19:45 +08:00
添加自动化测试,将api频率控制加入配置文件
This commit is contained in:
parent
ed7d256527
commit
cd30839006
@ -60,6 +60,7 @@ GO_PUSH_IOS_CLIP_TOPIC=com.pushdeer.app.ios.Clip
|
||||
ANDROID_PACKAGE=com.pushdeer.app.os
|
||||
MIPUSH_SECRET=NONE
|
||||
|
||||
|
||||
WECHAT_APPID=
|
||||
WECHAT_APPSECRET=
|
||||
|
||||
MAX_PUSH_EVERY_USER_PER_MINUTE=60
|
||||
|
@ -57,7 +57,7 @@ class RouteServiceProvider extends ServiceProvider
|
||||
protected function configureRateLimiting()
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60)->by(uid() ?: $request->ip());
|
||||
return Limit::perMinute(env('MAX_PUSH_EVERY_USER_PER_MINUTE'))->by(uid() ?: $request->ip());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
205
api/tests/Feature/ApiTest.php
Normal file
205
api/tests/Feature/ApiTest.php
Normal file
@ -0,0 +1,205 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Testing\Fluent\AssertableJson;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ApiTest extends TestCase
|
||||
{
|
||||
private $token;
|
||||
private static $key;
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_login_fake()
|
||||
{
|
||||
$response = $this->getJson('/login/fake');
|
||||
$response->assertStatus(200)->assertJson(['code'=>0]);
|
||||
$data = json_decode($response->getContent(), true);
|
||||
$this->token = $data['content']['token'];
|
||||
echo __LINE__ . " " . $this->token ."\r\n";
|
||||
// $response->dd();
|
||||
}
|
||||
|
||||
public function test_user_info()
|
||||
{
|
||||
$response = $this->post('/user/info', ['token'=>$this->token]);
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['code'=>0])
|
||||
->assertJsonPath('content.id', 1)
|
||||
->assertJsonPath('content.apple_id', 'theid999');
|
||||
}
|
||||
|
||||
public function test_device_reg()
|
||||
{
|
||||
$response = $this->post('/device/reg', [
|
||||
'token'=>$this->token,
|
||||
'name'=>'Easy的iPad',
|
||||
'device_id'=>'device-token',
|
||||
'is_clip'=>0,
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['code'=>0])
|
||||
->assertJsonPath('content.devices.0.uid', '1')
|
||||
->assertJsonPath('content.devices.0.device_id', 'device-token');
|
||||
}
|
||||
|
||||
public function test_device_list()
|
||||
{
|
||||
$response = $this->post('/device/list', [
|
||||
'token'=>$this->token,
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['code'=>0])
|
||||
->assertJsonPath('content.devices.0.uid', '1')
|
||||
->assertJsonPath('content.devices.0.device_id', 'device-token');
|
||||
}
|
||||
|
||||
public function test_device_rename()
|
||||
{
|
||||
$response = $this->post('/device/rename', [
|
||||
'token'=>$this->token,
|
||||
'id' => 1,
|
||||
'name' => 'device-renamed',
|
||||
]);
|
||||
|
||||
// $response->dump();
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['code'=>0])
|
||||
->assertJsonPath('content.message', 'done');
|
||||
|
||||
$response = $this->post('/device/list', [
|
||||
'token'=>$this->token,
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['code'=>0])
|
||||
->assertSee('device-renamed');
|
||||
}
|
||||
|
||||
public function test_key_gen()
|
||||
{
|
||||
$response = $this->post('/key/gen', [
|
||||
'token'=>$this->token,
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['code'=>0])
|
||||
// ->assertJson('content.keys.0.id', 1)
|
||||
->assertSee('PDU');
|
||||
|
||||
$data = json_decode($response->getContent(), true);
|
||||
self::$key = $data['content']['keys'][0]['key'];
|
||||
}
|
||||
|
||||
public function test_key_rename()
|
||||
{
|
||||
$response = $this->post('/key/rename', [
|
||||
'token'=>$this->token,
|
||||
'id' => 1,
|
||||
'name' => 'key-renamed',
|
||||
]);
|
||||
|
||||
// $response->dump();
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['code'=>0])
|
||||
->assertJsonPath('content.message', 'done');
|
||||
|
||||
$response = $this->post('/key/list', [
|
||||
'token'=>$this->token,
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['code'=>0])
|
||||
->assertSee('key-renamed');
|
||||
}
|
||||
|
||||
public function test_message_push()
|
||||
{
|
||||
$response = $this->post('/message/push', [
|
||||
'pushkey'=>self::$key,
|
||||
'text' => 'tested',
|
||||
'type' => 'text',
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['code'=>0])
|
||||
->assertSee('success');
|
||||
}
|
||||
|
||||
public function test_message_list()
|
||||
{
|
||||
$response = $this->post('/message/list', [
|
||||
'token'=>$this->token,
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['code'=>0])
|
||||
->assertSee('tested');
|
||||
}
|
||||
|
||||
public function test_message_remove()
|
||||
{
|
||||
$response = $this->post('/message/remove', [
|
||||
'token'=>$this->token,
|
||||
'id' => 1,
|
||||
]);
|
||||
|
||||
// $response->dump();
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['code'=>0])
|
||||
->assertJsonPath('content.message', 'done');
|
||||
}
|
||||
|
||||
public function test_key_regen()
|
||||
{
|
||||
$response = $this->post('/key/regen', [
|
||||
'token'=>$this->token,
|
||||
'id' => 1,
|
||||
]);
|
||||
|
||||
// $response->dump();
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['code'=>0])
|
||||
->assertJsonPath('content.message', 'done');
|
||||
}
|
||||
|
||||
public function test_key_remove()
|
||||
{
|
||||
$response = $this->post('/key/remove', [
|
||||
'token'=>$this->token,
|
||||
'id' => 1,
|
||||
]);
|
||||
|
||||
// $response->dump();
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['code'=>0])
|
||||
->assertJsonPath('content.message', 'done');
|
||||
}
|
||||
|
||||
public function test_device_remove()
|
||||
{
|
||||
$response = $this->post('/device/remove', [
|
||||
'token'=>$this->token,
|
||||
'id' => 1,
|
||||
]);
|
||||
|
||||
// $response->dump();
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJson(['code'=>0])
|
||||
->assertJsonPath('content.message', 'done');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user