Added Metric and MetricPoint API testing

This commit is contained in:
James Brooks 2015-06-02 20:02:43 +01:00
parent 90110944ff
commit 743ed28fd8
5 changed files with 114 additions and 0 deletions

View File

@ -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),
];
});

View File

@ -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()

View File

@ -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()

View 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);
}
}

View File

@ -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);
}
}