Add web cron ability #821 (#1073)

* Use database for kvp storage

* Read kvpstore

* Add web cron ability through API #821

* Style fixes

* Fix text
This commit is contained in:
Nabeel S
2021-03-09 11:36:56 -05:00
committed by GitHub
parent f1c54bcc7c
commit e70ee5aa6f
13 changed files with 243 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ use App\Models\News;
use App\Models\Subfleet;
use App\Models\User;
use App\Services\FareService;
use App\Support\Utils;
use Exception;
use function random_int;
@@ -312,4 +313,21 @@ class ApiTest extends TestCase
$this->assertNotNull($user);
$this->assertTrue(strpos($user['avatar'], 'gravatar') !== -1);
}
/**
* Test that the web cron runs
*/
public function testWebCron()
{
$this->updateSetting('cron.random_id', '');
$this->get('/api/cron/sdf')->assertStatus(400);
$id = Utils::generateNewId(24);
$this->updateSetting('cron.random_id', $id);
$this->get('/api/cron/sdf')->assertStatus(400);
$res = $this->get('/api/cron/'.$id);
$res->assertStatus(200);
}
}

View File

@@ -2,6 +2,7 @@
namespace Tests;
use App\Repositories\KvpRepository;
use App\Support\ICAO;
use App\Support\Units\Time;
use App\Support\Utils;
@@ -15,6 +16,24 @@ class UtilsTest extends TestCase
$this->assertNotNull($carbon);
}
/**
* Simple test for KVP
*/
public function testKvp()
{
/** @var KvpRepository $kvpRepo */
$kvpRepo = app(KvpRepository::class);
$kvpRepo->save('testkey', 'some value');
$this->assertEquals('some value', $kvpRepo->get('testkey'));
// test that default value is working
$this->assertEquals('default value', $kvpRepo->get('unknownkey', 'default value'));
// try saving an integer
$kvpRepo->save('intval', 1);
$this->assertEquals(1, $kvpRepo->get('intval'));
}
/**
* @throws \Exception
*/