Refactored the way we store metrics

This commit is contained in:
James Brooks
2016-03-02 12:09:57 +00:00
committed by James Brooks
parent 3730ca8811
commit f9bc46b460
25 changed files with 329 additions and 104 deletions
+18
View File
@@ -29,9 +29,12 @@ class MetricPointTest extends AbstractApiTestCase
]);
$this->get("/api/v1/metrics/{$metric->id}/points");
$this->seeJson(['id' => $metricPoint[0]->id]);
$this->seeJson(['id' => $metricPoint[1]->id]);
$this->seeJson(['id' => $metricPoint[2]->id]);
$this->assertResponseOk();
}
public function testPostMetricPointUnauthorized()
@@ -55,7 +58,10 @@ class MetricPointTest extends AbstractApiTestCase
]);
$this->post("/api/v1/metrics/{$metric->id}/points", $metricPoint->toArray());
$this->seeJson(['value' => $metricPoint->value]);
$this->assertResponseOk();
}
public function testPostMetricPointTimestamp()
@@ -72,7 +78,10 @@ class MetricPointTest extends AbstractApiTestCase
$postData['timestamp'] = $timestamp;
$this->post("/api/v1/metrics/{$metric->id}/points", $postData);
$this->seeJson(['value' => $metricPoint->value, 'created_at' => $datetime]);
$this->assertResponseOk();
}
public function testPostMetricPointTimestampTimezone()
@@ -96,7 +105,10 @@ class MetricPointTest extends AbstractApiTestCase
$postData['timestamp'] = $datetime->timestamp;
$this->post("/api/v1/metrics/{$metric->id}/points", $postData, ['Time-Zone' => $timezone]);
$this->seeJson(['value' => $metricPoint->value, 'created_at' => $datetime->toDateTimeString()]);
$this->assertResponseOk();
}
public function testPutMetricPoint()
@@ -106,10 +118,14 @@ class MetricPointTest extends AbstractApiTestCase
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create([
'metric_id' => $metric->id,
]);
$this->put("/api/v1/metrics/{$metric->id}/points/{$metricPoint->id}", [
'value' => 999,
]);
$this->seeJson(['value' => 999]);
$this->assertResponseOk();
}
public function testDeleteMetricPoint()
@@ -119,7 +135,9 @@ class MetricPointTest extends AbstractApiTestCase
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->create([
'metric_id' => $metric->id,
]);
$this->delete("/api/v1/metrics/{$metric->id}/points/{$metricPoint->id}");
$this->assertResponseStatus(204);
}
}
@@ -29,14 +29,15 @@ class AddMetricCommandTest extends AbstractTestCase
protected function getObjectAndParams()
{
$params = [
'name' => 'Coffee',
'suffix' => 'cups',
'description' => 'Cups of coffee consumed',
'default_value' => 0,
'calc_type' => 0,
'display_chart' => 1,
'places' => 0,
'default_view' => 0,
'name' => 'Coffee',
'suffix' => 'cups',
'description' => 'Cups of coffee consumed',
'default_value' => 0,
'calc_type' => 0,
'display_chart' => 1,
'places' => 0,
'default_view' => 0,
'threshold' => 0,
];
$object = new AddMetricCommand(
@@ -47,7 +48,8 @@ class AddMetricCommandTest extends AbstractTestCase
$params['calc_type'],
$params['display_chart'],
$params['places'],
$params['default_view']
$params['default_view'],
$params['threshold']
);
return compact('params', 'object');
@@ -39,6 +39,7 @@ class UpdateMetricCommandTest extends AbstractTestCase
'display_chart' => 1,
'places' => 0,
'default_view' => 0,
'threshold' => 0,
];
$object = new UpdateMetricCommand(
@@ -50,7 +51,8 @@ class UpdateMetricCommandTest extends AbstractTestCase
$params['calc_type'],
$params['display_chart'],
$params['places'],
$params['default_view']
$params['default_view'],
$params['threshold']
);
return compact('params', 'object');