test metric points by latests
This commit is contained in:
@@ -101,19 +101,22 @@ class MetricPointTest extends AbstractApiTestCase
|
|||||||
$this->beUser();
|
$this->beUser();
|
||||||
|
|
||||||
$metric = factory(Metric::class)->create();
|
$metric = factory(Metric::class)->create();
|
||||||
$timestamp = strtotime('now');
|
$createdAt = Carbon::now();
|
||||||
$metricPoint = factory(MetricPoint::class)->make([
|
$metricPoint = factory(MetricPoint::class)->make([
|
||||||
'metric_id' => $metric->id,
|
'metric_id' => $metric->id,
|
||||||
]);
|
]);
|
||||||
$postData = $metricPoint->toArray();
|
$postData = $metricPoint->toArray();
|
||||||
$postData['timestamp'] = $timestamp;
|
$postData['timestamp'] = $createdAt->timestamp;
|
||||||
|
|
||||||
$response = $this->json('POST', "/api/v1/metrics/{$metric->id}/points", $postData);
|
$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->assertStatus(200);
|
||||||
$response->assertJsonFragment([
|
$response->assertJsonFragment([
|
||||||
'value' => $metricPoint->value,
|
'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';
|
$timezone = 'America/Mexico_City';
|
||||||
$metric = factory(Metric::class)->create();
|
$metric = factory(Metric::class)->create();
|
||||||
$datetime = Carbon::now()->timezone($timezone);
|
$createdAt = Carbon::now()->timezone($timezone);
|
||||||
$metricPoint = factory(MetricPoint::class)->make([
|
$metricPoint = factory(MetricPoint::class)->make([
|
||||||
'metric_id' => $metric->id,
|
'metric_id' => $metric->id,
|
||||||
]);
|
]);
|
||||||
$postData = $metricPoint->toArray();
|
$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]);
|
$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->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()
|
public function test_can_update_metric_point()
|
||||||
|
|||||||
Reference in New Issue
Block a user