Upsert on ACARS positions #572 (#573)

This commit is contained in:
Nabeel S
2020-02-22 16:03:01 -05:00
committed by GitHub
parent 6e87f7804c
commit 9ed07da9c3
6 changed files with 91 additions and 28 deletions

View File

@@ -4,6 +4,7 @@ use App\Models\Enums\PirepState;
use App\Models\Enums\PirepStatus;
use App\Models\PirepFare;
use App\Repositories\SettingRepository;
use App\Support\Utils;
/**
* Test API calls and authentication, etc
@@ -660,13 +661,22 @@ class AcarsTest extends TestCase
$uri = '/api/pireps/'.$pirep_id.'/acars/position';
// Post an ACARS update
$acars_count = \random_int(2, 10);
$acars = factory(App\Models\Acars::class, $acars_count)->make(['id' => ''])->toArray();
$acars_count = \random_int(5, 10);
$acars = factory(App\Models\Acars::class, $acars_count)->make(['id' => ''])
->map(function ($point) {
$point['id'] = Utils::generateNewId();
return $point;
})
->toArray();
$update = ['positions' => $acars];
$response = $this->post($uri, $update);
$response->assertStatus(200)->assertJson(['count' => $acars_count]);
// Try posting again, should be ignored/not throw any sql errors
$response = $this->post($uri, $update);
$response->assertStatus(200)->assertJson(['count' => $acars_count]);
$response = $this->get($uri);
$response->assertStatus(200)->assertJsonCount($acars_count, 'data');
}
@@ -700,11 +710,9 @@ class AcarsTest extends TestCase
$dt = date('c');
$uri = '/api/pireps/'.$pirep_id.'/acars/position';
$acars = factory(App\Models\Acars::class)->make(
[
'sim_time' => $dt,
]
)->toArray();
$acars = factory(App\Models\Acars::class)->make([
'sim_time' => $dt,
])->toArray();
$update = ['positions' => [$acars]];
$response = $this->post($uri, $update);
@@ -729,7 +737,13 @@ class AcarsTest extends TestCase
$response->assertStatus(400);
$post_route = [
['order' => 1, 'name' => 'NAVPOINT', 'lat' => 'notanumber', 'lon' => 34.11],
[
'id' => 'NAVPOINT',
'order' => 1,
'name' => 'NAVPOINT',
'lat' => 'notanumber',
'lon' => 34.11,
],
];
$uri = '/api/pireps/'.$pirep_id.'/route';
@@ -803,6 +817,10 @@ class AcarsTest extends TestCase
$response = $this->post($uri, ['route' => $post_route]);
$response->assertStatus(200)->assertJson(['count' => $route_count]);
// Try double post to ignore SQL update
$response = $this->post($uri, ['route' => $post_route]);
$response->assertStatus(200)->assertJson(['count' => $route_count]);
/**
* Get
*/