2015-06-01 21:32:02 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Cachet.
|
|
|
|
*
|
2015-07-06 17:37:01 +01:00
|
|
|
* (c) Alt Three Services Limited
|
2015-06-01 21:32:02 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace CachetHQ\Tests\Cachet\Api;
|
|
|
|
|
|
|
|
use CachetHQ\Tests\Cachet\AbstractTestCase;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
|
|
|
|
|
|
class MetricTest extends AbstractTestCase
|
|
|
|
{
|
|
|
|
use DatabaseMigrations;
|
|
|
|
|
|
|
|
public function testGetMetrics()
|
|
|
|
{
|
2015-05-23 19:09:24 +01:00
|
|
|
$metrics = factory('CachetHQ\Cachet\Models\Metric', 3)->create();
|
|
|
|
|
2015-06-03 08:28:48 +01:00
|
|
|
$this->get('/api/v1/metrics');
|
2015-05-23 19:09:24 +01:00
|
|
|
$this->seeJson(['id' => (string) $metrics[0]->id]);
|
|
|
|
$this->seeJson(['id' => (string) $metrics[1]->id]);
|
|
|
|
$this->seeJson(['id' => (string) $metrics[2]->id]);
|
2015-06-03 08:28:48 +01:00
|
|
|
$this->assertResponseOk();
|
2015-06-01 21:32:02 +01:00
|
|
|
}
|
2015-06-02 14:23:55 +01:00
|
|
|
|
|
|
|
public function testGetInvalidMetric()
|
|
|
|
{
|
2015-05-23 19:09:24 +01:00
|
|
|
$this->get('/api/v1/metrics/0');
|
2015-06-02 14:23:55 +01:00
|
|
|
$this->assertResponseStatus(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPostMetricUnauthorized()
|
|
|
|
{
|
|
|
|
$this->post('/api/v1/metrics');
|
|
|
|
$this->assertResponseStatus(401);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPostMetricNoData()
|
|
|
|
{
|
|
|
|
$this->beUser();
|
|
|
|
|
|
|
|
$this->post('/api/v1/metrics');
|
|
|
|
$this->assertResponseStatus(400);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPostMetric()
|
|
|
|
{
|
|
|
|
$this->beUser();
|
|
|
|
|
|
|
|
$this->post('/api/v1/metrics', [
|
|
|
|
'name' => 'Foo',
|
|
|
|
'suffix' => 'foo\'s per second',
|
|
|
|
'description' => 'Lorem ipsum dolor',
|
|
|
|
'default_value' => 1,
|
|
|
|
'display_chart' => 1,
|
|
|
|
]);
|
|
|
|
$this->seeJson(['name' => 'Foo']);
|
2015-06-03 08:28:48 +01:00
|
|
|
$this->assertResponseOk();
|
2015-06-02 14:23:55 +01:00
|
|
|
}
|
2015-06-02 20:02:43 +01:00
|
|
|
|
|
|
|
public function testGetNewMetric()
|
|
|
|
{
|
|
|
|
$incident = factory('CachetHQ\Cachet\Models\Metric')->create();
|
|
|
|
|
|
|
|
$this->get('/api/v1/metrics/1');
|
|
|
|
$this->seeJson(['name' => $incident->name]);
|
2015-06-03 08:28:48 +01:00
|
|
|
$this->assertResponseOk();
|
2015-06-02 20:02:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testPutMetric()
|
|
|
|
{
|
|
|
|
$this->beUser();
|
|
|
|
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
|
|
|
|
|
|
|
|
$this->put('/api/v1/metrics/1', [
|
|
|
|
'name' => 'Foo',
|
|
|
|
]);
|
|
|
|
$this->seeJson(['name' => 'Foo']);
|
2015-06-03 08:28:48 +01:00
|
|
|
$this->assertResponseOk();
|
2015-06-02 20:02:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteMetric()
|
|
|
|
{
|
|
|
|
$this->beUser();
|
|
|
|
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
|
|
|
|
|
|
|
|
$this->delete('/api/v1/metrics/1');
|
|
|
|
$this->assertResponseStatus(204);
|
|
|
|
}
|
2015-06-01 21:32:02 +01:00
|
|
|
}
|