test metric points by latests

This commit is contained in:
Joe Cohen
2018-07-03 13:08:41 -05:00
parent a79187569e
commit 60ec8b766b

View File

@@ -101,19 +101,22 @@ class MetricPointTest extends AbstractApiTestCase
$this->beUser();
$metric = factory(Metric::class)->create();
$timestamp = strtotime('now');
$createdAt = Carbon::now();
$metricPoint = factory(MetricPoint::class)->make([
'metric_id' => $metric->id,
]);
$postData = $metricPoint->toArray();
$postData['timestamp'] = $timestamp;
$postData['timestamp'] = $createdAt->timestamp;
$response = $this->json('POST', "/api/v1/metrics/{$metric->id}/points", $postData);
// Round value to match ours
$timestamp = 30 * round($createdAt->timestamp / 30);
$response->assertStatus(200);
$response->assertJsonFragment([
'value' => $metricPoint->value,
'created_at' => date('Y-m-d H:i:s', $timestamp),
'created_at' => Carbon::createFromFormat('U', $timestamp)->setTimezone('Europe/London')->toDateTimeString(),
]);
}
@@ -126,17 +129,23 @@ class MetricPointTest extends AbstractApiTestCase
$timezone = 'America/Mexico_City';
$metric = factory(Metric::class)->create();
$datetime = Carbon::now()->timezone($timezone);
$createdAt = Carbon::now()->timezone($timezone);
$metricPoint = factory(MetricPoint::class)->make([
'metric_id' => $metric->id,
]);
$postData = $metricPoint->toArray();
$postData['timestamp'] = $datetime->timestamp;
$postData['timestamp'] = $createdAt->timestamp;
$response = $this->json('POST', "/api/v1/metrics/{$metric->id}/points", $postData, ['Time-Zone' => $timezone]);
// Round value to match ours
$timestamp = 30 * round($createdAt->timestamp / 30);
$response->assertStatus(200);
$response->assertJsonFragment(['value' => $metricPoint->value, 'created_at' => $datetime->toDateTimeString()]);
$response->assertJsonFragment([
'value' => $metricPoint->value,
'created_at' => Carbon::createFromFormat('U', $timestamp)->setTimezone($timezone)->toDateTimeString(),
]);
}
public function test_can_update_metric_point()