Fix tests

This commit is contained in:
James Brooks
2018-06-27 14:39:49 +01:00
parent 55002bb4b4
commit 1ac884805d
2 changed files with 10 additions and 5 deletions
+8 -4
View File
@@ -92,13 +92,17 @@ class MetricPoint extends Model implements HasPresenter
/** /**
* Round the created at value into intervals of 30 seconds. * Round the created at value into intervals of 30 seconds.
* *
* @param string $value * @param string $createdAt
* *
* @return void * @return string|void
*/ */
public function setCreatedAtAttribute($value) public function setCreatedAtAttribute($createdAt)
{ {
$timestamp = $value->format('U'); if (!$createdAt) return;
$createdAt = Carbon::parse($createdAt);
$timestamp = $createdAt->format('U');
$timestamp = 30 * round($timestamp / 30); $timestamp = 30 * round($timestamp / 30);
return Carbon::createFromFormat('U', $timestamp)->toDateTimeString(); return Carbon::createFromFormat('U', $timestamp)->toDateTimeString();
+2 -1
View File
@@ -78,11 +78,12 @@ class MetricPointTest extends AbstractApiTestCase
$postData['timestamp'] = $timestamp; $postData['timestamp'] = $timestamp;
$response = $this->json('POST', "/api/v1/metrics/{$metric->id}/points", $postData); $response = $this->json('POST', "/api/v1/metrics/{$metric->id}/points", $postData);
$response->dump();
$response->assertStatus(200); $response->assertStatus(200);
$response->assertJsonFragment([ $response->assertJsonFragment([
'value' => $metricPoint->value, 'value' => $metricPoint->value,
'created_at' => date('Y-m-d H:i:s', 1434369116), 'created_at' => date('Y-m-d H:i:00', 1434369116),
]); ]);
} }