test metric points by latests
This commit is contained in:
@@ -120,7 +120,11 @@ class MetricPoint extends Model implements HasPresenter
|
|||||||
$timestamp = $createdAt->format('U');
|
$timestamp = $createdAt->format('U');
|
||||||
$timestamp = 30 * round($timestamp / 30);
|
$timestamp = 30 * round($timestamp / 30);
|
||||||
|
|
||||||
return Carbon::createFromFormat('U', $timestamp)->toDateTimeString();
|
$date = Carbon::createFromFormat('U', $timestamp)->toDateTimeString();
|
||||||
|
|
||||||
|
$this->attributes['created_at'] = $date;
|
||||||
|
|
||||||
|
return $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -85,9 +85,11 @@ $factory->define(Metric::class, function ($faker) {
|
|||||||
|
|
||||||
$factory->define(MetricPoint::class, function ($faker) {
|
$factory->define(MetricPoint::class, function ($faker) {
|
||||||
return [
|
return [
|
||||||
'metric_id' => factory(Metric::class)->create()->id,
|
'metric_id' => factory(Metric::class)->create()->id,
|
||||||
'value' => mt_rand(1, 100),
|
'value' => mt_rand(1, 100),
|
||||||
'counter' => 1,
|
'counter' => 1,
|
||||||
|
'created_at' => Carbon::now(),
|
||||||
|
'updated_at' => Carbon::now(),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,38 @@ class MetricPointTest extends AbstractApiTestCase
|
|||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_can_get_all_metric_points_in_order_by_latests()
|
||||||
|
{
|
||||||
|
$metric = factory(Metric::class)->create();
|
||||||
|
$metricPoint1 = factory(MetricPoint::class)->create([
|
||||||
|
'metric_id' => $metric->id,
|
||||||
|
'created_at' => Carbon::parse('2016-12-01 2:00pm'),
|
||||||
|
'updated_at' => Carbon::parse('2016-12-01 2:00pm'),
|
||||||
|
]);
|
||||||
|
$metricPoint2 = factory(MetricPoint::class)->create([
|
||||||
|
'metric_id' => $metric->id,
|
||||||
|
'created_at' => Carbon::parse('2016-12-01 1:00pm'),
|
||||||
|
'updated_at' => Carbon::parse('2016-12-01 1:00pm'),
|
||||||
|
]);
|
||||||
|
$metricPoint3 = factory(MetricPoint::class)->create([
|
||||||
|
'metric_id' => $metric->id,
|
||||||
|
'created_at' => Carbon::parse('2016-12-01 4:00pm'),
|
||||||
|
'updated_at' => Carbon::parse('2016-12-01 4:00pm'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->json('GET', "/api/v1/metrics/{$metric->id}/points");
|
||||||
|
|
||||||
|
$response->assertJson([
|
||||||
|
'data' => [
|
||||||
|
['id' => $metricPoint3->id],
|
||||||
|
['id' => $metricPoint1->id],
|
||||||
|
['id' => $metricPoint2->id],
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_cannot_create_metric_point_without_authorization()
|
public function test_cannot_create_metric_point_without_authorization()
|
||||||
{
|
{
|
||||||
$metric = factory(Metric::class)->create();
|
$metric = factory(Metric::class)->create();
|
||||||
|
|||||||
Reference in New Issue
Block a user