mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-03-14 20:39:44 +01:00
Added Metric and MetricPoint API testing
This commit is contained in:
parent
90110944ff
commit
743ed28fd8
@ -31,3 +31,30 @@ $factory->define('CachetHQ\Cachet\Models\Component', function ($faker) {
|
||||
'user_id' => 1,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define('CachetHQ\Cachet\Models\Incident', function ($faker) {
|
||||
return [
|
||||
'name' => $faker->sentence(),
|
||||
'message' => $faker->paragraph(),
|
||||
'status' => 1,
|
||||
'user_id' => 1,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define('CachetHQ\Cachet\Models\Metric', function ($faker) {
|
||||
return [
|
||||
'name' => $faker->sentence(),
|
||||
'suffix' => $faker->word(),
|
||||
'description' => $faker->paragraph(),
|
||||
'default_value' => 1,
|
||||
'calc_type' => 1,
|
||||
'display_chart' => 1,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define('CachetHQ\Cachet\Models\MetricPoint', function ($faker) {
|
||||
return [
|
||||
'metric_id' => 1,
|
||||
'value' => rand(1, 100),
|
||||
];
|
||||
});
|
||||
|
@ -35,6 +35,7 @@ class ComponentTest extends AbstractTestCase
|
||||
{
|
||||
$this->post('/api/v1/components');
|
||||
$this->assertResponseStatus(401);
|
||||
$this->seeJson(['message' => 'You are not authorized to view this content.', 'status_code' => 401]);
|
||||
}
|
||||
|
||||
public function testPostComponentNoData()
|
||||
|
@ -33,6 +33,7 @@ class IncidentTest extends AbstractTestCase
|
||||
{
|
||||
$this->post('/api/v1/incidents');
|
||||
$this->assertResponseStatus(401);
|
||||
$this->seeJson(['message' => 'You are not authorized to view this content.', 'status_code' => 401]);
|
||||
}
|
||||
|
||||
public function testPostIncidentNoData()
|
||||
|
56
tests/Api/MetricPointTest.php
Normal file
56
tests/Api/MetricPointTest.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* 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 MetricPointTest extends AbstractTestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
public function testPostMetricPointUnauthorized()
|
||||
{
|
||||
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create();
|
||||
$this->post('/api/v1/metrics/1/points');
|
||||
|
||||
$this->assertResponseStatus(401);
|
||||
$this->seeJson(['message' => 'You are not authorized to view this content.', 'status_code' => 401]);
|
||||
}
|
||||
|
||||
public function testPostMetricPoint()
|
||||
{
|
||||
$this->beUser();
|
||||
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create();
|
||||
|
||||
$this->post('/api/v1/metrics/1/points', $metricPoint->toArray());
|
||||
$this->seeJson(['value' => (string) $metricPoint->value]);
|
||||
}
|
||||
|
||||
public function testPutMetricPoint()
|
||||
{
|
||||
$this->beUser();
|
||||
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create();
|
||||
$this->put('/api/v1/metrics/1/points/1', [
|
||||
'value' => 999,
|
||||
]);
|
||||
$this->seeJson(['value' => '999']);
|
||||
}
|
||||
|
||||
public function testDeleteMetricPoint()
|
||||
{
|
||||
$this->beUser();
|
||||
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create();
|
||||
$this->delete('/api/v1/metrics/1/points/1');
|
||||
$this->assertResponseStatus(204);
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ class MetricTest extends AbstractTestCase
|
||||
{
|
||||
$this->post('/api/v1/metrics');
|
||||
$this->assertResponseStatus(401);
|
||||
$this->seeJson(['message' => 'You are not authorized to view this content.', 'status_code' => 401]);
|
||||
}
|
||||
|
||||
public function testPostMetricNoData()
|
||||
@ -56,4 +57,32 @@ class MetricTest extends AbstractTestCase
|
||||
]);
|
||||
$this->seeJson(['name' => 'Foo']);
|
||||
}
|
||||
|
||||
public function testGetNewMetric()
|
||||
{
|
||||
$incident = factory('CachetHQ\Cachet\Models\Metric')->create();
|
||||
|
||||
$this->get('/api/v1/metrics/1');
|
||||
$this->seeJson(['name' => $incident->name]);
|
||||
}
|
||||
|
||||
public function testPutMetric()
|
||||
{
|
||||
$this->beUser();
|
||||
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
|
||||
|
||||
$this->put('/api/v1/metrics/1', [
|
||||
'name' => 'Foo',
|
||||
]);
|
||||
$this->seeJson(['name' => 'Foo']);
|
||||
}
|
||||
|
||||
public function testDeleteMetric()
|
||||
{
|
||||
$this->beUser();
|
||||
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
|
||||
|
||||
$this->delete('/api/v1/metrics/1');
|
||||
$this->assertResponseStatus(204);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user