diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index f98b88a3..7a986b90 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -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), + ]; +}); diff --git a/tests/Api/ComponentTest.php b/tests/Api/ComponentTest.php index 66c77788..8f7854d3 100644 --- a/tests/Api/ComponentTest.php +++ b/tests/Api/ComponentTest.php @@ -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() diff --git a/tests/Api/IncidentTest.php b/tests/Api/IncidentTest.php index 586df61c..045590d0 100644 --- a/tests/Api/IncidentTest.php +++ b/tests/Api/IncidentTest.php @@ -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() diff --git a/tests/Api/MetricPointTest.php b/tests/Api/MetricPointTest.php new file mode 100644 index 00000000..5d58cb29 --- /dev/null +++ b/tests/Api/MetricPointTest.php @@ -0,0 +1,56 @@ + + * + * 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); + } +} diff --git a/tests/Api/MetricTest.php b/tests/Api/MetricTest.php index 93463174..09fe0ff0 100644 --- a/tests/Api/MetricTest.php +++ b/tests/Api/MetricTest.php @@ -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); + } }